question regarding having the kernel mapped in all address s

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
proxy

question regarding having the kernel mapped in all address s

Post by proxy »

ok, so i am working on setting up my "process" objects and i plan to go the route of having the kernel's memory mapped into all processes address space. However, there is something that occured to me.

I have a kernel heap which grows (up to a certain amount). As it does, it adds pages into the heap as neccessary. Right now the main "easy" way i can think of handling this is to pre-map in all the page tables into the kernel's page directory (not the pages, just the page tables) for the whole size the heap is allowed to grow.

Is there any better way to address this issue?

And on a similar note, what about if i want to make parts of my kernel abled to be paged out, do i need to go through ever running process and update that region of there page table entries?

thanks.

proxy
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:question regarding having the kernel mapped in all addres

Post by Brendan »

Hi,
proxy wrote: ok, so i am working on setting up my "process" objects and i plan to go the route of having the kernel's memory mapped into all processes address space. However, there is something that occured to me.

I have a kernel heap which grows (up to a certain amount). As it does, it adds pages into the heap as neccessary. Right now the main "easy" way i can think of handling this is to pre-map in all the page tables into the kernel's page directory (not the pages, just the page tables) for the whole size the heap is allowed to grow.

Is there any better way to address this issue?
This would depend on the maximum size of the kernel's heap, and how likely it is that the maximum heap size is needed - if your heap can grow to 512 MB you'd need to pre-allocate 512 KB of memory for page tables (whether it's used or not).
proxy wrote:And on a similar note, what about if i want to make parts of my kernel abled to be paged out, do i need to go through every running process and update that region of there page table entries?
You'd need to put all of the kernel's page tables into every address space. If you change a page table entry within a page table then the change will automatically occur in all address spaces that use that page table (with the minor exception of invalidating the TLBs in a multi-CPU situation). The only time you'd need to manually mess with all address spaces is when you change one of the kernel's page directory entries (ie. add or remove a page table to the kernel's space).

If all of the page tables used by the kernel are all pre-allocated and never change then you'd never need to worry about changing the paging data for every address space (which is a reason in favour of pre-allocating page tables for the kernel's heap).

You'd also need to be extremely careful with paging parts of the kernel's space to disk - you can get a deadlock (where the kernel needs to get data from the swap in order to get data from the swap). This means things that are used for the disk device driver/s, swap file, memory management, scheduler, IRQ and exception handlers (and possibly IPC) can't be swapped to disk. If you're doing a micro-kernel that doesn't leave much that can be safely swapped to disk (ie. it wouldn't be worth bothering with). For a monolithic kernel it can be a different story though.


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.
proxy

Re:question regarding having the kernel mapped in all addres

Post by proxy »

yea, right now my kernel heap has a max of 64 megs (seem like enough?) so that's 16 page tables if my math serves me right. This seems reasonable to pre-allocate. So unless you have a better suggestion (always open to suggestions) I think that's the way to go.

proxy
Post Reply