Page 1 of 1

How the OS sees paging?

Posted: Wed Dec 10, 2008 10:08 am
by Khaoticmind
First of all, i've not tried yet to implement my paging code, but reading the intel manuals and thinking a bit i got one question:
How the OS sees the memory after paging is enabled?

I mean... if I've my OS loaded at 0x0000, and then I enable paging, do i have to reserve some pages in the page table, so that the page where is my kernel won't be override?

Also, how does memory access work after paging has been enabled? I ask this because on the intel manuals it reads:
When paging is used, the processor divides the linear address space into fixed-size pages (of 4 KBytes, 2 MBytes, or 4 MBytes in length) that can be mapped into physical
memory and/or disk storage. When a program (or task) references a logical address in memory, the processor translates the address into a linear address and then uses its paging mechanism to translate the linear address into a corresponding physical address.
So... paging only works for programs/tasks? Or all access by the OS go throu the MMU as well?

Re: How the OS sees paging?

Posted: Wed Dec 10, 2008 10:18 am
by neon
The kernel itself runs in its own address space (Kind of. But for the purpose of this post Im going to say it is for simplicity) and can be seen as a "process" so yes, all accesses by the OS goes through the MMU as well. This is why idenitity mapping the memory of the current excution code before actually enabling paging is required.

Re: How the OS sees paging?

Posted: Wed Dec 10, 2008 11:01 am
by Khaoticmind
neon wrote:The kernel itself runs in its own address space (Kind of. But for the purpose of this post Im going to say it is for simplicity) and can be seen as a "process" so yes, all accesses by the OS goes through the MMU as well. This is why idenitity mapping the memory of the current excution code before actually enabling paging is required.
And by identity mapping you mean "knowing where the kernel is and save keeps this address from being used by any other process, also make sure to map the virtual address to the physical address used by the kernel", right? :)

Also, in the "kernel used space" you also have stuff like stack and heap right?

Also #2, i imagine that you can't page out the memory management part of the kernel, for obvious chicken-and-egg reasons. So some pages will always be in the ram, right?

Re: How the OS sees paging?

Posted: Wed Dec 10, 2008 11:20 am
by CodeCat
Identity means self. So identity mapping means that virtual addresses are mapped to themselves, i.e. to the same physical address.

Re: How the OS sees paging?

Posted: Wed Dec 10, 2008 11:59 am
by neon
And by identity mapping you mean "knowing where the kernel is and save keeps this address from being used by any other process, also make sure to map the virtual address to the physical address used by the kernel", right?
no and yes :) rather, the first part of your sentence is wrong, the second part is right.
Also, in the "kernel used space" you also have stuff like stack and heap right?
For the kernel, yes.
So some pages will always be in the ram, right?
Correct. You can even page out certain portians of the kernel itself just so long as the memory management is not, and should never be, paged out.

Re: How the OS sees paging?

Posted: Thu Dec 11, 2008 6:48 am
by jal
neon wrote:You can even page out certain portians of the kernel itself just so long as the memory management is not, and should never be, paged out.
Well, if your page fault handler can restore the memory management code, no problem there. I'm not saying this makes sense though :).


JAL