BUG/MINOR: pool/stats: Use ullong to report total pool usage in bytes in stats

The same change was already performed for the cli. The stats applet and the
prometheus exporter are also concerned. Both use the stats API and rely on
pool functions to get total pool usage in bytes. pool_total_allocated() and
pool_total_used() must return 64 bits unsigned integer to avoid any wrapping
around 4G.

This may be backported to all versions.
This commit is contained in:
Christopher Faulet 2022-12-22 11:05:48 +01:00
parent 827a6299e6
commit c960a3b60f
4 changed files with 12 additions and 12 deletions

View File

@ -439,14 +439,14 @@ int pool_total_failures(void)
and is only meant to be used as an indicator rather than a precise and is only meant to be used as an indicator rather than a precise
measure. measure.
ulong pool_total_allocated(void) ullong pool_total_allocated(void)
Report the total number of bytes allocated in all pools, for reporting Report the total number of bytes allocated in all pools, for reporting
in the "PoolAlloc_MB" field of the "show info" output. The total is in the "PoolAlloc_MB" field of the "show info" output. The total is
calculated on the fly by summing the number of allocated bytes in all calculated on the fly by summing the number of allocated bytes in all
pools and is only meant to be used as an indicator rather than a pools and is only meant to be used as an indicator rather than a
precise measure. precise measure.
ulong pool_total_used(void) ullong pool_total_used(void)
Report the total number of bytes used in all pools, for reporting in Report the total number of bytes used in all pools, for reporting in
the "PoolUsed_MB" field of the "show info" output. The total is the "PoolUsed_MB" field of the "show info" output. The total is
calculated on the fly by summing the number of used bytes in all pools calculated on the fly by summing the number of used bytes in all pools

View File

@ -108,8 +108,8 @@ void pool_free_nocache(struct pool_head *pool, void *ptr);
void dump_pools(void); void dump_pools(void);
int pool_parse_debugging(const char *str, char **err); int pool_parse_debugging(const char *str, char **err);
int pool_total_failures(void); int pool_total_failures(void);
unsigned long pool_total_allocated(void); unsigned long long pool_total_allocated(void);
unsigned long pool_total_used(void); unsigned long long pool_total_used(void);
void pool_flush(struct pool_head *pool); void pool_flush(struct pool_head *pool);
void pool_gc(struct pool_head *pool_ctx); void pool_gc(struct pool_head *pool_ctx);
struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags); struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags);

View File

@ -980,24 +980,24 @@ int pool_total_failures()
} }
/* This function returns the total amount of memory allocated in pools (in bytes) */ /* This function returns the total amount of memory allocated in pools (in bytes) */
unsigned long pool_total_allocated() unsigned long long pool_total_allocated()
{ {
struct pool_head *entry; struct pool_head *entry;
unsigned long allocated = 0; unsigned long long allocated = 0;
list_for_each_entry(entry, &pools, list) list_for_each_entry(entry, &pools, list)
allocated += entry->allocated * entry->size; allocated += entry->allocated * (ullong)entry->size;
return allocated; return allocated;
} }
/* This function returns the total amount of memory used in pools (in bytes) */ /* This function returns the total amount of memory used in pools (in bytes) */
unsigned long pool_total_used() unsigned long long pool_total_used()
{ {
struct pool_head *entry; struct pool_head *entry;
unsigned long used = 0; unsigned long long used = 0;
list_for_each_entry(entry, &pools, list) list_for_each_entry(entry, &pools, list)
used += entry->used * entry->size; used += entry->used * (ullong)entry->size;
return used; return used;
} }

View File

@ -4541,9 +4541,9 @@ int stats_fill_info(struct field *info, int len, uint flags)
info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax);
info[INF_MEMMAX_BYTES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L); info[INF_MEMMAX_BYTES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L));
info[INF_POOL_ALLOC_BYTES] = mkf_u32(0, pool_total_allocated()); info[INF_POOL_ALLOC_BYTES] = mkf_u64(0, pool_total_allocated());
info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L));
info[INF_POOL_USED_BYTES] = mkf_u32(0, pool_total_used()); info[INF_POOL_USED_BYTES] = mkf_u64(0, pool_total_used());
info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures());
info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);