From: Libor Peltan Date: Fri, 27 Apr 2018 12:09:39 +0000 (+0200) Subject: kr_cache_gc: little improvements X-Git-Tag: v4.1.0~8^2~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d35c77271c7128bb310062d3edf598fe5bb415b;p=thirdparty%2Fknot-resolver.git kr_cache_gc: little improvements --- diff --git a/utils/kr_cache_gc/kr_cache_gc.c b/utils/kr_cache_gc/kr_cache_gc.c index 802c9ed50..8e7d9e410 100644 --- a/utils/kr_cache_gc/kr_cache_gc.c +++ b/utils/kr_cache_gc/kr_cache_gc.c @@ -1,4 +1,6 @@ // standard includes +#include +#include #include #include #include @@ -15,7 +17,7 @@ #include "kr_cache_gc.h" // TODO remove and use time(NULL) ! this is just for debug with pre-generated cache -int64_t now = 1523701784; +int64_t now = 1524301784; // section: timer // TODO replace/move to contrib @@ -207,6 +209,7 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg) size_t cache_records = 0, deleted_records = 0; size_t oversize_records = 0, already_gone = 0;; size_t used_space = 0, rw_txn_count = 1; + int64_t min_expire = INT64_MAX; while (it != NULL) { knot_db_val_t key = { 0 }, val = { 0 }; @@ -222,6 +225,9 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg) struct entry_h *entry = entry_h_consistent(val, *entry_type); int64_t over = entry->time + entry->ttl; over -= now; + if (over < min_expire) { + min_expire = over; + } if (over < 0) { knot_db_val_t *todelete; if ((cfg->temp_keys_space > 0 && @@ -242,6 +248,9 @@ int kr_cache_gc(kr_cache_gc_cfg_t *cfg) printf("Cache analyzed in %.2lf secs, %zu records types", gc_timer_end(&timer_analyze), cache_records); rrtypelist_print(&cache_rrtypes); + if (min_expire < INT64_MAX) { + printf("Minimum expire in %"PRId64" secs\n", min_expire); + } printf("%zu records to be deleted using %.2lf MBytes of temporary memory, %zu records skipped due to memory limit.\n", to_del.size, ((double)used_space / 1048576.0), oversize_records); rrtype_dynarray_free(&cache_rrtypes); diff --git a/utils/kr_cache_gc/main.c b/utils/kr_cache_gc/main.c index 808f66bbf..7ef03a43e 100644 --- a/utils/kr_cache_gc/main.c +++ b/utils/kr_cache_gc/main.c @@ -8,7 +8,7 @@ #include "kr_cache_gc.h" -static int killed = 0; +volatile static int killed = 0; static void got_killed(int signum) {