.. code-block:: bash
- $ kres_cache_gc -c /var/cache/knot-resolver -d 60000
+ $ kres_cache_gc -c /var/cache/knot-resolver -d 10000
It's also possible to run this under systemd. However, a dedicated systemd unit
is not currently part of the upstream package. See `message#167`_ on our
return libknot_db;
}
-int kr_gc_cache_open(const char *cache_path, struct kr_cache *kres_db, knot_db_t **libknot_db, double *usage)
+int kr_gc_cache_open(const char *cache_path, struct kr_cache *kres_db, knot_db_t **libknot_db)
{
char cache_data[strlen(cache_path) + 10];
snprintf(cache_data, sizeof(cache_data), "%s/data.mdb", cache_path);
return -ENOMEM;
}
- size_t real_size = knot_db_lmdb_get_mapsize(*libknot_db), usageb = knot_db_lmdb_get_usage(*libknot_db);
- *usage = (double)usageb / real_size * 100.0;
- printf("Cache size: %zu, Usage: %zu (%.2lf%%)\n", real_size, usageb, *usage);
-
-#if 1
- if (*usage > 90.0) {
- free(*libknot_db);
- kr_cache_close(kres_db);
- cache_size += cache_size / 10;
- opts.maxsize = cache_size;
- goto open_kr_cache;
- }
-# endif
return 0;
}
#include "kr_cache_gc.h"
-int kr_gc_cache_open(const char *cache_path, struct kr_cache *kres_db, knot_db_t **libknot_db, double *usage);
+int kr_gc_cache_open(const char *cache_path, struct kr_cache *kres_db, knot_db_t **libknot_db);
void kr_gc_cache_close(struct kr_cache *kres_db, knot_db_t *knot_db);
{
struct kr_cache kres_db = { 0 };
knot_db_t *db = NULL;
- double db_usage;
- int ret = kr_gc_cache_open(cfg->cache_path, &kres_db, &db, &db_usage);
+ int ret = kr_gc_cache_open(cfg->cache_path, &kres_db, &db);
if (ret) {
return ret;
}
- if (cfg->dry_run || db_usage < cfg->cache_max_usage) {
+ const size_t db_size = knot_db_lmdb_get_mapsize(db);
+ const size_t db_usage_abs = knot_db_lmdb_get_usage(db);
+ const double db_usage = (double)db_usage_abs / db_size * 100.0;
+#if 0 // Probably not worth it, better reduce the risk by checking more often.
+ if (db_usage > 90.0) {
+ free(*libknot_db);
+ kr_cache_close(kres_db);
+ cache_size += cache_size / 10;
+ opts.maxsize = cache_size;
+ goto open_kr_cache;
+ }
+# endif
+ const bool large_usage = db_usage >= cfg->cache_max_usage;
+ if (cfg->dry_run || large_usage) { // don't print this on every size check
+ printf("Usage: %.2lf%% (%zu / %zu)\n", db_usage, db_usage_abs, db_size);
+ }
+ if (cfg->dry_run || !large_usage) {
kr_gc_cache_close(&kres_db, db);
return KNOT_EOK;
}
do {
int ret = kr_cache_gc(&cfg);
- if (ret) {
+ // ENOENT: kresd may not be started yet or cleared the cache now
+ if (ret && ret != -ENOENT) {
printf("Error (%s)\n", kr_strerror(ret));
return 10;
}