]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
gc: better approximation of the space to free
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 2 Jul 2019 09:22:04 +0000 (11:22 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 10 Jul 2019 13:59:24 +0000 (15:59 +0200)
utils/cache_gc/kr_cache_gc.c

index 01b01a160b970b928ae497a5429c41d974989698..e240b2920ea3a932ed98d3f7486cd1a0ef528d6b 100644 (file)
@@ -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);