]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: make the pool allocator support a few flags
authorWilly Tarreau <w@1wt.eu>
Mon, 22 Mar 2021 19:54:15 +0000 (20:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 22 Mar 2021 19:54:15 +0000 (20:54 +0100)
The pool_alloc_dirty() function was renamed to __pool_alloc() and now
takes a set of flags indicating whether poisonning is permitted or not
and whether zeroing the area is needed or not. The pool_alloc() function
is now just a wrapper calling __pool_alloc(pool, 0).

include/haproxy/dynbuf.h
include/haproxy/pool-t.h
include/haproxy/pool.h

index 2a9051546d1f78a2c99f6cff866adbdbb8e3c689..d3377549e1cf987c50039ad31d848a4440a60958 100644 (file)
@@ -68,7 +68,7 @@ static inline struct buffer *b_alloc(struct buffer *buf)
                return buf;
 
        *buf = BUF_WANTED;
-       area = pool_alloc_dirty(pool_head_buffer);
+       area = __pool_alloc(pool_head_buffer, POOL_F_NO_POISON);
        if (unlikely(!area)) {
                activity[tid].buf_wait++;
                return NULL;
index f1cba044eb015d0c5667d562ff84884a4ab409f7..bc54c2d3e1f3f3226a5163f383f1c6f2b8f68c55 100644 (file)
 
 #define POOL_AVG_SAMPLES 1024
 
+/* possible flags for __pool_alloc() */
+#define POOL_F_NO_POISON    0x00000001  // do not poison the area
+#define POOL_F_MUST_ZERO    0x00000002  // zero the returned area
+
 
 struct pool_cache_head {
        struct list list;    /* head of objects in this pool */
index abaa087e73a1c2c63d396d8a404ed5aa31328372..b37fb9d3e139169ec2fc633602687efcda64f8e1 100644 (file)
@@ -286,16 +286,16 @@ static inline void __pool_free(struct pool_head *pool, void *ptr)
 /*
  * Returns a pointer to type <type> taken from the pool <pool_type> or
  * dynamically allocated. In the first case, <pool_type> is updated to point to
- * the next element in the list. No memory poisonning is ever performed on the
- * returned area.
+ * the next element in the list. <flags> is a binary-OR of POOL_F_* flags.
+ * Prefer using pool_alloc() which does the right thing without flags.
  */
-static inline void *pool_alloc_dirty(struct pool_head *pool)
+static inline void *__pool_alloc(struct pool_head *pool, unsigned int flags)
 {
        void *p;
 
 #ifdef CONFIG_HAP_LOCAL_POOLS
        if (likely(p = __pool_get_from_cache(pool)))
-               return p;
+               goto ret;
 #endif
 
 #if !defined(CONFIG_HAP_LOCKLESS_POOLS) && !defined(CONFIG_HAP_NO_GLOBAL_POOLS)
@@ -306,24 +306,23 @@ static inline void *pool_alloc_dirty(struct pool_head *pool)
 #if !defined(CONFIG_HAP_LOCKLESS_POOLS) && !defined(CONFIG_HAP_NO_GLOBAL_POOLS)
        HA_SPIN_UNLOCK(POOL_LOCK, &pool->lock);
 #endif
+ ret:
+       if (p) {
+               if (flags & POOL_F_MUST_ZERO)
+                       memset(p, 0, pool->size);
+               else if (!(flags & POOL_F_NO_POISON) && mem_poison_byte >= 0)
+                       memset(p, mem_poison_byte, pool->size);
+       }
        return p;
 }
 
 /*
  * Returns a pointer to type <type> taken from the pool <pool_type> or
- * dynamically allocated. In the first case, <pool_type> is updated to point to
- * the next element in the list. Memory poisonning is performed if enabled.
+ * dynamically allocated. Memory poisonning is performed if enabled.
  */
 static inline void *pool_alloc(struct pool_head *pool)
 {
-       void *p;
-
-       p = pool_alloc_dirty(pool);
-       if (p && mem_poison_byte >= 0) {
-               memset(p, mem_poison_byte, pool->size);
-       }
-
-       return p;
+       return __pool_alloc(pool, 0);
 }
 
 /*