summaryrefslogtreecommitdiffstats
path: root/utils/cache_gc
diff options
context:
space:
mode:
authorVladimír Čunát <vladimir.cunat@nic.cz>2020-06-09 08:09:32 +0200
committerTomas Krizek <tomas.krizek@nic.cz>2020-06-29 14:25:32 +0200
commit26cf29390b2acfe8c6b0547532474ae53763cf42 (patch)
tree58617ebbeae3fad8139294414555fcafd9495edc /utils/cache_gc
parentgc: fix flushing of messages to logs (diff)
downloadknot-resolver-26cf29390b2acfe8c6b0547532474ae53763cf42.tar.xz
knot-resolver-26cf29390b2acfe8c6b0547532474ae53763cf42.zip
gc: fix integer overflow when computing how much to GC
On 32-bit systems the insufficient GC could commonly happen: https://lists.nic.cz/pipermail/knot-resolver-users/2020/000265.html The meaning of -f parameter got slightly changed, so that the buggy computation could be greatly simplified. GC seems to make sense when most of cache space is used, in which case the difference is small.
Diffstat (limited to 'utils/cache_gc')
-rw-r--r--utils/cache_gc/kr_cache_gc.c4
-rw-r--r--utils/cache_gc/kr_cache_gc.h2
-rw-r--r--utils/cache_gc/main.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/utils/cache_gc/kr_cache_gc.c b/utils/cache_gc/kr_cache_gc.c
index 6ba8aad6..a4c04959 100644
--- a/utils/cache_gc/kr_cache_gc.c
+++ b/utils/cache_gc/kr_cache_gc.c
@@ -217,8 +217,8 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg, kr_cache_gc_state_t **state)
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));
+ /* use less precise variant to avoid 32-bit overflow */
+ ssize_t amount_tofree = cats_sumsize / 100 * cfg->cache_to_be_freed;
#ifdef DEBUG
printf("tofree: %zd\n", amount_tofree);
diff --git a/utils/cache_gc/kr_cache_gc.h b/utils/cache_gc/kr_cache_gc.h
index 261115d0..839e553d 100644
--- a/utils/cache_gc/kr_cache_gc.h
+++ b/utils/cache_gc/kr_cache_gc.h
@@ -25,7 +25,7 @@ typedef struct {
unsigned long rw_txn_delay; // waiting time between two RW transactions in usecs
uint8_t cache_max_usage; // maximum cache usage before triggering GC (percent)
- uint8_t cache_to_be_freed; // percent of cache to be freed during GC
+ uint8_t cache_to_be_freed; // percent of current cache usage to be freed during GC
bool dry_run;
} kr_cache_gc_cfg_t;
diff --git a/utils/cache_gc/main.c b/utils/cache_gc/main.c
index cd868553..41654c84 100644
--- a/utils/cache_gc/main.c
+++ b/utils/cache_gc/main.c
@@ -36,7 +36,7 @@ static void print_help()
printf(" -l <deletes_per_txn>\n");
printf(" -m <rw_txn_duration(usecs)>\n");
printf(" -u <cache_max_usage(percent)>\n");
- printf(" -f <cache_to_be_freed(percent)>\n");
+ printf(" -f <cache_to_be_freed(percent-of-current-usage)>\n");
printf(" -w <wait_next_rw_txn(usecs)>\n");
printf(" -t <temporary_memory(MBytes)>\n");
printf(" -n (= dry run)\n");