From 1b4a714266898f3be88fa1fcba0db32a2cf0987a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 7 Oct 2021 16:29:31 +0200 Subject: [PATCH] MINOR: pools: report the amount used by thread caches in "show pools" The "show pools" command provides some "allocated" and "used" estimates on the pools objects, but this applies to the shared pool and the "used" includes what is currently assigned to thread-local caches. It's possible to know how much each thread uses, so let's dump the total size allocated by thread caches as an estimate. It's only done when pools are enabled, which explains why the patch adds quite a lot of ifdefs. --- src/pool.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/pool.c b/src/pool.c index 4bfe014..cb0179b 100644 --- a/src/pool.c +++ b/src/pool.c @@ -519,23 +519,48 @@ void dump_pools_to_trash() struct pool_head *entry; unsigned long allocated, used; int nbpools; +#ifdef CONFIG_HAP_POOLS + unsigned long cached_bytes = 0; + uint cached = 0; +#endif allocated = used = nbpools = 0; chunk_printf(&trash, "Dumping pools usage. Use SIGQUIT to flush them.\n"); list_for_each_entry(entry, &pools, list) { - chunk_appendf(&trash, " - Pool %s (%u bytes) : %u allocated (%u bytes), %u used, needed_avg %u, %u failures, %u users, @%p%s\n", - entry->name, entry->size, entry->allocated, - entry->size * entry->allocated, entry->used, - swrate_avg(entry->needed_avg, POOL_AVG_SAMPLES), entry->failed, - entry->users, entry, - (entry->flags & MEM_F_SHARED) ? " [SHARED]" : ""); +#ifdef CONFIG_HAP_POOLS + int i; + for (cached = i = 0; i < global.nbthread; i++) + cached += entry->cache[i].count; + cached_bytes += cached * entry->size; +#endif + chunk_appendf(&trash, " - Pool %s (%u bytes) : %u allocated (%u bytes), %u used" +#ifdef CONFIG_HAP_POOLS + " (~%u by thread caches)" +#endif + ", needed_avg %u, %u failures, %u users, @%p%s\n", + entry->name, entry->size, entry->allocated, + entry->size * entry->allocated, entry->used, +#ifdef CONFIG_HAP_POOLS + cached, +#endif + swrate_avg(entry->needed_avg, POOL_AVG_SAMPLES), entry->failed, + entry->users, entry, + (entry->flags & MEM_F_SHARED) ? " [SHARED]" : ""); allocated += entry->allocated * entry->size; used += entry->used * entry->size; nbpools++; } - chunk_appendf(&trash, "Total: %d pools, %lu bytes allocated, %lu used.\n", - nbpools, allocated, used); + chunk_appendf(&trash, "Total: %d pools, %lu bytes allocated, %lu used" +#ifdef CONFIG_HAP_POOLS + " (~%lu by thread caches)" +#endif + ".\n", + nbpools, allocated, used +#ifdef CONFIG_HAP_POOLS + , cached_bytes +#endif + ); } /* Dump statistics on pools usage. */ -- 1.7.10.4