* Reverted r35203, i.e. ObjectCache::object_per_slab is gone again.

* Changed the semantics of object_cache_reserve_internal(). Now it makes sure
  the given number of objects are free. As a side effect this also changes
  the semantics of object_cache_reserve() similarly, though I have trouble
  seeing the purpose of the function in the first place.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35204 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2010-01-20 18:05:00 +00:00
parent 4ebe37ab69
commit 8766b8b4b9
4 changed files with 9 additions and 22 deletions

View File

@ -72,8 +72,6 @@ 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;
}

View File

@ -47,7 +47,6 @@ 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;

View File

@ -312,20 +312,19 @@ increase_object_reserve(ObjectCache* cache)
}
/*! Makes sure that \a objectCount objects can be allocated.
*/
static status_t
object_cache_reserve_internal(ObjectCache* cache, size_t objectCount,
uint32 flags, bool unlockWhileAllocating)
{
size_t slabCount = (objectCount - 1) / cache->objects_per_slab + 1;
while (slabCount > 0) {
while (objectCount > cache->total_objects - cache->used_count) {
slab* newSlab = cache->CreateSlab(flags, unlockWhileAllocating);
if (newSlab == NULL)
return B_NO_MEMORY;
cache->empty.Add(newSlab);
cache->empty_count++;
slabCount--;
}
return B_OK;
@ -422,18 +421,12 @@ object_cache_resizer(void*)
MutexLocker cacheLocker(cache->lock);
size_t freeObjects = cache->total_objects - cache->used_count;
while (freeObjects < cache->min_object_reserve) {
status_t error = object_cache_reserve_internal(cache,
cache->min_object_reserve - freeObjects, 0, true);
if (error != B_OK) {
dprintf("object cache resizer: Failed to resize object cache "
"%p!\n", cache);
break;
}
freeObjects = cache->total_objects - cache->used_count;
status_t error = object_cache_reserve_internal(cache,
cache->min_object_reserve, 0, true);
if (error != B_OK) {
dprintf("object cache resizer: Failed to resize object cache "
"%p!\n", cache);
break;
}
request->pending = false;

View File

@ -35,9 +35,6 @@ 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;
}