kernel now keeping track of total/free number of physical pages instead of free/used

git-svn-id: svn://anubis/hos/trunk@90 5b3e749e-e535-0410-8002-a9bb6afbdfca
This commit is contained in:
josh 2010-01-22 20:51:34 +00:00
parent dccecb054b
commit 0bc304328d

View File

@ -14,7 +14,7 @@ static pagedirectory_entry_t * page_directory;
static mm_mem_range_t mm_mmap_entries[MM_MAX_MMAP_ENTRIES]; static mm_mem_range_t mm_mmap_entries[MM_MAX_MMAP_ENTRIES];
static int mm_mmap_num_entries = 0; static int mm_mmap_num_entries = 0;
static int mm_num_free_pages = 0; static int mm_num_free_pages = 0;
static int mm_num_used_pages = 0; static int mm_num_total_pages = 0;
static u32_t * mm_free_page_ptr = NULL; static u32_t * mm_free_page_ptr = NULL;
gdtr_t mm_gdtr; gdtr_t mm_gdtr;
static u64_t * mm_gdt; static u64_t * mm_gdt;
@ -47,6 +47,11 @@ void mm_record_mmap_entry(mb_mmap_t * mmap)
void mm_bootstrap() void mm_bootstrap()
{ {
u32_t max_ram_address = KERNEL_PHYSICAL_ADDRESS + KERNEL_SIZE - 1; u32_t max_ram_address = KERNEL_PHYSICAL_ADDRESS + KERNEL_SIZE - 1;
/* this function requires a big enough initial stack to run */
BUILD_BUG_ON((STACK_INITIAL_SIZE * PAGE_SIZE) < 8000);
u32_t page_alloc_pages[1025];
u32_t num_page_alloc_pages = 0;
mm_free_page_ptr = NULL;
if (mm_mmap_num_entries < 1) if (mm_mmap_num_entries < 1)
{ {
@ -57,6 +62,7 @@ void mm_bootstrap()
{ {
u32_t base_address = mm_mmap_entries[mmap_idx].base; u32_t base_address = mm_mmap_entries[mmap_idx].base;
u32_t address_limit = base_address + mm_mmap_entries[mmap_idx].length; u32_t address_limit = base_address + mm_mmap_entries[mmap_idx].length;
if (base_address & PAGE_LOW_MASK) if (base_address & PAGE_LOW_MASK)
{ {
/* start of this mmap range is not page-aligned */ /* start of this mmap range is not page-aligned */
@ -78,8 +84,9 @@ void mm_bootstrap()
* loop through every page in the mmap range and add * loop through every page in the mmap range and add
* pages into the free page linked list * pages into the free page linked list
*/ */
u32_t * last_page = NULL; for (u32_t * last_page = NULL;
while (base_address < address_limit) base_address < address_limit;
base_address += PAGE_SIZE)
{ {
/* check to make sure the RAM page is ok */ /* check to make sure the RAM page is ok */
if ( base_address > 0 /* don't map address 0 */ if ( base_address > 0 /* don't map address 0 */
@ -101,7 +108,7 @@ void mm_bootstrap()
last_page = page_virtual_address; last_page = page_virtual_address;
mm_num_free_pages++; mm_num_free_pages++;
} }
base_address += PAGE_SIZE; mm_num_total_pages++;
} }
} }
@ -266,7 +273,6 @@ u32_t mm_early_page_alloc()
page_address = (u32_t) mm_free_page_ptr; page_address = (u32_t) mm_free_page_ptr;
mm_free_page_ptr = (u32_t *) *page_ptr; mm_free_page_ptr = (u32_t *) *page_ptr;
mm_num_free_pages--; mm_num_free_pages--;
mm_num_used_pages++;
} }
return page_address; return page_address;
} }
@ -284,7 +290,6 @@ u32_t mm_page_alloc()
page_address = (u32_t) mm_free_page_ptr; page_address = (u32_t) mm_free_page_ptr;
mm_free_page_ptr = (u32_t *) *page_ptr; mm_free_page_ptr = (u32_t *) *page_ptr;
mm_num_free_pages--; mm_num_free_pages--;
mm_num_used_pages++;
} }
return page_address; return page_address;
} }
@ -302,6 +307,6 @@ void mm_print_memory_map()
mm_mmap_entries[i].length >> 10, mm_mmap_entries[i].length >> 10,
mm_mmap_entries[i].length >> 20); mm_mmap_entries[i].length >> 20);
} }
kprintf("Used pages: %d\n", mm_num_used_pages); kprintf("Used pages: %d\n", mm_num_total_pages - mm_num_free_pages);
kprintf("Free pages: %d\n", mm_num_free_pages); kprintf("Free pages: %d\n", mm_num_free_pages);
} }