From c49aa60ace411ea452ebf3ad0b49d1da9d3cc10c Mon Sep 17 00:00:00 2001 From: Hugo Santos Date: Sun, 29 Apr 2007 15:13:09 +0000 Subject: [PATCH] cache allocator: for allocations > 8k create areas, and delete them on free. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20902 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/slab/Slab.cpp | 4 --- src/system/kernel/slab/allocator.cpp | 43 +++++++++++++++++++++------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/system/kernel/slab/Slab.cpp b/src/system/kernel/slab/Slab.cpp index 49be17fc73..a617e0e885 100644 --- a/src/system/kernel/slab/Slab.cpp +++ b/src/system/kernel/slab/Slab.cpp @@ -26,10 +26,6 @@ #include -// TODO all of the small allocations we perform here will fallback -// to the internal allocator which in the future will use this -// same code. We'll have to resolve all of the dependencies -// then, for now, it is still not required. // TODO kMagazineCapacity should be dynamically tuned per cache. diff --git a/src/system/kernel/slab/allocator.cpp b/src/system/kernel/slab/allocator.cpp index ea75a8d244..72a6dfa8c5 100644 --- a/src/system/kernel/slab/allocator.cpp +++ b/src/system/kernel/slab/allocator.cpp @@ -10,6 +10,8 @@ #include "slab_private.h" +#include // for ROUNDUP + #include #define DEBUG_ALLOCATOR @@ -35,6 +37,12 @@ struct boundary_tag { #endif }; +struct area_boundary_tag { + area_id area; + boundary_tag tag; +}; + + static const uint32 kBoundaryMagic = 0x6da78d13; @@ -68,16 +76,26 @@ block_alloc(size_t size) object_cache *cache = size_to_cache(size + sizeof(boundary_tag)); void *block; + boundary_tag *tag; if (cache) { - block = object_cache_alloc(cache, 0); + tag = (boundary_tag *)object_cache_alloc(cache, 0); + if (tag == NULL) + return NULL; + block = tag + 1; } else { - // TODO create areas - panic("allocator: unimplemented"); - return NULL; - } + void *pages; + area_id area = create_area("alloc'ed block", &pages, + B_ANY_KERNEL_ADDRESS, ROUNDUP(size + sizeof(area_boundary_tag), + B_PAGE_SIZE), B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + if (area < B_OK) + return NULL; - boundary_tag *tag = (boundary_tag *)block; + area_boundary_tag *areaTag = (area_boundary_tag *)pages; + areaTag->area = area; + tag = &areaTag->tag; + block = areaTag + 1; + } tag->size = size; @@ -85,7 +103,7 @@ block_alloc(size_t size) tag->magic = kBoundaryMagic; #endif - return ((uint8 *)block) + sizeof(boundary_tag); + return block; } @@ -101,10 +119,13 @@ block_free(void *block) #endif object_cache *cache = size_to_cache(tag->size); - if (cache == NULL) - panic("allocator: unimplemented"); - - object_cache_free(cache, tag); + if (cache == NULL) { + area_boundary_tag *areaTag = (area_boundary_tag *)(((uint8 *)block) + - sizeof(area_boundary_tag)); + delete_area(areaTag->area); + } else { + object_cache_free(cache, tag); + } }