@cryptotaxi247 / netdata-1 / commits / 400697097

Log message when page cache sleeps for more than 1 second. (#11314)

If the page cache manager can not reserve the requested number of pages, it sleeps based on an exponential-backoff value. Normally, this value is a couple milliseconds. However, in rare cases the sleep duration can grow up to several seconds. This patch logs an error message whenever the sleep period is more than 1 second.

vkalintiris committed Jul 14, 2021 at 16:52 UTC 4006970974fc4e1187c3ea1e84af9b8c0d57dbf4
1 file changed +8 -3
database/engine/pagecache.c
+8 -3
@@ -299,10 +299,15 @@ static void pg_cache_reserve_pages(struct rrdengine_instance *ctx, unsigned numb
299 destroy_completion(&compl);
300
301 if (unlikely(failures > 1)) {
302 - unsigned long slots;
302 + unsigned long slots, usecs_to_sleep;
303 /* exponential backoff */
304 slots = random() % (2LU << MIN(failures, FAILURES_CEILING));
305 - (void)sleep_usec(slots * exp_backoff_slot_usec);
305 + usecs_to_sleep = slots * exp_backoff_slot_usec;
306 +
307 + if (usecs_to_sleep >= USEC_PER_SEC)
308 + error("Page cache is full. Sleeping for %llu second(s).", usecs_to_sleep / USEC_PER_SEC);
309 +
310 + (void)sleep_usec(usecs_to_sleep);
311 }
312 uv_rwlock_wrlock(&pg_cache->pg_cache_rwlock);
313 }
@@ -1243,4 +1248,4 @@ void free_page_cache(struct rrdengine_instance *ctx)
1248 bytes_freed += ret_Judy;
1249
1250 info("Freed %lu bytes of memory from page cache.", bytes_freed);
1246 -}
\ No newline at end of file
1251 +}