Page 1 of 1

Multiprocess and page directory

Posted: Tue Jan 07, 2014 10:38 am
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?

Re: Multiprocess and page directory

Posted: Tue Jan 07, 2014 11:04 am
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.

Re: Multiprocess and page directory

Posted: Tue Jan 07, 2014 11:49 am
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?

Re: Multiprocess and page directory

Posted: Tue Jan 07, 2014 7:21 pm
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

Re: Multiprocess and page directory

Posted: Tue Jan 07, 2014 11:10 pm
by brunexgeek
Great! Thanks for the help guys!