Kernel heap now allocates all required pages at once
As opposed to allocating pages individually
This commit is contained in:
22
src/heap.c
22
src/heap.c
@@ -41,18 +41,34 @@ int kminit(void *base, size_t heap_size)
|
||||
.size = 0
|
||||
};
|
||||
memmap_insert_region(&map, base, heap_size, M_AVAILABLE);
|
||||
for(void *p = base; p < (base + heap_size); p += page_size)
|
||||
physaddr_t phys_addr = reserve_pages(heap_size);
|
||||
if(phys_addr == ENOMEM)
|
||||
{
|
||||
return ENOMEM;
|
||||
}
|
||||
for(unsigned long off = 0; off < heap_size; off += page_size)
|
||||
{
|
||||
if((page_type(base + off) & PAGE_PRESENT))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if(map_page(base + off, phys_addr + off, PAGE_RW))
|
||||
{
|
||||
return ENOMEM;
|
||||
}
|
||||
}
|
||||
/*for(void *p = base; p < (base + heap_size); p += page_size)
|
||||
{
|
||||
if((page_type(p) & PAGE_PRESENT))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
physaddr_t frame = reserve_page();
|
||||
//physaddr_t frame = reserve_page();
|
||||
if(frame == ENOMEM || map_page(p, frame, PAGE_RW))
|
||||
{
|
||||
return ENOMEM;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return list_alloc_init(&system_heap, &map);
|
||||
}
|
||||
|
||||
|
||||
18
src/mmgr.c
18
src/mmgr.c
@@ -15,6 +15,7 @@ buddy_descriptor_t page_alloc;
|
||||
physaddr_t reserve_pages(size_t size)
|
||||
{
|
||||
unsigned long location = buddy_reserve(&page_alloc, size);
|
||||
printf("Reserved >=%08x pages at %08x\n", size, location);
|
||||
if(location != NOMEM)
|
||||
{
|
||||
return location;
|
||||
@@ -117,29 +118,12 @@ error_t initialize_page_map(memory_map_t *map, void *base, size_t memory_size, u
|
||||
}
|
||||
}
|
||||
|
||||
printf("Initializing page allocator...\n");
|
||||
|
||||
if(buddy_alloc_init(&page_alloc, map))
|
||||
{
|
||||
return ENOMEM;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("page_alloc = {\n\t" \
|
||||
"avail = %08x\n\t" \
|
||||
"block_map = %08x\n\t" \
|
||||
"block_map_size = %08x\n\t" \
|
||||
"max_kval = %i\n\t" \
|
||||
"block_size = %i\n\t" \
|
||||
"offset = %08x\n\t" \
|
||||
"free_block_count = %08x\n}",
|
||||
page_alloc.avail,
|
||||
page_alloc.block_map,
|
||||
page_alloc.block_map_size,
|
||||
page_alloc.max_kval,
|
||||
page_alloc.block_size,
|
||||
page_alloc.offset,
|
||||
page_alloc.free_block_count);
|
||||
return ENONE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user