From c79e66abb7246bb9c992bd5ca44bb33ade013f82 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 6 Aug 2008 00:09:31 +0000 Subject: [PATCH] Added block_cache_used_memory() that returns the memory allocated by all block caches for the block cache buffers. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26836 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/block_cache.h | 3 ++- src/system/kernel/cache/block_cache.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/headers/private/kernel/block_cache.h b/headers/private/kernel/block_cache.h index 321a549087..a15a0d8447 100644 --- a/headers/private/kernel/block_cache.h +++ b/headers/private/kernel/block_cache.h @@ -14,9 +14,10 @@ extern "C" { #endif extern status_t block_cache_init(void); +extern size_t block_cache_used_memory(); #ifdef __cplusplus } #endif -#endif /* _KRENEL_BLOCK_CACHE_H */ +#endif /* _KERNEL_BLOCK_CACHE_H */ diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index d882a55492..bc089ff6d3 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -1807,6 +1807,27 @@ block_cache_init(void) } +extern "C" size_t +block_cache_used_memory() +{ + 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; +} + + // #pragma mark - public transaction API