Multiprocess and page directory

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
brunexgeek
Member
Member
Posts: 45
Joined: Wed Dec 25, 2013 11:51 am

Multiprocess and page directory

Post by brunexgeek »

I'm implementing support for multiprocess in my OS and I don't have much experience with this. AFAIK I need to create a page directory for each process to isolate them and each page directory should map the kernel address space.

The point is: if the kernel change its address space (e.g. allocate new pages in a syscall) the page directory of other processes will became 'outdated'. I think this can cause a lot of troubles.

I found nothing about this problem in the 'literature'. This problem really exists?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Multiprocess and page directory

Post by Combuster »

The reason you won't be able to find much documentation on it is because you added a "feature" nobody else did.

Mapping the kernel freshly in each address space is a waste of RAM because you seem to add new page tables and make them simple duplicates of existing kernel page tables. Therefore you normally use preallocated page tables for the kernel and use those by reference in every page directory. That also means that if you update the kernel address space once, you don't need to modify 100 copies of it, and you can create a fresh address space costing only 4K RAM for a single page directory, rather than one directory and several tables.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
brunexgeek
Member
Member
Posts: 45
Joined: Wed Dec 25, 2013 11:51 am

Re: Multiprocess and page directory

Post by brunexgeek »

Combuster wrote:The reason you won't be able to find much documentation on it is because you added a "feature" nobody else did.

Mapping the kernel freshly in each address space is a waste of RAM because you seem to add new page tables and make them simple duplicates of existing kernel page tables. Therefore you normally use preallocated page tables for the kernel and use those by reference in every page directory. That also means that if you update the kernel address space once, you don't need to modify 100 copies of it, and you can create a fresh address space costing only 4K RAM for a single page directory, rather than one directory and several tables.
I was thinking to create the page directory of the new process and then 'copy' some entries from kernel page directory. Thus, the first 512 entries of the process PD still empty (before binary loading) and the other 512 entries is a copy of the last 512 entries of the kernel PD (my kernel uses the higher 2GB).

I think its something like you said (except the preallocation). I understand that you suggest to create every PT (preallocate them) for the kernel before create the processes PDs, therefore my processes PD will have the references for all kernel page tables even them is not used yet.

It's right?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Multiprocess and page directory

Post by Brendan »

Hi,
brunexgeek wrote:I think its something like you said (except the preallocation). I understand that you suggest to create every PT (preallocate them) for the kernel before create the processes PDs, therefore my processes PD will have the references for all kernel page tables even them is not used yet.

It's right?
Yes. If all virtual address spaces use the same pre-allocated page tables for kernel-space; then any changes to the page table entries will effect all virtual address spaces.

Of course this isn't the only way to solve the problem, but it's definitely the easiest way; as long as you don't want to change page tables after they're pre-allocated, don't mind consuming RAM for page tables that might not actually get used, and don't have different "kernel page tables" for different cases (e.g. different page tables for CPUs in different NUMA domains).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
brunexgeek
Member
Member
Posts: 45
Joined: Wed Dec 25, 2013 11:51 am

Re: Multiprocess and page directory

Post by brunexgeek »

Great! Thanks for the help guys!
Post Reply