]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compression: report zlib memory usage
authorWilliam Lallemand <wlallemand@exceliance.fr>
Tue, 20 Nov 2012 10:25:20 +0000 (11:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 21 Nov 2012 01:15:16 +0000 (02:15 +0100)
Show the memory usage and the max memory available for zlib.
The value stored is now the memory used instead of the remaining
available memory.

doc/configuration.txt
include/proto/compression.h
include/types/global.h
src/cfgparse.c
src/compression.c
src/dumpstats.c

index 94a1f22402be04a33908b0d1614e51583eea58f0..ded48dec814581a67ff4004189c4bb6e185b211b 100644 (file)
@@ -718,7 +718,10 @@ maxzlibmem <number>
   Sets the maximum amount of RAM in megabytes per process usable by the zlib.
   When the maximum amount is reached, future sessions will not compress as long
   as RAM is unavailable. When sets to 0, there is no limit.
-  The default value is 0.
+  The default value is 0. The value is available in bytes on the UNIX socket
+  with "show info" on the line "MaxZlibMemUsage", the memory used by zlib is
+  "ZlibMemUsage" in bytes.
+
 
 noepoll
   Disables the use of the "epoll" event polling system on Linux. It is
index 1614eddfcd9e5d7e29a3e75ea17957d0033e30f7..0eaa21604046e6283b07ef3cc51ba2383a7f84d0 100644 (file)
@@ -41,6 +41,8 @@ int identity_end(struct comp_ctx **comp_ctx);
 
 
 #ifdef USE_ZLIB
+extern long zlib_used_memory;
+
 int deflate_init(struct comp_ctx **comp_ctx, int level);
 int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
 int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
index f2a010267ac9137b055f41a0b49c14037dbec8e6..081cf545314599fb05a51d0b2b74fa1d36b74a3e 100644 (file)
@@ -87,7 +87,7 @@ struct global {
        int maxsock;            /* max # of sockets */
        int rlimit_nofile;      /* default ulimit-n value : 0=unset */
        int rlimit_memmax;      /* default ulimit-d in megs value : 0=unset */
-       int maxzlibmem;         /* max RAM for zlib in megs */
+       long maxzlibmem;        /* max RAM for zlib in bytes */
        int mode;
        unsigned int req_count; /* HTTP request counter */
        int last_checks;
index d4b3d9182b4d3136bd24ce4641d034934f866e1f..1fe270894bf431a79dfe10ad5b9ca1cbf96451a6 100644 (file)
@@ -885,7 +885,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
-               global.maxzlibmem = atol(args[1]);
+               global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
        }
        else if (!strcmp(args[0], "ulimit-n")) {
                if (global.rlimit_nofile != 0) {
index c1e1afd7950f23f3d67be4a6f9b8c486c0921880..1df0f57a75c93bc7faf8a5665d6a0711c47ac8be 100644 (file)
@@ -47,7 +47,7 @@ static struct pool_head *zlib_pool_prev = NULL;
 static struct pool_head *zlib_pool_head = NULL;
 static struct pool_head *zlib_pool_pending_buf = NULL;
 
-static long long zlib_memory_available = -1;
+long zlib_used_memory = 0;
 
 #endif
 
@@ -301,10 +301,7 @@ static inline int init_comp_ctx(struct comp_ctx **comp_ctx)
 #ifdef USE_ZLIB
        z_stream *strm;
 
-       if (global.maxzlibmem > 0 && zlib_memory_available < 0)
-               zlib_memory_available = global.maxzlibmem * 1024 * 1024;  /*  Megabytes to bytes */
-
-       if (global.maxzlibmem > 0 && zlib_memory_available < sizeof(struct comp_ctx))
+       if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < sizeof(struct comp_ctx))
                return -1;
 #endif
 
@@ -315,7 +312,7 @@ static inline int init_comp_ctx(struct comp_ctx **comp_ctx)
        if (*comp_ctx == NULL)
                return -1;
 #ifdef USE_ZLIB
-       zlib_memory_available -= sizeof(struct comp_ctx);
+       zlib_used_memory += sizeof(struct comp_ctx);
 
        strm = &(*comp_ctx)->strm;
        strm->zalloc = alloc_zlib;
@@ -337,9 +334,8 @@ static inline int deinit_comp_ctx(struct comp_ctx **comp_ctx)
        *comp_ctx = NULL;
 
 #ifdef USE_ZLIB
-       zlib_memory_available += sizeof(struct comp_ctx);
+       zlib_used_memory -= sizeof(struct comp_ctx);
 #endif
-
        return 0;
 }
 
@@ -380,7 +376,6 @@ int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
        return 0;
 }
 
-
 int identity_reset(struct comp_ctx *comp_ctx)
 {
        return 0;
@@ -406,10 +401,8 @@ static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size)
        static char round = 0; /* order in deflateInit2 */
        void *buf = NULL;
 
-       if (global.maxzlibmem > 0 && zlib_memory_available < items * size){
-               buf = NULL;
+       if (global.maxzlibmem > 0 && (global.maxzlibmem - zlib_used_memory) < (long)(items * size))
                goto end;
-       }
 
        switch (round) {
                case 0:
@@ -442,8 +435,8 @@ static void *alloc_zlib(void *opaque, unsigned int items, unsigned int size)
                        ctx->zlib_pending_buf = buf = pool_alloc2(zlib_pool_pending_buf);
                break;
        }
-       if (buf != NULL && global.maxzlibmem > 0)
-               zlib_memory_available -= items * size;
+       if (buf != NULL)
+               zlib_used_memory += items * size;
 
 end:
 
@@ -474,8 +467,7 @@ static void free_zlib(void *opaque, void *ptr)
                pool = zlib_pool_pending_buf;
 
        pool_free2(pool, ptr);
-       if (global.maxzlibmem > 0)
-               zlib_memory_available += pool->size;
+       zlib_used_memory -= pool->size;
 }
 
 /**************************
index 32825b0775f9b17cef7c4c926b73353de0a6f16b..2a07140ee073716cfde2bfb0e5fc3ea3c4462388 100644 (file)
@@ -42,6 +42,7 @@
 #include <proto/backend.h>
 #include <proto/channel.h>
 #include <proto/checks.h>
+#include <proto/compression.h>
 #include <proto/dumpstats.h>
 #include <proto/fd.h>
 #include <proto/freq_ctr.h>
@@ -1747,6 +1748,10 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si)
                                     "CompressBpsIn: %u\n"
                                     "CompressBpsOut: %u\n"
                                     "CompressBpsRateLim: %u\n"
+#ifdef USE_ZLIB
+                                    "ZlibMemUsage: %ld\n"
+                                    "MaxZlibMemUsage: %ld\n"
+#endif
                                     "Tasks: %d\n"
                                     "Run_queue: %d\n"
                                     "Idle_pct: %d\n"
@@ -1765,6 +1770,9 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si)
                                     read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max,
                                     read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out),
                                     global.comp_rate_lim,
+#ifdef USE_ZLIB
+                                    zlib_used_memory, global.maxzlibmem,
+#endif
                                     nb_tasks_cur, run_queue_cur, idle_pct,
                                     global.node, global.desc?global.desc:""
                                     );