Hello,
I'm planning to implement multitasking. I have paging enabled already. I'm planning to have my kernel address space below 512MB which leave 3.5GB for user processes.
If i understood correctly in order to implement multitasking i need to have page directories for each task, the page directories will eventually points to page tables. This means 1024*1024*4=4MiB of "paging" structurs per task, which is a lot. Maybe a misunderstood something, but if what i'm saying is correct then if load 10 tasks this will already consumes my 32MB of RAM.
[SOLVED] Page directories per task
[SOLVED] Page directories per task
Last edited by alix on Wed Nov 21, 2012 2:41 am, edited 1 time in total.
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Page directories per task
You don't need to have page tables for a region of memory that is not being used. Each task needs one page directory, but generally not all 1024 page tables.
Re: Page directories per task
Thanks for your reply. But then i don't see in this case how can i virtually occupy kernel address space in each process. I should at least use a sufficient number of pages to get my kernel address space.NickJohnson wrote:You don't need to have page tables for a region of memory that is not being used. Each task needs one page directory, but generally not all 1024 page tables.
How it is handled in real world? For example in my Linux box i have 4G of mem so every process has 4MB of page directories and tables? For instance
ps -Al | wc -l gives me 149 processes, so i have about 600MB wasted?
I don't think it is really like that, however it could be implemented otherwise.
Re: Page directories per task
generally, each process has its own address space
typically, you will reserve space within the address space for the page tables, but the tables themeselves can be marked as NotPresent (and thus don't need to actually exist within physical memory) -- if you then need access to that particular portion of the address space, you will then need to allocate page tables
to map 4GB virtual address space (using standard, non-PAE paging) takes about 4MB -- so 4MB should (but doesn't necessarily need to be, but its easier if it is) reserved in each address space -- but only once in each address space
physical memory however, you don't need to have the full 4MB of tables -- there are 1024 tables that make up that 4MB of mapping tables -- theoretically, the only tables that have to exist are the directory and the specific page table that covers currently executing memory -- means only 2 tables, 8k of physical memory used, in practice however, you also need to have (portions of) your kernel space mapped, the stack, and other data areas
so you might have something like this:
PAGE DIRECTORY:
#1 -->Points to table #1
#2 ---> Not Present
#3 ---> points to table #2
#4 ----> points to table #3
#5 ----> NotPresent
.....
#850 ----> points to table #4
#851 ----> points to table #5
#852 -----> NotPresent
...
#1000 ---> points to table #6
#1001 ---> points to table #7
TABLE#1:
this table points to things in the lower parts of memory
TABLE#2:
this points to parts of your kernel
TABLE#3:
this points to parts of your kernel
TABLE#4:
this points to part of your application
TABLE#5:
this points to part of your application
TABLE#6:
this points to part of your application DATA (or mabey stack, or... etc.)
TABLE#7:
...
in this (not very good) example, you have 7 page tables, plus a page directory, for a total physical memory use of 8*4k = 32KB for page tables for this application
this isn't a very good example, but hopefully it can give you a better idea of what you need to do
typically, you will reserve space within the address space for the page tables, but the tables themeselves can be marked as NotPresent (and thus don't need to actually exist within physical memory) -- if you then need access to that particular portion of the address space, you will then need to allocate page tables
to map 4GB virtual address space (using standard, non-PAE paging) takes about 4MB -- so 4MB should (but doesn't necessarily need to be, but its easier if it is) reserved in each address space -- but only once in each address space
physical memory however, you don't need to have the full 4MB of tables -- there are 1024 tables that make up that 4MB of mapping tables -- theoretically, the only tables that have to exist are the directory and the specific page table that covers currently executing memory -- means only 2 tables, 8k of physical memory used, in practice however, you also need to have (portions of) your kernel space mapped, the stack, and other data areas
so you might have something like this:
PAGE DIRECTORY:
#1 -->Points to table #1
#2 ---> Not Present
#3 ---> points to table #2
#4 ----> points to table #3
#5 ----> NotPresent
.....
#850 ----> points to table #4
#851 ----> points to table #5
#852 -----> NotPresent
...
#1000 ---> points to table #6
#1001 ---> points to table #7
TABLE#1:
this table points to things in the lower parts of memory
TABLE#2:
this points to parts of your kernel
TABLE#3:
this points to parts of your kernel
TABLE#4:
this points to part of your application
TABLE#5:
this points to part of your application
TABLE#6:
this points to part of your application DATA (or mabey stack, or... etc.)
TABLE#7:
...
in this (not very good) example, you have 7 page tables, plus a page directory, for a total physical memory use of 8*4k = 32KB for page tables for this application
this isn't a very good example, but hopefully it can give you a better idea of what you need to do
every process (in PMode) will always have 4GB, regardless of how much memory you have (the amount of physical memory you have doesn't affect how much virtual address space each process has)
How it is handled in real world? For example in my Linux box i have 4G of mem so every process has 4MB of page directories and tables? For instance
ps -Al | wc -l gives me 149 processes, so i have about 600MB wasted?
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Re: Page directories per task
Yes, but since the kernel is the same for all processes, the page tables used to cover the kernel can be the same for every process (so you only need 512 kiB of page tables *total* to cover your entire 512 MiB kernel address space, rather than 512 kiB per process). Furthermore, your kernel generally will not occupy the entire 512 MiB space you've given it, so you won't even need 512 kiB.alix wrote:Thanks for your reply. But then i don't see in this case how can i virtually occupy kernel address space in each process. I should at least use a sufficient number of pages to get my kernel address space.NickJohnson wrote:You don't need to have page tables for a region of memory that is not being used. Each task needs one page directory, but generally not all 1024 page tables.
Re: Page directories per task
Also, how I did it, is at boot I allocate all the page tables over 0xC0000000 (which is 1 MiB ) so that I don't have to update all page directories if the kernel decides to change its address space.
Re: Page directories per task
Thanks for all the replies, that's make sense now.
I don't see the button "Solved" to mark the thread as solved!
I don't see the button "Solved" to mark the thread as solved!
Re: Page directories per task
Just edit the title of your original post.