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.
(cherry picked from commit c960a3b60f5d05b82cdac2a33ab22ca465787e60)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit b174d82dff11d7fb67e9a7f53c20a658f23dd9e7)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit a6ff9f5361894e6e75fe26ffe5fce4b98fb4bee2)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 3974420fb1bbfcc28bd9fcbd70903d72732adf5f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/pool.c b/src/pool.c
index 7f5032f..ce709f9 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -571,24 +571,24 @@
}
/* 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;
- unsigned long allocated = 0;
+ unsigned long long allocated = 0;
list_for_each_entry(entry, &pools, list)
- allocated += entry->allocated * entry->size;
+ allocated += entry->allocated * (ullong)entry->size;
return allocated;
}
/* 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;
- unsigned long used = 0;
+ unsigned long long used = 0;
list_for_each_entry(entry, &pools, list)
- used += entry->used * entry->size;
+ used += entry->used * (ullong)entry->size;
return used;
}
diff --git a/src/stats.c b/src/stats.c
index f46ce2f..d1f3daa 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -4416,9 +4416,9 @@
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_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_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_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);