#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
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;
}
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);
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;
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");
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;
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;