Called from serverCron and loadingCron to update cached memory metrics. */
| 2285 | |
| 2286 | /* Called from serverCron and loadingCron to update cached memory metrics. */ |
| 2287 | void cronUpdateMemoryStats() { |
| 2288 | /* Record the max memory used since the server was started. */ |
| 2289 | if (zmalloc_used_memory() > g_pserver->stat_peak_memory) |
| 2290 | g_pserver->stat_peak_memory = zmalloc_used_memory(); |
| 2291 | |
| 2292 | run_with_period(100) { |
| 2293 | /* Sample the RSS and other metrics here since this is a relatively slow call. |
| 2294 | * We must sample the zmalloc_used at the same time we take the rss, otherwise |
| 2295 | * the frag ratio calculate may be off (ratio of two samples at different times) */ |
| 2296 | g_pserver->cron_malloc_stats.process_rss = zmalloc_get_rss(); |
| 2297 | g_pserver->cron_malloc_stats.zmalloc_used = zmalloc_used_memory(); |
| 2298 | /* Sampling the allocator info can be slow too. |
| 2299 | * The fragmentation ratio it'll show is potentially more accurate |
| 2300 | * it excludes other RSS pages such as: shared libraries, LUA and other non-zmalloc |
| 2301 | * allocations, and allocator reserved pages that can be pursed (all not actual frag) */ |
| 2302 | zmalloc_get_allocator_info(&g_pserver->cron_malloc_stats.allocator_allocated, |
| 2303 | &g_pserver->cron_malloc_stats.allocator_active, |
| 2304 | &g_pserver->cron_malloc_stats.allocator_resident); |
| 2305 | /* in case the allocator isn't providing these stats, fake them so that |
| 2306 | * fragmentation info still shows some (inaccurate metrics) */ |
| 2307 | if (!g_pserver->cron_malloc_stats.allocator_resident) { |
| 2308 | /* LUA memory isn't part of zmalloc_used, but it is part of the process RSS, |
| 2309 | * so we must deduct it in order to be able to calculate correct |
| 2310 | * "allocator fragmentation" ratio */ |
| 2311 | size_t lua_memory = lua_gc(g_pserver->lua,LUA_GCCOUNT,0)*1024LL; |
| 2312 | g_pserver->cron_malloc_stats.allocator_resident = g_pserver->cron_malloc_stats.process_rss - lua_memory; |
| 2313 | } |
| 2314 | if (!g_pserver->cron_malloc_stats.allocator_active) |
| 2315 | g_pserver->cron_malloc_stats.allocator_active = g_pserver->cron_malloc_stats.allocator_resident; |
| 2316 | if (!g_pserver->cron_malloc_stats.allocator_allocated) |
| 2317 | g_pserver->cron_malloc_stats.allocator_allocated = g_pserver->cron_malloc_stats.zmalloc_used; |
| 2318 | |
| 2319 | if (g_pserver->force_eviction_percent) { |
| 2320 | g_pserver->cron_malloc_stats.sys_available = getMemAvailable(); |
| 2321 | } |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | static std::atomic<bool> s_fFlushInProgress { false }; |
| 2326 | void flushStorageWeak() |
no test coverage detected