Kernel Address Space
Kernel Address Space
The operating system I'm developing uses the first gig of virtual memory to hold everything kernel related, including the binary image, BSS, the heap. The heap is used, of course, for things like the linked lists that have process information. I have made it so that for that every process created, the first 4 mb are also mapped to the kernel image, so that when an interrupt is called, it doesn't switch address spaces, and can run the handler while still in the process's context. However, when something like a system call occurs, and I will need to access kernel data, for things like allocating more memory to the process, do I have to switch address spaces, for every single system call? That seems rather inefficient. Another solution would be to map the entirety of all allocated kernel address space in userspace as well (much like the first 4mb), but it would require each time kmalloc is called to update every single process's page table. Any ideas?
What I mean is that the kernel memory (a gigabyte) is obviously not gonna be completely mapped. Probably only the first few megabytes will be used, but whenever this needs to be changed (ie, sbrk is called) in the kernel, because it needs more space, it would have to correspondly change the mappings in every PD of every process.
Hi,
Cheers,
Brendan
You can map every page directory into kernel space, so that you can add page tables in them without changing address spaces....vialator wrote:What I mean is that the kernel memory (a gigabyte) is obviously not gonna be completely mapped. Probably only the first few megabytes will be used, but whenever this needs to be changed (ie, sbrk is called) in the kernel, because it needs more space, it would have to correspondly change the mappings in every PD of every process.
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.
Well, I found a solution that your previous post inspired. I'm going to allocate a page for each of the Page Tables for the first gigabyte of memory. This will "waste" 1 megabyte, but will make it so the addresses of the page tables are already known, and at process creation, can be set, so that they don't have to be edited later. When the kernel actually needs to allocate memory, it already has the page tables to add to.
exactly what i have done but, what shall we do if we run out of page tables and need to allocate a new page dir.Brendan wrote: You can map every page directory into kernel space, so that you can add page tables in them without changing address spaces....
We will also update all processes.
To write an OS you need 2 minds one for coding and other for debugging.
Hi,
It doesn't necessarily need to be done in that order either. For example, you could allocate a new physical page for the new page directory and try to map it into kernel space and find out there isn't enough room; then allocate a new physical page for a new page table, insert the page table into all page directories, and try to map it into kernel space again.
In both of these cases you may need code to back out of the operation (for e.g. if you can't allocate the second page because there isn't enough memory, free the previously allocated page before returning an "out of memory" error).
Cheers,
Brendan
That doesn't create any problem - allocate a new physical page for the new page table, insert the page table into all page directories, then allocate a new physical page for the new page directory and map it into the new page table in kernel space.ces_mohab wrote:exactly what i have done but, what shall we do if we run out of page tables and need to allocate a new page dir.Brendan wrote:You can map every page directory into kernel space, so that you can add page tables in them without changing address spaces....
It doesn't necessarily need to be done in that order either. For example, you could allocate a new physical page for the new page directory and try to map it into kernel space and find out there isn't enough room; then allocate a new physical page for a new page table, insert the page table into all page directories, and try to map it into kernel space again.
In both of these cases you may need code to back out of the operation (for e.g. if you can't allocate the second page because there isn't enough memory, free the previously allocated page before returning an "out of memory" error).
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.