Memory Management Question
Posted: Fri Aug 24, 2007 10:46 am
(Please excuse me if I sound like I've lost my mind, but I haven't done any real osdev in a few years.)
I've been working on the memory management part of my kernel, and have been thinking about writing kmalloc and such as to make kernel work a tad easier. (Note: I'm using paging.)
I was reading about ways to do this and that, linked lists, trees, etc. and I thought: "If I'm using paging, than can't I take a lot of small chunks of physical memory and make it appear to be continuous?" For example, if I were to use a list of physical memory like:
(Obtained from the physical memory manager.)
Then, if I were to call something like:
I would take the 8k, 2k, and 2k from the 16k and map them to one continuous region in the process's page tables.
So, when I would free the memory, I would just unmap them from the process's memory and set them to free in my list.
I wouldn't need to search at all. All I would need would be to take any region smaller or equal to or greater than what I needed until I had the amount. If there wasn't a piece small enough I would just ask for more physical memory from the kernel and break that up.
Am I really off? Have I lost my mind? Would this even work? I feel as though I am forgetting something important....
Thanks!
Alboin
I've been working on the memory management part of my kernel, and have been thinking about writing kmalloc and such as to make kernel work a tad easier. (Note: I'm using paging.)
I was reading about ways to do this and that, linked lists, trees, etc. and I thought: "If I'm using paging, than can't I take a lot of small chunks of physical memory and make it appear to be continuous?" For example, if I were to use a list of physical memory like:
Code: Select all
| 16k | 8k | 2k | ....
Then, if I were to call something like:
Code: Select all
ptr = kmalloc(12);
So, when I would free the memory, I would just unmap them from the process's memory and set them to free in my list.
I wouldn't need to search at all. All I would need would be to take any region smaller or equal to or greater than what I needed until I had the amount. If there wasn't a piece small enough I would just ask for more physical memory from the kernel and break that up.
Am I really off? Have I lost my mind? Would this even work? I feel as though I am forgetting something important....
Thanks!
Alboin