From 6cfb71e00ad2c67e0d58155d95dba82efe4e2f89 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 17 Jan 2008 05:14:49 +0000 Subject: [PATCH] HAMMER utilities: * Fix missing releases, fix endless loop in cache flush. --- sbin/hammer/cache.c | 14 +++++++++++++- sbin/hammer/cmd_show.c | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sbin/hammer/cache.c b/sbin/hammer/cache.c index d3d50c1ec..e6b522c3f 100644 --- a/sbin/hammer/cache.c +++ b/sbin/hammer/cache.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/cache.c,v 1.1 2008/01/03 06:48:45 dillon Exp $ + * $DragonFly: src/sbin/hammer/cache.c,v 1.2 2008/01/17 05:14:49 dillon Exp $ */ #include @@ -47,6 +47,7 @@ static int CacheUse; static int CacheMax = 8 * 1024 * 1024; +static int NCache; static TAILQ_HEAD(, cache_info) CacheList = TAILQ_HEAD_INITIALIZER(CacheList); void @@ -55,6 +56,7 @@ hammer_cache_add(struct cache_info *cache, enum cache_type type) TAILQ_INSERT_TAIL(&CacheList, cache, entry); cache->type = type; CacheUse += HAMMER_BUFSIZE; + ++NCache; } void @@ -62,6 +64,7 @@ hammer_cache_del(struct cache_info *cache) { TAILQ_REMOVE(&CacheList, cache, entry); CacheUse -= HAMMER_BUFSIZE; + --NCache; } void @@ -69,15 +72,22 @@ hammer_cache_flush(void) { struct cache_info *cache; int target; + int count = 0; if (CacheUse >= CacheMax) { target = CacheMax / 2; while ((cache = TAILQ_FIRST(&CacheList)) != NULL) { + ++count; if (cache->refs) { TAILQ_REMOVE(&CacheList, cache, entry); TAILQ_INSERT_TAIL(&CacheList, cache, entry); continue; } + if (count == NCache) { + CacheMax += 8 * 1024 * 1024; + target = CacheMax / 2; + count = 0; + } cache->refs = 1; cache->delete = 1; @@ -101,6 +111,8 @@ hammer_cache_flush(void) break; } /* structure was freed */ + if (CacheUse < target) + break; } } } diff --git a/sbin/hammer/cmd_show.c b/sbin/hammer/cmd_show.c index 24fa8a2a8..9beb99c53 100644 --- a/sbin/hammer/cmd_show.c +++ b/sbin/hammer/cmd_show.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/cmd_show.c,v 1.1 2008/01/17 04:59:48 dillon Exp $ + * $DragonFly: src/sbin/hammer/cmd_show.c,v 1.2 2008/01/17 05:14:49 dillon Exp $ */ #include "hammer.h" @@ -67,6 +67,8 @@ hammer_cmd_show(int32_t vol_no, int32_t clu_no, int depth) depth); node_offset = cluster->ondisk->clu_btree_root; print_btree_node(cluster, node_offset, depth); + rel_cluster(cluster); + rel_volume(volume); } static void -- 2.11.4.GIT