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
This commit is contained in:
Hugo Santos 2007-04-29 15:13:09 +00:00
parent 0be6e97788
commit c49aa60ace
2 changed files with 32 additions and 15 deletions

View File

@ -26,10 +26,6 @@
#include <new> #include <new>
// 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. // TODO kMagazineCapacity should be dynamically tuned per cache.

View File

@ -10,6 +10,8 @@
#include "slab_private.h" #include "slab_private.h"
#include <kernel.h> // for ROUNDUP
#include <stdio.h> #include <stdio.h>
#define DEBUG_ALLOCATOR #define DEBUG_ALLOCATOR
@ -35,6 +37,12 @@ struct boundary_tag {
#endif #endif
}; };
struct area_boundary_tag {
area_id area;
boundary_tag tag;
};
static const uint32 kBoundaryMagic = 0x6da78d13; static const uint32 kBoundaryMagic = 0x6da78d13;
@ -68,16 +76,26 @@ block_alloc(size_t size)
object_cache *cache = size_to_cache(size + sizeof(boundary_tag)); object_cache *cache = size_to_cache(size + sizeof(boundary_tag));
void *block; void *block;
boundary_tag *tag;
if (cache) { 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 { } else {
// TODO create areas void *pages;
panic("allocator: unimplemented"); area_id area = create_area("alloc'ed block", &pages,
return NULL; 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; tag->size = size;
@ -85,7 +103,7 @@ block_alloc(size_t size)
tag->magic = kBoundaryMagic; tag->magic = kBoundaryMagic;
#endif #endif
return ((uint8 *)block) + sizeof(boundary_tag); return block;
} }
@ -101,10 +119,13 @@ block_free(void *block)
#endif #endif
object_cache *cache = size_to_cache(tag->size); object_cache *cache = size_to_cache(tag->size);
if (cache == NULL) if (cache == NULL) {
panic("allocator: unimplemented"); area_boundary_tag *areaTag = (area_boundary_tag *)(((uint8 *)block)
- sizeof(area_boundary_tag));
object_cache_free(cache, tag); delete_area(areaTag->area);
} else {
object_cache_free(cache, tag);
}
} }