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:
parent
0be6e97788
commit
c49aa60ace
@ -26,10 +26,6 @@
|
||||
#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.
|
||||
|
||||
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include "slab_private.h"
|
||||
|
||||
#include <kernel.h> // for ROUNDUP
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user