From 887ef7b20e416909ed31ee8b37dad23c7cf197d5 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Thu, 24 Aug 2023 23:42:39 +0800 Subject: [PATCH] dns_cache: some cpu usage optimize for inactive cache --- src/dns_cache.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/dns_cache.c b/src/dns_cache.c index 73efb4a..a2a589a 100644 --- a/src/dns_cache.c +++ b/src/dns_cache.c @@ -129,6 +129,7 @@ static void _dns_cache_move_inactive(struct dns_cache *dns_cache) { list_del_init(&dns_cache->list); list_add_tail(&dns_cache->list, &dns_cache_head.inactive_list); + time(&dns_cache->info.replace_time); } enum CACHE_TYPE dns_cache_data_type(struct dns_cache_data *cache_data) @@ -621,13 +622,20 @@ static void _dns_cache_remove_expired_ttl(dns_cache_callback inactive_precallbac continue; } - ttl = *now - dns_cache->info.replace_time; - if (ttl < ttl_inactive_pre || inactive_precallback == NULL) { + if (inactive_precallback == NULL) { + if (dns_cache_head.inactive_list_expired + ttl > 0) { + break; + } continue; } + ttl = *now - dns_cache->info.replace_time; + if (ttl < ttl_inactive_pre) { + break; + } + if (callback_num >= max_callback_num) { - continue; + break; } if (dns_cache->del_pending == 1) {