Changeset 23939

Show
Ignore:
Timestamp:
02/10/08 15:00:13 (3 months ago)
Author:
mmlr
Message:
Complete rework of the heap implementation. Freelists are now part of the pages
and pages are now kept in lists as well. This allows to return free pages once
a bin does not need them anymore. Partially filled pages are kept in a sorted
linked list so that allocation will always happen on the fullest page - this
favours having full pages and makes it more likely lightly used pages will get
completely empty so they can be returned. Generally this now goes more in the
direction of a slab allocator.
The allocation logic has been extracted, so a heap is now simply attachable to
a region of memory. This allows for multiple heaps and for dynamic growing. In
case the allocator runs out of free pages, an asynchronous growing thread is
notified to create a new area and attach a new heap to it.
By default the kernel heap is now set to 16MB and grows by 8MB each time all
heaps run full.
This should solve quite a few issues, like certain bins just claiming all pages
so that even if there is free space nothing can be allocated. Also it obviously
does aways with filling the heap page by page until it overgrows.
I think this is now a well performing and scalable allocator we can live with
for quite some time. It is well tested under emulation and real hardware and
performs as expected. If problems come up there is an extensive sanity checker
that can be enabled by PARANOID_VALIDATION that covers most aspects of the
allocator. For normal operation this is not necessary though and is therefore
disabled by default.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • haiku/trunk/src/system/kernel/Jamfile

    r23809 r23939  
    2222        cpu.c 
    2323        elf.cpp 
    24         heap.c 
     24        heap.cpp 
    2525        image.c 
    2626        int.c 
  • haiku/trunk/src/system/kernel/vm/vm.cpp

    r23906 r23939  
    2626#include <vm_low_memory.h> 
    2727#include <file_cache.h> 
    28 #include <memheap.h> 
     28#include <heap.h> 
    2929#include <condition_variable.h> 
    3030#include <debug.h> 
     
    34813481        sAvailableMemory = vm_page_num_pages() * B_PAGE_SIZE; 
    34823482 
    3483         // reduce the heap size if we have not so much RAM 
    3484         size_t heapSize = HEAP_SIZE; 
    3485         if (sAvailableMemory < 100 * 1024 * 1024) 
    3486                 heapSize /= 4; 
    3487         else if (sAvailableMemory < 200 * 1024 * 1024) 
    3488                 heapSize /= 2; 
    3489         else if (sAvailableMemory >= 1024 * 1024 * 1024) 
    3490                 heapSize *= 2; 
    3491  
    34923483        // map in the new heap and initialize it 
     3484        size_t heapSize = INITIAL_HEAP_SIZE; 
    34933485        addr_t heapBase = vm_allocate_early(args, heapSize, heapSize, 
    34943486                B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); 
     
    36083600 
    36093601        slab_init_post_sem(); 
    3610  
    3611         return heap_init_post_sem(args); 
     3602        return heap_init_post_sem(); 
    36123603} 
    36133604 
     
    36193610        vm_daemon_init(); 
    36203611        vm_low_memory_init_post_thread(); 
    3621  
    3622         return heap_init_post_thread(args); 
     3612        return heap_init_post_thread(); 
    36233613} 
    36243614