]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pools: add a new flag to avoid rounding pool size up
authorWilly Tarreau <w@1wt.eu>
Mon, 25 Jan 2016 01:19:13 +0000 (02:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Jan 2016 01:31:18 +0000 (02:31 +0100)
Usually it's desirable to merge similarly sized pools, which is the
reason why their size is rounded up to the next multiple of 16. But
for the buffers this is problematic because we add the size of
struct buffer to the user-requested size, and the rounding results
in 8 extra bytes that are usable in the end. So the user gets more
bytes than asked for, and in case of SSL it results in short writes
for the extra bytes that are sent above multiples of 16 kB.

So we add a new flag MEM_F_EXACT to request that the size is not
rounded up when creating the entry. Thus it doesn't disable merging.

include/common/memory.h
src/memory.c

index 2b7121b420b5830c87fb11ce4439bce5957ad872..d52fb62657d2c90dea7aac53dfe58cc3cb17d894 100644 (file)
@@ -33,6 +33,7 @@
 #else
 #define MEM_F_SHARED   0
 #endif
+#define MEM_F_EXACT    0x2
 
 /* reserve an extra void* at the end of a pool for linking */
 #ifdef DEBUG_MEMORY_POOLS
index 036f78607d9404489816cde4b0958d218b1e8df6..53ab4890a3da06ca03c346b2a7eb3d75712e6da1 100644 (file)
@@ -24,7 +24,9 @@ int mem_poison_byte = -1;
 
 /* Try to find an existing shared pool with the same characteristics and
  * returns it, otherwise creates this one. NULL is returned if no memory
- * is available for a new creation.
+ * is available for a new creation. Two flags are supported :
+ *   - MEM_F_SHARED to indicate that the pool may be shared with other users
+ *   - MEM_F_EXACT to indicate that the size must not be rounded up
  */
 struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags)
 {
@@ -41,8 +43,10 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags)
         * so that the visible parts outside are not affected.
         */
 
-       align = 16;
-       size  = ((size + POOL_EXTRA + align - 1) & -align) - POOL_EXTRA;
+       if (!(flags & MEM_F_EXACT)) {
+               align = 16;
+               size  = ((size + POOL_EXTRA + align - 1) & -align) - POOL_EXTRA;
+       }
 
        start = &pools;
        pool = NULL;