]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: memory: move the pool type definitions to haproxy/pool-t.h
authorWilly Tarreau <w@1wt.eu>
Sat, 30 May 2020 16:27:03 +0000 (18:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 11 Jun 2020 08:18:56 +0000 (10:18 +0200)
This is the beginning of the move and cleanup of memory.h. This first
step only extracts type definitions and basic macros that are needed
by the files which reference a pool. They're moved to pool-t.h (since
"pool" is more obvious than "memory" when looking for pool-related
stuff). 3 files which didn't need to include the whole memory.h were
updated.

include/common/memory.h
include/haproxy/pool-t.h [new file with mode: 0644]
include/types/capture.h
include/types/stick_table.h
src/cli.c

index 88119a00385db083d45d62517b3291c3dd221a58..64a7387f6b3a3e4b0bfbbda9b680951628b3f401 100644 (file)
 #include <haproxy/api.h>
 #include <haproxy/freq_ctr.h>
 #include <haproxy/list.h>
+#include <haproxy/pool-t.h>
 #include <haproxy/thread.h>
 
-/* On architectures supporting threads and double-word CAS, we can implement
- * lock-less memory pools. This isn't supported for debugging modes however.
- */
-#if defined(USE_THREAD) && defined(HA_HAVE_CAS_DW) && !defined(DEBUG_NO_LOCKLESS_POOLS) && !defined(DEBUG_UAF) && !defined(DEBUG_FAIL_ALLOC)
-#define CONFIG_HAP_LOCKLESS_POOLS
-#endif
-
-#ifndef DEBUG_DONT_SHARE_POOLS
-#define MEM_F_SHARED   0x1
-#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
-#define POOL_EXTRA (sizeof(void *))
-#define POOL_LINK(pool, item) (void **)(((char *)item) + (pool->size))
-#else
-#define POOL_EXTRA (0)
-#define POOL_LINK(pool, item) ((void **)(item))
-#endif
-
-#define MAX_BASE_POOLS 32
-
-#define POOL_AVG_SAMPLES 1024
-
-struct pool_cache_head {
-       struct list list;    /* head of objects in this pool */
-       size_t size;         /* size of an object */
-       unsigned int count;  /* number of objects in this pool */
-};
-
-struct pool_cache_item {
-       struct list by_pool; /* link to objects in this pool */
-       struct list by_lru;  /* link to objects by LRU order */
-};
-
 extern struct pool_cache_head pool_cache[][MAX_BASE_POOLS];
 extern THREAD_LOCAL size_t pool_cache_bytes;   /* total cache size */
 extern THREAD_LOCAL size_t pool_cache_count;   /* #cache objects   */
-
-#ifdef CONFIG_HAP_LOCKLESS_POOLS
-struct pool_free_list {
-       void **free_list;
-       uintptr_t seq;
-};
-#endif
-
-/* Note below, in case of lockless pools, we still need the lock only for
- * the flush() operation.
- */
-struct pool_head {
-       void **free_list;
-#ifdef CONFIG_HAP_LOCKLESS_POOLS
-       uintptr_t seq;
-#endif
-       __decl_thread(HA_SPINLOCK_T lock); /* the spin lock */
-       unsigned int used;      /* how many chunks are currently in use */
-       unsigned int needed_avg;/* floating indicator between used and allocated */
-       unsigned int allocated; /* how many chunks have been allocated */
-       unsigned int limit;     /* hard limit on the number of chunks */
-       unsigned int minavail;  /* how many chunks are expected to be used */
-       unsigned int size;      /* chunk size */
-       unsigned int flags;     /* MEM_F_* */
-       unsigned int users;     /* number of pools sharing this zone */
-       unsigned int failed;    /* failed allocations */
-       struct list list;       /* list of all known pools */
-       char name[12];          /* name of the pool */
-} __attribute__((aligned(64)));
-
-
 extern struct pool_head pool_base_start[MAX_BASE_POOLS];
 extern unsigned int pool_base_count;
 
