]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils/kr_cache_gc: add params for configuring cache
authorTomas Krizek <tomas.krizek@nic.cz>
Thu, 16 May 2019 10:29:05 +0000 (12:29 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 10 Jul 2019 13:59:21 +0000 (15:59 +0200)
utils/kr_cache_gc/kr_cache_gc.c
utils/kr_cache_gc/kr_cache_gc.h
utils/kr_cache_gc/main.c

index fb448501e0b17ec31f8f2dd0fa7152d08f61d2bc..a4036667d5a33f3c0080191a7fdc5d81fccfcc12 100644 (file)
@@ -18,9 +18,6 @@
 #include "categories.h"
 #include "db.h"
 
-#define MAX_OK_PERCENT_USAGE 80.0
-#define TO_BE_FREED_PERCENT 10.0
-
 // section: timer
 // TODO replace/move to contrib
 
@@ -153,7 +150,7 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg)
                return ret;
        }
 
-       if (cfg->dry_run || db_usage < MAX_OK_PERCENT_USAGE) {
+       if (cfg->dry_run || db_usage < cfg->cache_max_usage) {
                kr_gc_cache_close(&kres_db, db);
                return KNOT_EOK;
        }
@@ -168,7 +165,7 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg)
                return ret;
        }
 
-       ssize_t amount_tofree = (double)knot_db_lmdb_get_mapsize(db) * TO_BE_FREED_PERCENT / 100.0;
+       ssize_t amount_tofree = (double)knot_db_lmdb_get_mapsize(db) * cfg->cache_to_be_freed / 100.0;
 
        // debug
        /*printf("tofree: %zd\n", amount_tofree);
index fc1806b919ce493d22f8b9af6f9f6faaa033cad9..5988ec762f84458182770bf7a8210404a821aa95 100644 (file)
@@ -22,6 +22,9 @@ typedef struct {
         unsigned long rw_txn_duration;   // maximum duration of RW transaction in usecs (0 = unlimited)
         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
+
         bool dry_run;
 } kr_cache_gc_cfg_t;
 
index d4c0b56921302d1dcab7440bfcfa108201b891d3..72ce137984bba2415881ba81c521275f01da6d75 100644 (file)
@@ -33,6 +33,8 @@ static void print_help()
        printf(" -d <garbage_interval(millis)>\n");
        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(" -w <wait_next_rw_txn(usecs)>\n");
        printf(" -t <temporary_memory(MBytes)>\n");
        printf(" -n (= dry run)\n");
@@ -48,11 +50,14 @@ int main(int argc, char *argv[])
        signal(SIGCHLD, got_killed);
        signal(SIGINT, got_killed);
 
-       kr_cache_gc_cfg_t cfg = { 0 };
-       cfg.rw_txn_items = 100
+       kr_cache_gc_cfg_t cfg = {
+               .rw_txn_items = 100,
+               .cache_max_usage = 80,
+               .cache_to_be_freed = 10
+       };
 
        int o;
-       while ((o = getopt(argc, argv, "hnc:d:l:m:w:t:")) != -1) {
+       while ((o = getopt(argc, argv, "hnc:d:l:m:u:f:w:t:")) != -1) {
                switch (o) {
                case 'c':
                        cfg.cache_path = optarg;
@@ -68,6 +73,12 @@ int main(int argc, char *argv[])
                case 'm':
                        get_nonneg_optarg(cfg.rw_txn_duration);
                        break;
+               case 'u':
+                       get_nonneg_optarg(cfg.cache_max_usage);
+                       break;
+               case 'f':
+                       get_nonneg_optarg(cfg.cache_to_be_freed);
+                       break;
                case 'w':
                        get_nonneg_optarg(cfg.rw_txn_delay);
                        break;