Do I need to use paging?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
phix

Do I need to use paging?

Post by phix »

Hi!

I have just created my first os kernel... It boots nicely and sets up IDT GDT etc. and I have just finish a small console system for my os.

But I can't run from the problem any more... I need a memory manager. So I have read alot on the subject lately but I'm confused. If I just want to make a singel-task os. (As simple as posible... MS-DOS) do I realy need the paging and stuff??

Can't I just devide the memory in to user and kernal memory and
keep track of used and unused memory??

I just want to do my os as simple as posible.
Pyr0Mathic

Re:Do I need to use paging?

Post by Pyr0Mathic »

Lo,

Whell u dont need paging but i would put it in your OS.

I did the following: Simply set the first 512MB directly to the first 512MB of the RAM, so phisical address and Paged address are the same for the first 512MB. That way u can easely acces PTE's and other stuf, which point to Phisical addresses.

and later i set the range 1gig to 2 gig. to paged memory. which is used by the functions which require more then 4KB of memory.

The big advantage of using paging is, atleast in my case, u dont need to phisicly allocate all the memory which u declare, for example if u need x MB of memory but u know it isnt bigger then 64KB u can simply declare an area of 64Kb whitout needing to consider if u got enough memory left, since it is only made present if u try to access the page, due to a PageFault, then u need to make it present.

Also if u only have a small amount of phisical memory u dont need to worry about gaps in your memory. so for instance that u wouldnt anymore be able to declare a segment of 64KB since all aviable data which is free is "Skatterd" all over the Phisical memory.


i hope u can make any sence about the above statments.


Regards.
PyroMathic

Btw: if u do want to implement paging. fully, look the following command up, INVLPG. it is required to invalidate the TLB's.
Dex4u

Re:Do I need to use paging?

Post by Dex4u »

For a single tasking OS, you do not need paging, Dex4u OS (my OS) is single-tasking OS and does not use it, you can use a simple memory management or none at all :o.
By letting the program control the memory you should be OK.
So you load the user program, to say 8MB and give it from 8MB to top of ram to use.
The Xbox for example does not use paging or have any memory management, see here:
http://www.extremetech.com/article2/0,1697,1670116,00.asp
Hope this helps.
paulbarker

Re:Do I need to use paging?

Post by paulbarker »

If you intend to support a swap file or partition, keep you're user programs protected from each other, isolate failures to the failing program (rather than a bug in a user program crashing the whole OS) or protect the kernel from being modified by user programs, you need paging / virtual memory in some form or other.

If you are making a single tasking OS or don't care about security and stability, you don't need paging / virtual memory.

Read everyone elses comments, draw up a list of pros and cons (If you don't understand that phrase of English, read reasons for and reasons against). It usually helps for decisions like this.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Do I need to use paging?

Post by Colonel Kernel »

paulbarker wrote: If you intend to support a swap file or partition, keep you're user programs protected from each other, isolate failures to the failing program (rather than a bug in a user program crashing the whole OS) or protect the kernel from being modified by user programs, you need paging / virtual memory in some form or other.
Add "if you're running unverifiable code" to that list of qualifications. Paging is not actually necessary to achieve process isolation. Singularity uses paging, but strictly speaking it doesn't need to since it relies on code verification for process isolation. Paging is still useful for the reasons Pyr0Mathic pointed out, however.

OT: Pyr0Mathic, it's spelled "you", not "u"... :P I hope you're not posting from a cell phone. ;)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
B.E

Re:Do I need to use paging?

Post by B.E »

It's up to u wither u use paging or segementation. An OS can be bult with out, but if you want a multi-tasking OS, paging is almost essental.
Paging is not actually necessary to achieve process isolation.
that right, u can use segmentation to achive process isolation.

Segmentation is good(I think we should use it more often), if used right. it allows you to control access to the kernel, you could have the kernel at 0-16MB(maybe less if your kernel is smaller) and the rest of memeory available to the program. link the kernel and programs to address 0.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Do I need to use paging?

Post by Colonel Kernel »

B.E wrote:that right, u can use segmentation to achive process isolation.
Not on MIPS, Sparc, Itanium, or x86-64 (and probably others)...
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
Dex4u

Re:Do I need to use paging?

Post by Dex4u »

I maybe wrong, but i read some where, that you must use paging, in long mode on a 64bit PC, If this is so, i would map it 1-1.
JoeKayzA

Re:Do I need to use paging?

Post by JoeKayzA »

Dex4u wrote: I maybe wrong, but i read some where, that you must use paging, in long mode on a 64bit PC, If this is so, i would map it 1-1.
I can confirm this. To enable long mode, both paging and PAE mode must be already enabled.
phix

Re:Do I need to use paging?

Post by phix »

OKI.. that sort of answerd my questions. :)

I'm also a litle bit confused when it comes to physical memory...
In what range lies the "free to use memory", in a x86 system. I know 0xB8000 is for VGA. Witch would be quite bad to map as free memory. :) Is their any documentation. (for a OS nube).

Just curious.. How do monolithic kernels handle memory. (if multi-tasking)
JoeKayzA

Re:Do I need to use paging?

Post by JoeKayzA »

phix wrote: I'm also a litle bit confused when it comes to physical memory...
In what range lies the "free to use memory", in a x86 system. I know 0xB8000 is for VGA. Witch would be quite bad to map as free memory. :) Is their any documentation. (for a OS nube).
Search the FAQ for the 'BIOS memory map'. The memory map contains all information about the memory layout.
phix wrote: Just curious.. How do monolithic kernels handle memory. (if multi-tasking)
That can be very different from system to system. Many monolithic systems today use the unix process scheme (at least I call it like this). That means the address space is split into a user space area and a kernel space area. Every process gets its own address space, where the user space area is private (is different in every process) and the kernel space is shared among all the processes. This way, all code and data that belongs to the kernel (and kernel mode drivers) is always present and does not need a context switch to execute it.

The pros and cons of this method have been discussed extensively already (imo), so you will probably find something more on this board.

cheers Joe
phix

Re:Do I need to use paging?

Post by phix »

OK..

Hmmm... well. I think I try to implement basic paging.

Thank you guys!
Post Reply