diff --git a/include/haproxy/pool-t.h b/include/haproxy/pool-t.h
new file mode 100644 (file)
index 0000000..df778ba
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * include/haproxy/pool-t.h
+ * Memory pools configuration and type definitions.
+ *
+ * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _HAPROXY_POOL_T_H
+#define _HAPROXY_POOL_T_H
+
+#include <haproxy/api.h>
+#include <haproxy/list.h>
+#include <haproxy/thread.h>
+
+/* On architectures supporting threads and double-word CAS, we can implement
+ * lock-less memory pools. This isn't supported for debugging modes however.
+ */
+#if defined(USE_THREAD) && defined(HA_HAVE_CAS_DW) && !defined(DEBUG_NO_LOCKLESS_POOLS) && !defined(DEBUG_UAF) && !defined(DEBUG_FAIL_ALLOC)
+#define CONFIG_HAP_LOCKLESS_POOLS
+#endif
+
+/* Pools of very similar size are shared by default, unless macro
+ * DEBUG_DONT_SHARE_POOLS is set.
+ */
+#ifndef DEBUG_DONT_SHARE_POOLS
+#define MEM_F_SHARED   0x1
+#else
+#define MEM_F_SHARED   0
+#endif
+#define MEM_F_EXACT    0x2
+
+/* By default, free objects are linked by a pointer stored at the beginning of
+ * the memory area. When DEBUG_MEMORY_POOLS is set, the allocated area is
+ * inflated by the size of a pointer so that the link is placed at the end
+ * of the objects. Hence free objects in pools remain intact. In addition,
+ * this location is used to keep a pointer to the pool the object was
+ * allocated from, and verify it's freed into the appropriate one.
+ */
+#ifdef DEBUG_MEMORY_POOLS
+#define POOL_EXTRA (sizeof(void *))
+#define POOL_LINK(pool, item) (void **)(((char *)(item)) + ((pool)->size))
+#else
+#define POOL_EXTRA (0)
+#define POOL_LINK(pool, item) ((void **)(item))
+#endif
+
+#define MAX_BASE_POOLS 32
+
+#define POOL_AVG_SAMPLES 1024
+
+
+struct pool_cache_head {
+       struct list list;    /* head of objects in this pool */
+       size_t size;         /* size of an object */
+       unsigned int count;  /* number of objects in this pool */
+};
+
+struct pool_cache_item {
+       struct list by_pool; /* link to objects in this pool */
+       struct list by_lru;  /* link to objects by LRU order */
+};
+
+struct pool_free_list {
+       void **free_list;
+       uintptr_t seq;
+};
+
+/* Note below, in case of lockless pools, we still need the lock only for
+ * the flush() operation.
+ */
+struct pool_head {
+       void **free_list;
+#ifdef CONFIG_HAP_LOCKLESS_POOLS
+       uintptr_t seq;
+#endif
+       __decl_thread(HA_SPINLOCK_T lock); /* the spin lock */
+       unsigned int used;      /* how many chunks are currently in use */
+       unsigned int needed_avg;/* floating indicator between used and allocated */
+       unsigned int allocated; /* how many chunks have been allocated */
+       unsigned int limit;     /* hard limit on the number of chunks */
+       unsigned int minavail;  /* how many chunks are expected to be used */
+       unsigned int size;      /* chunk size */
+       unsigned int flags;     /* MEM_F_* */
+       unsigned int users;     /* number of pools sharing this zone */
+       unsigned int failed;    /* failed allocations */
+       struct list list;       /* list of all known pools */
+       char name[12];          /* name of the pool */
+} __attribute__((aligned(64)));
+
+#endif /* _HAPROXY_POOL_T_H */
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */
index 493d0be2c949ecbe143ce4559cac2a767e26b873..7849cdd74caf905904c41eacd20aa9fa3915b2fb 100644 (file)
@@ -23,7 +23,7 @@
 #define _TYPES_CAPTURE_H
 
 #include <haproxy/api-t.h>
-#include <common/memory.h>
+#include <haproxy/pool-t.h>
 
 struct cap_hdr {
     struct cap_hdr *next;
index 122daeab3c5c5597847b3f72379e3c10de10ffad..ccd1dcb656b63b809510f9c80a8e88c9babb8dea 100644 (file)
@@ -29,7 +29,7 @@
 #include <import/ebtree.h>
 #include <import/ebmbtree.h>
 #include <import/eb32tree.h>
-#include <common/memory.h>
+#include <haproxy/pool-t.h>
 #include <types/dict.h>
 #include <haproxy/freq_ctr-t.h>
 #include <types/peers.h>
index 91e7ffb1978c0ba093ede90ce1da9732ae070752..8084dfd464ff0070b85938bfa17eb81f09730a35 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -28,7 +28,6 @@
 
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
-#include <common/memory.h>
 #include <haproxy/list.h>
 #include <common/standard.h>
 #include <common/ticks.h>