From d75d1dc9e556527b1784e6addb219fd9f4ff5168 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Sun, 15 Mar 2015 03:55:48 +0900 Subject: [PATCH] sbin/hammer: Properly break from cache flush loop - hammer_cache_flush() needs to keep track of the first element that was pushed back to tail of the list (ref!=0), and break from the loop if it hits that element for the second time. - It's currently working without above check because it breaks from the loop after it has accomplished 'target'. If this function was changed to release unlimited number of cache then it'll loop forever unless tracking those that can't be released (ref!=0). --- sbin/hammer/cache.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sbin/hammer/cache.c b/sbin/hammer/cache.c index 0017cb53f0..c3e872c0ca 100644 --- a/sbin/hammer/cache.c +++ b/sbin/hammer/cache.c @@ -84,6 +84,7 @@ void hammer_cache_flush(void) { struct cache_info *cache; + struct cache_info *p = NULL; int target; int count = 0; int ncache = NCache; @@ -91,8 +92,12 @@ hammer_cache_flush(void) if (CacheUse >= CacheMax) { target = CacheMax / 2; while ((cache = TAILQ_FIRST(&CacheList)) != NULL) { + if (cache == p) + break; /* seen this before */ ++count; if (cache->refs) { + if (p == NULL) + p = cache; TAILQ_REMOVE(&CacheList, cache, entry); TAILQ_INSERT_TAIL(&CacheList, cache, entry); continue; -- 2.41.0