From eb26e782f332b3a3e957f5868bd5d9af03d7f478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 27 Jul 2009 14:59:39 +0000 Subject: [PATCH] * Decoupled block_cache_used_memory() from the sCachesLock - this should fix the UI freezes (ActivityMonitor and ProcessController both use get_system_info() a lot), although this is only the symptom of another problem. * The downside is that the block cache usage information isn't as up to date as it was previously - it's updated by the block write/notifier thread now (worst case every 2 seconds). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31812 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/cache/block_cache.cpp | 33 ++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index 681eee6e14..5743d80e20 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -552,8 +552,12 @@ static status_t write_cached_block(block_cache* cache, cached_block* block, static DoublyLinkedList sCaches; static mutex sCachesLock = MUTEX_INITIALIZER("block caches"); +static mutex sCachesMemoryUseLock + = MUTEX_INITIALIZER("block caches memory use"); +static size_t sUsedMemory; static sem_id sEventSemaphore; -static mutex sNotificationsLock = MUTEX_INITIALIZER("block cache notifications"); +static mutex sNotificationsLock + = MUTEX_INITIALIZER("block cache notifications"); static thread_id sNotifierWriterThread; static DoublyLinkedListLink sMarkCache; // TODO: this only works if the link is the first entry of block_cache @@ -1916,6 +1920,7 @@ block_notifier_and_writer(void* /*data*/) // write 64 blocks of each block_cache every two seconds // TODO: change this once we have an I/O scheduler timeout = kTimeout; + size_t usedMemory = 0; block_cache* cache = NULL; while ((cache = get_next_locked_block_cache(cache)) != NULL) { @@ -1923,6 +1928,10 @@ block_notifier_and_writer(void* /*data*/) cached_block* blocks[kMaxCount]; uint32 count = 0; + size_t cacheUsedMemory; + object_cache_get_usage(cache->buffer_cache, &cacheUsedMemory); + usedMemory += cacheUsedMemory; + if (cache->num_dirty_blocks) { // This cache is not using transactions, we'll scan the blocks // directly @@ -1976,6 +1985,9 @@ block_notifier_and_writer(void* /*data*/) break; } } + + MutexLocker _(sCachesMemoryUseLock); + sUsedMemory = usedMemory; } // never can get here @@ -2098,23 +2110,10 @@ block_cache_init(void) size_t -block_cache_used_memory() +block_cache_used_memory(void) { - size_t usedMemory = 0; - - MutexLocker _(sCachesLock); - - DoublyLinkedList::Iterator it = sCaches.GetIterator(); - while (block_cache* cache = it.Next()) { - if (cache == (block_cache*)&sMarkCache) - continue; - - size_t cacheUsedMemory; - object_cache_get_usage(cache->buffer_cache, &cacheUsedMemory); - usedMemory += cacheUsedMemory; - } - - return usedMemory; + MutexLocker _(sCachesMemoryUseLock); + return sUsedMemory; }