Added ObjectCache::objects_per_slab, which allowed to squash the TODO in

object_cache_reserve_internal().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35203 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-01-20 17:46:06 +00:00
parent bb439b871e
commit 4ebe37ab69
4 changed files with 7 additions and 4 deletions
@@ -72,6 +72,8 @@ HashedObjectCache::Create(const char* name, size_t object_size,
cache->slab_size = max_c(16 * B_PAGE_SIZE, 8 * object_size);
cache->lower_boundary = __fls0(cache->object_size);
cache->objects_per_slab = cache->slab_size / cache->object_size;
return cache;
}
+1
View File
@@ -47,6 +47,7 @@ struct ObjectCache : DoublyLinkedListLinkImpl<ObjectCache> {
// minimum number of free objects
size_t slab_size;
size_t objects_per_slab;
size_t usage;
size_t maximum;
uint32 flags;
+1 -4
View File
@@ -316,10 +316,7 @@ static status_t
object_cache_reserve_internal(ObjectCache* cache, size_t objectCount,
uint32 flags, bool unlockWhileAllocating)
{
size_t numBytes = objectCount * cache->object_size;
size_t slabCount = ((numBytes - 1) / cache->slab_size) + 1;
// TODO: This also counts the unusable space of each slab, which can
// sum up.
size_t slabCount = (objectCount - 1) / cache->objects_per_slab + 1;
while (slabCount > 0) {
slab* newSlab = cache->CreateSlab(flags, unlockWhileAllocating);
@@ -35,6 +35,9 @@ SmallObjectCache::Create(const char* name, size_t object_size,
else
cache->slab_size = B_PAGE_SIZE;
cache->objects_per_slab = (cache->slab_size - sizeof(slab))
/ cache->object_size;
return cache;
}