From: Libor Peltan Date: Fri, 11 May 2018 14:20:58 +0000 (+0200) Subject: kr_cache_gc: randomized deleting of parts of huge categories X-Git-Tag: v4.1.0^2~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cefaac58f4e628028f4fb97a320ea58e112e9e6a;p=thirdparty%2Fknot-resolver.git kr_cache_gc: randomized deleting of parts of huge categories --- diff --git a/utils/kr_cache_gc/categories.c b/utils/kr_cache_gc/categories.c index db4a7104e..bfdb465c0 100644 --- a/utils/kr_cache_gc/categories.c +++ b/utils/kr_cache_gc/categories.c @@ -16,6 +16,11 @@ static bool rrtype_is_infrastructure(uint16_t r) } } +static int get_random(int to) +{ + return rand() % to; +} + // TODO this is just an example, make this more clever category_t kr_gc_categorize(gc_record_info_t *info) { @@ -23,25 +28,26 @@ category_t kr_gc_categorize(gc_record_info_t *info) switch (info->no_labels) { case 0: - return 1; + res = 5; + break; case 1: - return 2; + res = 10; + break; case 2: - return (rrtype_is_infrastructure(info->rrtype) ? 3 : 20); + res = (rrtype_is_infrastructure(info->rrtype) ? 15 : 20); + break; } if (info->entry_size > 300) { - return 90; + res += 30; } if (rrtype_is_infrastructure(info->rrtype)) { if (info->expires_in > 0) { - res = 30; - } else { - res = 45; + res = res > 40 ? 40 : res; } } - return res; + return res + get_random(5); }