WinExperements wrote:
Okay so i just added test kernel heap implementation. And got the same problem that i have before, when the heap is trying to extend himself(like when i allocate 120MB of memory) the pmml_alloc(used for mapping) returns physically valid but not mapped address. So i here to ask did i need map full memory to correctly use kernel heap, if no can you say how i can correctly fix the problem with mapping? My kernel heap implementation use physical page allocator to extend himself.
Also what I should use for non kernel heap memory management? Can I use my PMM that I use previous to extend the kernel heap?
You can manage kernel memory in the same way as you manage user memory.
You have memory segments (not x86 segments, but base/size tuples that define a virtual address range.)
You have segments for kernel text and data, then a segment for the heap, as well as any segments to describe further memory mappings in the kernel virtual address space.
Then all you need is some code to map a page fault address to a segment in the kernel address space, then add segment code to translate a segment offset to a physical page, then you just need code to map a virtual address to a physical address.
Once you have that in place, your kernel then uses the same virtual address resolution that your user space will use. All pretty much general purpose.
I have special kernel heap segment drivers, that work without using the heap (can't have the heap address space dependent on the heap itself), but all the other kernel virtual address segments work the same for kernel and user address spaces.
Early in my boot process, I reserve address space for the heap using the heap segment driver, but without allocating any physical memory to the underlying mappings. Physical pages are then mapped on demand as my heap grows, up to the heap limit, using the same page fault handling code. Of course, you have to be really careful when you run out of memory, as anything that allocates heap memory when handling out of memory situations can result in death spiral with recursive failing page faults.
It's also a bit fiddly to bootstrap, as the underlying early stages of virtual memory management needs to work without access to heap memory.