From ba8db43d5f8089049e44b1107a41ce6c0d4f52d5 Mon Sep 17 00:00:00 2001 From: Ilya Maximets Date: Fri, 22 Sep 2023 14:21:43 +0200 Subject: [PATCH] memory-trim: Fix timestamp overflow warning right after reboot. If OVN is started less than 30 seconds after system boot, it logs: |memory_trim|WARN|Detected last active timestamp overflow The 'now < trim_timeout_ms' is not for a timestamp overflow, but for the later subtraction. 'now < last_active_ms' is enough to check for the overflow. Technically, we shouldn't need to check that now > trim_timeout_ms before subtraction, because the result should be a signed integer, but it's cleaner this way. Fixes: 12ddb1c9d908 ("lflow-cache: Automatically trim cache when it becomes inactive.") Signed-off-by: Ilya Maximets Signed-off-by: Dumitru Ceara (cherry picked from commit 11cd04afe60e626649c8b95749f2344784f88f88) --- controller/lflow-cache.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/controller/lflow-cache.c b/controller/lflow-cache.c index 9fca2d7441..0b90b11c22 100644 --- a/controller/lflow-cache.c +++ b/controller/lflow-cache.c @@ -332,21 +332,15 @@ lflow_cache_run(struct lflow_cache *lc) } long long int now = time_msec(); - if (now < lc->last_active_ms || now < lc->trim_timeout_ms) { + if (now < lc->last_active_ms) { VLOG_WARN_RL(&rl, "Detected cache last active timestamp overflow"); lc->recently_active = false; lflow_cache_trim__(lc, true); return; } - if (now < lc->trim_timeout_ms) { - VLOG_WARN_RL(&rl, "Detected very large trim timeout: " - "now %lld ms timeout %"PRIu32" ms", - now, lc->trim_timeout_ms); - return; - } - - if (now - lc->trim_timeout_ms >= lc->last_active_ms) { + if (now > lc->trim_timeout_ms + && now - lc->trim_timeout_ms >= lc->last_active_ms) { VLOG_INFO_RL(&rl, "Detected cache inactivity " "(last active %lld ms ago): trimming cache", now - lc->last_active_ms);