From: Vladimír Čunát Date: Tue, 2 Jul 2019 09:22:04 +0000 (+0200) Subject: gc: better approximation of the space to free X-Git-Tag: v4.1.0^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6beba003ad9189951d2aa365764e8e2fa65248e;p=thirdparty%2Fknot-resolver.git gc: better approximation of the space to free --- diff --git a/utils/cache_gc/kr_cache_gc.c b/utils/cache_gc/kr_cache_gc.c index 01b01a160..e240b2920 100644 --- a/utils/cache_gc/kr_cache_gc.c +++ b/utils/cache_gc/kr_cache_gc.c @@ -180,7 +180,16 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg) return ret; } - ssize_t amount_tofree = knot_db_lmdb_get_mapsize(db) * cfg->cache_to_be_freed / 100; + //ssize_t amount_tofree = knot_db_lmdb_get_mapsize(db) * cfg->cache_to_be_freed / 100; + // Mixing ^^ page usage and entry sizes (key+value lengths) didn't work + // too well, probably due to internal fragmentation after some GC cycles. + // Therefore let's scale this by the ratio of these two sums. + ssize_t cats_sumsize = 0; + for (int i = 0; i < CATEGORIES; ++i) { + cats_sumsize += cats.categories_sizes[i]; + } + ssize_t amount_tofree = knot_db_lmdb_get_mapsize(db) * cfg->cache_to_be_freed + * cats_sumsize / (100 * knot_db_lmdb_get_usage(db)); #ifdef DEBUG printf("tofree: %zd\n", amount_tofree);