]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: pool/stats: Use ullong to report total pool usage in bytes in stats
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 22 Dec 2022 10:05:48 +0000 (11:05 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 22 Dec 2022 12:46:21 +0000 (13:46 +0100)
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.

doc/internals/api/pools.txt
include/haproxy/pool.h
src/pool.c
src/stats.c

index 480cf24e512e3f642c939eb5a440d5e25db783b8..d84fb9d018b94c47e6abb07819dfc6b9e223c9b6 100644 (file)
@@ -439,14 +439,14 @@ int pool_total_failures(void)
         and is only meant to be used as an indicator rather than a precise
         measure.
 
-ulong pool_total_allocated(void)
+ullong pool_total_allocated(void)
         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
         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
         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
         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
index 1275146616485112e22d6a12575b836b57544f24..16146604b2cb9515e7fee970f51063860b119a4e 100644 (file)
@@ -108,8 +108,8 @@ void pool_free_nocache(struct pool_head *pool, void *ptr);
 void dump_pools(void);
 int pool_parse_debugging(const char *str, char **err);
 int pool_total_failures(void);
-unsigned long pool_total_allocated(void);
-unsigned long pool_total_used(void);
+unsigned long long pool_total_allocated(void);
+unsigned long long pool_total_used(void);
 void pool_flush(struct pool_head *pool);
 void pool_gc(struct pool_head *pool_ctx);
 struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags);
index 610e20cc365bdbfae541a5e873b25d4d33efb5b5..4ea8d812703750123957fc5cce8b8a6459dabbd1 100644 (file)
@@ -980,24 +980,24 @@ int pool_total_failures()
 }
 
 /* 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;
 }
 
index 7b664c1290713b52345b61ac46338bfb2063cfd7..84a4f9b6e56819a3a3452da551c9df95ad148949 100644 (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_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);