diff --git a/headers/private/kernel/heap.h b/headers/private/kernel/heap.h index 4b55e683c1..72d7e489de 100644 --- a/headers/private/kernel/heap.h +++ b/headers/private/kernel/heap.h @@ -71,6 +71,7 @@ void heap_set_get_caller(heap_allocator* heap, addr_t (*getCaller)()); #endif status_t heap_init(addr_t heapBase, size_t heapSize); +status_t heap_init_post_area(); status_t heap_init_post_sem(); status_t heap_init_post_thread(); diff --git a/src/system/kernel/heap.cpp b/src/system/kernel/heap.cpp index b412adf7bf..d8153d95f0 100644 --- a/src/system/kernel/heap.cpp +++ b/src/system/kernel/heap.cpp @@ -2063,6 +2063,59 @@ heap_init(addr_t base, size_t size) } +status_t +heap_init_post_area() +{ + void *address = NULL; + area_id growHeapArea = create_area("dedicated grow heap", &address, + B_ANY_KERNEL_BLOCK_ADDRESS, HEAP_DEDICATED_GROW_SIZE, B_FULL_LOCK, + B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + if (growHeapArea < 0) { + panic("heap_init_post_area(): couldn't allocate dedicate grow heap " + "area"); + return growHeapArea; + } + + sGrowHeap = heap_create_allocator("grow", (addr_t)address, + HEAP_DEDICATED_GROW_SIZE, &sHeapClasses[0], false); + if (sGrowHeap == NULL) { + panic("heap_init_post_area(): failed to create dedicated grow heap\n"); + return B_ERROR; + } + + // create the VIP heap + static const heap_class heapClass = { + "VIP I/O", /* name */ + 100, /* initial percentage */ + B_PAGE_SIZE / 8, /* max allocation size */ + B_PAGE_SIZE, /* page size */ + 8, /* min bin size */ + 4, /* bin alignment */ + 8, /* min count per page */ + 16 /* max waste per page */ + }; + + area_id vipHeapArea = create_area("VIP heap", &address, + B_ANY_KERNEL_ADDRESS, VIP_HEAP_SIZE, B_FULL_LOCK, + B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + if (vipHeapArea < 0) { + panic("heap_init_post_area(): couldn't allocate VIP heap area"); + return B_ERROR; + } + + sVIPHeap = heap_create_allocator("VIP heap", (addr_t)address, + VIP_HEAP_SIZE, &heapClass, false); + if (sVIPHeap == NULL) { + panic("heap_init_post_area(): failed to create VIP heap\n"); + return B_ERROR; + } + + dprintf("heap_init_post_area(): created VIP heap: %p\n", sVIPHeap); + + return B_OK; +} + + status_t heap_init_post_sem() { @@ -2098,23 +2151,6 @@ status_t heap_init_post_thread() { #if !USE_SLAB_ALLOCATOR_FOR_MALLOC - void *address = NULL; - area_id growHeapArea = create_area("dedicated grow heap", &address, - B_ANY_KERNEL_BLOCK_ADDRESS, HEAP_DEDICATED_GROW_SIZE, B_FULL_LOCK, - B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); - if (growHeapArea < 0) { - panic("heap_init_post_thread(): couldn't allocate dedicate grow heap " - "area"); - return growHeapArea; - } - - sGrowHeap = heap_create_allocator("grow", (addr_t)address, - HEAP_DEDICATED_GROW_SIZE, &sHeapClasses[0], false); - if (sGrowHeap == NULL) { - panic("heap_init_post_thread(): failed to create dedicated grow heap\n"); - return B_ERROR; - } - sHeapGrowThread = spawn_kernel_thread(heap_grow_thread, "heap grower", B_URGENT_PRIORITY, NULL); if (sHeapGrowThread < 0) { @@ -2146,35 +2182,6 @@ heap_init_post_thread() } } - // create the VIP heap - static const heap_class heapClass = { - "VIP I/O", /* name */ - 100, /* initial percentage */ - B_PAGE_SIZE / 8, /* max allocation size */ - B_PAGE_SIZE, /* page size */ - 8, /* min bin size */ - 4, /* bin alignment */ - 8, /* min count per page */ - 16 /* max waste per page */ - }; - - area_id vipHeapArea = create_area("VIP heap", &address, - B_ANY_KERNEL_ADDRESS, VIP_HEAP_SIZE, B_FULL_LOCK, - B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); - if (vipHeapArea < 0) { - panic("heap_init_post_thread(): couldn't allocate VIP heap area"); - return B_ERROR; - } - - sVIPHeap = heap_create_allocator("VIP heap", (addr_t)address, - VIP_HEAP_SIZE, &heapClass, false); - if (sVIPHeap == NULL) { - panic("heap_init_post_thread(): failed to create VIP heap\n"); - return B_ERROR; - } - - dprintf("heap_init_post_thread(): created VIP heap: %p\n", sVIPHeap); - resume_thread(sHeapGrowThread); #endif // !USE_SLAB_ALLOCATOR_FOR_MALLOC diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index c331be2731..d9371d8879 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -3608,6 +3608,10 @@ vm_init(kernel_args* args) VMAddressSpace::Init(); reserve_boot_loader_ranges(args); +#if !USE_SLAB_ALLOCATOR_FOR_MALLOC + heap_init_post_area(); +#endif + // Do any further initialization that the architecture dependant layers may // need now arch_vm_translation_map_init_post_area(args);