[haiku-commits] r33622 - haiku/trunk/src/system/kernel/vm

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 17 Oct 2009 19:24:59 +0200 (CEST)

Author: mmlr
Date: 2009-10-17 19:24:59 +0200 (Sat, 17 Oct 2009)
New Revision: 33622
Changeset: http://dev.haiku-os.org/changeset/33622/haiku

Modified:
   haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp
Log:
Make the swap hash lock into a rw_lock to reduce lock contention a bit.


Modified: haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp
===================================================================
--- haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp       2009-10-17 
17:01:22 UTC (rev 33621)
+++ haiku/trunk/src/system/kernel/vm/VMAnonymousCache.cpp       2009-10-17 
17:24:59 UTC (rev 33622)
@@ -122,7 +122,7 @@
 typedef DoublyLinkedList<swap_file> SwapFileList;
 
 static SwapHashTable sSwapHashTable;
-static mutex sSwapHashLock;
+static rw_lock sSwapHashLock;
 
 static SwapFileList sSwapFileList;
 static mutex sSwapFileListLock;
@@ -345,7 +345,7 @@
 static void
 swap_hash_resizer(void*, int)
 {
-       MutexLocker locker(sSwapHashLock);
+       WriteLocker locker(sSwapHashLock);
 
        size_t size;
        void* allocation;
@@ -784,7 +784,7 @@
                        offset < source->virtual_end;
                        offset += B_PAGE_SIZE * SWAP_BLOCK_PAGES) {
 
-               MutexLocker locker(sSwapHashLock);
+               WriteLocker locker(sSwapHashLock);
 
                page_num_t swapBlockPageIndex = offset >> PAGE_SHIFT;
                swap_hash_key key = { source, swapBlockPageIndex };
@@ -878,7 +878,7 @@
 VMAnonymousCache::_SwapBlockBuild(off_t startPageIndex,
        swap_addr_t startSlotIndex, uint32 count)
 {
-       mutex_lock(&sSwapHashLock);
+       WriteLocker locker(sSwapHashLock);
 
        uint32 left = count;
        for (uint32 i = 0, j = 0; i < count; i += j) {
@@ -893,9 +893,9 @@
                                CACHE_DONT_SLEEP);
                        if (swap == NULL) {
                                // Wait a short time until memory is available 
again.
-                               mutex_unlock(&sSwapHashLock);
+                               locker.Unlock();
                                snooze(10000);
-                               mutex_lock(&sSwapHashLock);
+                               locker.Lock();
                                swap = sSwapHashTable.Lookup(key);
                                continue;
                        }
@@ -917,15 +917,13 @@
 
                swap->used += j;
        }
-
-       mutex_unlock(&sSwapHashLock);
 }
 
 
 void
 VMAnonymousCache::_SwapBlockFree(off_t startPageIndex, uint32 count)
 {
-       mutex_lock(&sSwapHashLock);
+       WriteLocker locker(sSwapHashLock);
 
        uint32 left = count;
        for (uint32 i = 0, j = 0; i < count; i += j) {
@@ -947,15 +945,13 @@
                        object_cache_free(sSwapBlockCache, swap);
                }
        }
-
-       mutex_unlock(&sSwapHashLock);
 }
 
 
 swap_addr_t
 VMAnonymousCache::_SwapBlockGetAddress(off_t pageIndex)
 {
-       mutex_lock(&sSwapHashLock);
+       ReadLocker locker(sSwapHashLock);
 
        swap_hash_key key = { this, pageIndex };
        swap_block *swap = sSwapHashTable.Lookup(key);
@@ -966,8 +962,6 @@
                slotIndex = swap->swap_slots[blockIndex];
        }
 
-       mutex_unlock(&sSwapHashLock);
-
        return slotIndex;
 }
 
@@ -1177,7 +1171,7 @@
 
        // init swap hash table
        sSwapHashTable.Init(INITIAL_SWAP_HASH_SIZE);
-       mutex_init(&sSwapHashLock, "swaphash");
+       rw_lock_init(&sSwapHashLock, "swaphash");
 
        error = register_resource_resizer(swap_hash_resizer, NULL,
                SWAP_HASH_RESIZE_INTERVAL);


Other related posts:

  • » [haiku-commits] r33622 - haiku/trunk/src/system/kernel/vm - mmlr