Chicken-and-egg dilemma in PMem manager!
Posted: Sun Dec 30, 2012 5:15 am
Wow, I'm pissed. Apparently I just got logged out, and the long post I just typed vanished.
I'm in no mood to write another essay, so here's the short and sweet version.
1. I identity map 4mb of memory at boot, them jump to long mode.
2. I have in place a table of page entry descriptors that 'describe' each page of memory.
3. I have a kmalloc function, that basically finds and hands out free pages.
4. It knows that once it hands out memory past 4mb, it needs to map() the memory or else it gets a #PF (duh)
5. So, I have a test routine that basically allocates memory in a while() loop.
6. Eventually, I reach 4mb. The allocator knows this, and calls map() to 1-1 map the memory.
7. Because I only created mappings for 4mb at bootstrap, these new mappings past 4mb don't exist.
8. The map() routine needs to put these page tables somewhere, so it calls kmalloc() to allocate memory for them.
9. It's past the 4mb limit so... See the problem?
If I don't map the memory in kmalloc(), I get a #PF after 4mb (duh).
If I don't allocate memory for the page tables in map(), they end up somewhere in memory (I'm guessing somewhere in my kernel), I get a #GPF (duh)
So. The question is; is it something wrong with my algorithm/approach to the pmem manager, or is it something obvious I'm not getting?
Thanks, guys.
I'm in no mood to write another essay, so here's the short and sweet version.
1. I identity map 4mb of memory at boot, them jump to long mode.
2. I have in place a table of page entry descriptors that 'describe' each page of memory.
3. I have a kmalloc function, that basically finds and hands out free pages.
4. It knows that once it hands out memory past 4mb, it needs to map() the memory or else it gets a #PF (duh)
5. So, I have a test routine that basically allocates memory in a while() loop.
6. Eventually, I reach 4mb. The allocator knows this, and calls map() to 1-1 map the memory.
7. Because I only created mappings for 4mb at bootstrap, these new mappings past 4mb don't exist.
8. The map() routine needs to put these page tables somewhere, so it calls kmalloc() to allocate memory for them.
9. It's past the 4mb limit so... See the problem?
If I don't map the memory in kmalloc(), I get a #PF after 4mb (duh).
If I don't allocate memory for the page tables in map(), they end up somewhere in memory (I'm guessing somewhere in my kernel), I get a #GPF (duh)
So. The question is; is it something wrong with my algorithm/approach to the pmem manager, or is it something obvious I'm not getting?
Thanks, guys.