From 1c164de7d21bd20efda561b647ebe08717699096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 1 Mar 2010 16:35:17 +0000 Subject: [PATCH] * Quick&dirty fix of a race condition that caused an endless loop in object_cache_alloc(): the ObjectCache::total_objects count was increased in ObjectCache::InitSlab(), but the slab was really only added at a later point between the cache could be unlocked. * If a second object_cache_reserve_internal() managed to be called while the lock was unlocked, it would see that there has to be space available, and will then return -- however, since the other thread could not yet place the slab into the cache, object_cache_alloc() cannot find it. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35702 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/slab/ObjectCache.cpp | 3 --- src/system/kernel/slab/Slab.cpp | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/system/kernel/slab/ObjectCache.cpp b/src/system/kernel/slab/ObjectCache.cpp index de6cbb5caf..3a6a157298 100644 --- a/src/system/kernel/slab/ObjectCache.cpp +++ b/src/system/kernel/slab/ObjectCache.cpp @@ -166,9 +166,6 @@ ObjectCache::InitSlab(slab* slab, void* pages, size_t byteCount, uint32 flags) data += object_size; } - usage += slab_size; - total_objects += slab->size; - return slab; } diff --git a/src/system/kernel/slab/Slab.cpp b/src/system/kernel/slab/Slab.cpp index 7a97ba332c..efb77f61fd 100644 --- a/src/system/kernel/slab/Slab.cpp +++ b/src/system/kernel/slab/Slab.cpp @@ -232,6 +232,7 @@ dump_cache_info(int argc, char* argv[]) kprintf("lock: %p\n", &cache->lock); kprintf("object_size: %lu\n", cache->object_size); kprintf("cache_color_cycle: %lu\n", cache->cache_color_cycle); + kprintf("total_objects: %lu\n", cache->total_objects); kprintf("used_count: %lu\n", cache->used_count); kprintf("empty_count: %lu\n", cache->empty_count); kprintf("pressure: %lu\n", cache->pressure); @@ -362,6 +363,9 @@ object_cache_reserve_internal(ObjectCache* cache, size_t objectCount, return B_NO_MEMORY; } + cache->usage += cache->slab_size; + cache->total_objects += newSlab->size; + cache->empty.Add(newSlab); cache->empty_count++; }