From 321ee820ea6c03f95ab426c8d61cb63ff78c8800 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Wed, 2 Jul 2008 13:00:13 +0000 Subject: [PATCH] * Fix the broken size/alignment computations for area allocations by replacing them with the ROUNDUP macro that was specifically made for this task so that too tired developers do not mess up the calculations... * Don't use area allocation during kernel startup (not that it really happened). * Minor simplification of similar calculations in heap_attach(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26221 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/heap.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/system/kernel/heap.cpp b/src/system/kernel/heap.cpp index bd71fe9b59..d97ed4c0e4 100644 --- a/src/system/kernel/heap.cpp +++ b/src/system/kernel/heap.cpp @@ -753,8 +753,8 @@ heap_attach(addr_t base, size_t size, uint32 heapClass) size -= pageTableSize; // the rest is now actually usable memory (rounded to the next page) - heap->base = (addr_t)(base + B_PAGE_SIZE - 1) / B_PAGE_SIZE * B_PAGE_SIZE; - heap->size = (size_t)(size / B_PAGE_SIZE) * B_PAGE_SIZE; + heap->base = ROUNDUP(base, B_PAGE_SIZE); + heap->size = (size / B_PAGE_SIZE) * B_PAGE_SIZE; // now we know the real page count pageCount = heap->size / heap->page_size; @@ -1453,15 +1453,15 @@ memalign(size_t alignment, size_t size) return NULL; } - if (size > HEAP_AREA_USE_THRESHOLD) { + if (!kernel_startup && size > HEAP_AREA_USE_THRESHOLD) { // don't even attempt such a huge allocation - use areas instead dprintf("heap: using area for huge allocation of %lu bytes!\n", size); size_t areaSize = size + sizeof(area_allocation_info); if (alignment != 0) - areaSize = (areaSize + alignment - 1) / alignment; + areaSize = ROUNDUP(areaSize, alignment); void *address = NULL; - areaSize = (areaSize + B_PAGE_SIZE - 1) / B_PAGE_SIZE; + areaSize = ROUNDUP(areaSize, B_PAGE_SIZE); area_id allocationArea = create_area("memalign area", &address, B_ANY_KERNEL_BLOCK_ADDRESS, areaSize, B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); @@ -1480,7 +1480,7 @@ memalign(size_t alignment, size_t size) address = (void *)((addr_t)address + sizeof(area_allocation_info)); if (alignment != 0) - address = (void *)(((addr_t)address + alignment - 1) / alignment); + address = (void *)ROUNDUP((addr_t)address, alignment); dprintf("heap: allocated area %ld for huge allocation returning %p\n", allocationArea, address);