[haiku-commits] r35702 - haiku/trunk/src/system/kernel/slab

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 1 Mar 2010 17:35:18 +0100 (CET)

Author: axeld
Date: 2010-03-01 17:35:17 +0100 (Mon, 01 Mar 2010)
New Revision: 35702
Changeset: http://dev.haiku-os.org/changeset/35702/haiku

Modified:
   haiku/trunk/src/system/kernel/slab/ObjectCache.cpp
   haiku/trunk/src/system/kernel/slab/Slab.cpp
Log:
* 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.


Modified: haiku/trunk/src/system/kernel/slab/ObjectCache.cpp
===================================================================
--- haiku/trunk/src/system/kernel/slab/ObjectCache.cpp  2010-03-01 16:21:44 UTC 
(rev 35701)
+++ haiku/trunk/src/system/kernel/slab/ObjectCache.cpp  2010-03-01 16:35:17 UTC 
(rev 35702)
@@ -166,9 +166,6 @@
                data += object_size;
        }
 
-       usage += slab_size;
-       total_objects += slab->size;
-
        return slab;
 }
 

Modified: haiku/trunk/src/system/kernel/slab/Slab.cpp
===================================================================
--- haiku/trunk/src/system/kernel/slab/Slab.cpp 2010-03-01 16:21:44 UTC (rev 
35701)
+++ haiku/trunk/src/system/kernel/slab/Slab.cpp 2010-03-01 16:35:17 UTC (rev 
35702)
@@ -232,6 +232,7 @@
        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 @@
                        return B_NO_MEMORY;
                }
 
+               cache->usage += cache->slab_size;
+               cache->total_objects += newSlab->size;
+
                cache->empty.Add(newSlab);
                cache->empty_count++;
        }


Other related posts:

  • » [haiku-commits] r35702 - haiku/trunk/src/system/kernel/slab - axeld