]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: include: move common/memory.h to haproxy/pool.h
authorWilly Tarreau <w@1wt.eu>
Tue, 2 Jun 2020 07:38:52 +0000 (09:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 11 Jun 2020 08:18:57 +0000 (10:18 +0200)
Now the file is ready to be stored into its final destination. A few
minor reorderings were performed to keep the file properly organized,
making the various sections more visible (cache & lockless).

In addition and to stay consistent, memory.c was renamed to pool.c.

34 files changed:
Makefile
contrib/prometheus-exporter/service-prometheus.c
include/common/buffer.h
include/common/chunk.h
include/common/hpack-tbl.h
include/haproxy/pool.h [moved from include/common/memory.h with 87% similarity]
include/proto/applet.h
include/proto/connection.h
include/proto/log.h
include/proto/obj_type.h
include/proto/queue.h
include/proto/session.h
include/proto/stream.h
include/proto/task.h
src/action.c
src/buffer.c
src/cfgparse.c
src/compression.c
src/flt_spoe.c
src/haproxy.c
src/http_acl.c
src/http_act.c
src/http_conv.c
src/http_fetch.c
src/http_rules.c
src/pipe.c
src/pool.c [moved from src/memory.c with 99% similarity]
src/proxy.c
src/queue.c
src/session.c
src/stats.c
src/stick_table.c
src/stream.c
src/task.c

index f7155d02abab842bc4cff0ae599d0f1f0f636131..6e4cad605c0de8bff1576f4951725b1b53953134 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -802,7 +802,7 @@ OBJS = src/mux_h2.o src/stream.o src/mux_fcgi.o src/cfgparse-listen.o         \
        src/payload.o src/vars.o src/debug.o src/mux_pt.o src/http_act.o       \
        src/h2.o src/queue.o src/fd.o src/proto_uxst.o src/lb_chash.o          \
        src/ring.o src/frontend.o src/raw_sock.o src/xprt_handshake.o          \
-       src/htx.o src/memory.o src/applet.o src/channel.o src/signal.o         \
+       src/htx.o src/pool.o src/applet.o src/channel.o src/signal.o           \
        src/lb_fwrr.o src/ev_select.o src/sink.o src/http_conv.o               \
        src/proto_sockpair.o src/mworker-prog.o src/activity.o src/lb_fwlc.o   \
        src/http.o src/lb_fas.o src/uri_auth.o src/thread.o src/regex.o        \
index 6afa43feb50f37f340f0ba3a28047d058ddf25ac..fe3431ccb4e87402daa04afd5351758b17e52986 100644 (file)
@@ -17,7 +17,7 @@
 #include <common/cfgparse.h>
 #include <common/buffer.h>
 #include <common/htx.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/list.h>
 
 #include <types/global.h>
index 132cbff6cf73299ae9306cda164d81fe131cafc2..e9aae2585160f0dc4bee0c1217489b1c32b2ae01 100644 (file)
@@ -31,7 +31,7 @@
 #include <common/chunk.h>
 #include <import/ist.h>
 #include <haproxy/istbuf.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 #include <proto/activity.h>
 
index 46dfae70d0d7edd8699f703add0d421df91ae5c8..279b80224b74a824162561878538b25f455b84a2 100644 (file)
@@ -28,7 +28,7 @@
 #include <haproxy/api.h>
 #include <haproxy/buf-t.h>
 #include <import/ist.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 
 extern struct pool_head *pool_head_trash;
index 1d2a8bd5f13463962618c4998f53b6514a38d140..07e0a9fa30354d551681794e7a97225967b6983e 100644 (file)
@@ -31,7 +31,7 @@
 #include <haproxy/api.h>
 #include <common/http-hdr.h>
 #include <import/ist.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 /* Dynamic Headers Table, usable for tables up to 4GB long and values of 64kB-1.
  * The model can be improved by using offsets relative to the table entry's end
similarity index 87%
rename from include/common/memory.h
rename to include/haproxy/pool.h
index d612263522e2bbb343508b7e477f042ab6490a21..a62d06efad4e29814124e47da47d66de0ee54f1b 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * include/common/memory.h
+ * include/haproxy/pool.h
  * Memory management definitions..
  *
- * Copyright (C) 2000-2014 Willy Tarreau - w@1wt.eu
+ * 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
@@ -19,8 +19,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef _COMMON_MEMORY_H
-#define _COMMON_MEMORY_H
+#ifndef _HAPROXY_POOL_H
+#define _HAPROXY_POOL_H
 
 #include <string.h>
 
 #include <haproxy/pool-t.h>
 #include <haproxy/thread.h>
 
-#ifdef CONFIG_HAP_LOCAL_POOLS
-extern struct pool_head pool_base_start[MAX_BASE_POOLS];
-extern unsigned int pool_base_count;
-extern struct pool_cache_head pool_cache[][MAX_BASE_POOLS];
-extern struct list pool_lru_head[MAX_THREADS];
-extern THREAD_LOCAL size_t pool_cache_bytes;   /* total cache size */
-extern THREAD_LOCAL size_t pool_cache_count;   /* #cache objects   */
-#endif
-
-/* poison each newly allocated area with this byte if >= 0 */
-extern int mem_poison_byte;
-
-/* Allocates new entries for pool <pool> until there are at least <avail> + 1
- * available, then returns the last one for immediate use, so that at least
- * <avail> are left available in the pool upon return. NULL is returned if the
- * last entry could not be allocated. It's important to note that at least one
- * allocation is always performed even if there are enough entries in the pool.
- * A call to the garbage collector is performed at most once in case malloc()
- * returns an error, before returning NULL.
- */
-void *__pool_refill_alloc(struct pool_head *pool, unsigned int avail);
-void *pool_refill_alloc(struct pool_head *pool, unsigned int avail);
-
-/* 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.
- */
-struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags);
-void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size);
-
 /* This registers a call to create_pool_callback(ptr, name, size) */
 #define REGISTER_POOL(ptr, name, size)  \
        INITCALL3(STG_POOL, create_pool_callback, (ptr), (name), (size))
@@ -75,48 +45,23 @@ void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size)
        static struct pool_head *(ptr);      \
        REGISTER_POOL(&ptr, name, size)
 
-/* Dump statistics on pools usage.
- */
+/* poison each newly allocated area with this byte if >= 0 */
+extern int mem_poison_byte;
+
+void *__pool_refill_alloc(struct pool_head *pool, unsigned int avail);
+void *pool_refill_alloc(struct pool_head *pool, unsigned int avail);
 void dump_pools_to_trash();
 void dump_pools(void);
 int pool_total_failures();
 unsigned long pool_total_allocated();
 unsigned long pool_total_used();
-
-/*
- * This function frees whatever can be freed in pool <pool>.
- */
 void pool_flush(struct pool_head *pool);
-
-/*
- * This function frees whatever can be freed in all pools, but respecting
- * the minimum thresholds imposed by owners.
- *
- * <pool_ctx> is used when pool_gc is called to release resources to allocate
- * an element in __pool_refill_alloc. It is important because <pool_ctx> is
- * already locked, so we need to skip the lock here.
- */
 void pool_gc(struct pool_head *pool_ctx);
-
-/*
- * This function destroys a pull by freeing it completely.
- * This should be called only under extreme circumstances.
- */
+struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags);
+void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size);
 void *pool_destroy(struct pool_head *pool);
 void pool_destroy_all();
 
-/* returns the pool index for pool <pool>, or -1 if this pool has no index */
-static inline ssize_t pool_get_index(const struct pool_head *pool)
-{
-#ifdef CONFIG_HAP_LOCAL_POOLS
-       size_t idx;
-
-       idx = pool - pool_base_start;
-       if (idx < MAX_BASE_POOLS)
-               return idx;
-#endif
-       return -1;
-}
 
 /* returns true if the pool is considered to have too many free objects */
 static inline int pool_is_crowded(const struct pool_head *pool)
@@ -125,9 +70,31 @@ static inline int pool_is_crowded(const struct pool_head *pool)
               (int)(pool->allocated - pool->used) >= pool->minavail;
 }
 
+
 #ifdef CONFIG_HAP_LOCAL_POOLS
+
+/****************** Thread-local cache management ******************/
+
+extern struct pool_head pool_base_start[MAX_BASE_POOLS];
+extern unsigned int pool_base_count;
+extern struct pool_cache_head pool_cache[][MAX_BASE_POOLS];
+extern struct list pool_lru_head[MAX_THREADS];
+extern THREAD_LOCAL size_t pool_cache_bytes;   /* total cache size */
+extern THREAD_LOCAL size_t pool_cache_count;   /* #cache objects   */
+
 void pool_evict_from_cache();
 
+/* returns the pool index for pool <pool>, or -1 if this pool has no index */
+static inline ssize_t pool_get_index(const struct pool_head *pool)
+{
+       size_t idx;
+
+       idx = pool - pool_base_start;
+       if (idx < MAX_BASE_POOLS)
+               return idx;
+       return -1;
+}
+
 /* Tries to retrieve an object from the local pool cache corresponding to pool
  * <pool>. Returns NULL if none is available.
  */
@@ -175,9 +142,19 @@ static inline void pool_put_to_cache(struct pool_head *pool, void *ptr, ssize_t
        if (unlikely(pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE))
                pool_evict_from_cache(pool, ptr, idx);
 }
+
+#else // CONFIG_HAP_LOCAL_POOLS
+
+/* always return index -1 when thread-local pools are disabled */
+#define pool_get_index(pool) ((ssize_t)-1)
+
 #endif // CONFIG_HAP_LOCAL_POOLS
 
+
 #ifdef CONFIG_HAP_LOCKLESS_POOLS
+
+/****************** Lockless pools implementation ******************/
+
 /*
  * Returns a pointer to type <type> taken from the pool <pool_type> if
  * available, otherwise returns NULL. No malloc() is attempted, and poisonning
@@ -232,6 +209,9 @@ static inline void __pool_free(struct pool_head *pool, void *ptr)
 }
 
 #else /* CONFIG_HAP_LOCKLESS_POOLS */
+
+/****************** Locked pools implementation ******************/
+
 /*
  * Returns a pointer to type <type> taken from the pool <pool_type> if
  * available, otherwise returns NULL. No malloc() is attempted, and poisonning
@@ -284,6 +264,8 @@ static inline void __pool_free(struct pool_head *pool, void *ptr)
 #endif /* CONFIG_HAP_LOCKLESS_POOLS */
 
 
+/****************** Common high-level code ******************/
+
 static inline void *pool_get_first(struct pool_head *pool)
 {
        void *p;
@@ -384,8 +366,7 @@ static inline void pool_free(struct pool_head *pool, void *ptr)
        }
 }
 
-
-#endif /* _COMMON_MEMORY_H */
+#endif /* _HAPROXY_POOL_H */
 
 /*
  * Local variables:
index aaa49038bc2289bd19fabb7480eb518e0185726e..80744ba130c66676ab3361de97ff922d7ac105b8 100644 (file)
@@ -25,7 +25,7 @@
 #include <stdlib.h>
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/list.h>
 #include <types/applet.h>
 #include <proto/task.h>
index 7ffe1fd8cfec7ebead0011f4a950041dad5ff8b8..de976d7a750b1bc157439e23de8a5bbac7f9a314 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <haproxy/api.h>
 #include <import/ist.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <types/connection.h>
 #include <types/listener.h>
 #include <proto/fd.h>
index ef792c81a59be095551bce4501c3a20d789a42fa..48802dc10ce0b40eab63978a09c55cf37f3a514f 100644 (file)
@@ -27,7 +27,7 @@
 #include <syslog.h>
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/thread-t.h>
 
 #include <types/log.h>
index f4816b13730556ffd709f3bcb75ad95632186d3f..402d08413e8a835d080eb4f4f6aa431ed77bf2e2 100644 (file)
@@ -23,7 +23,7 @@
 #define _PROTO_OBJ_TYPE_H
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <types/applet.h>
 #include <types/connection.h>
 #include <types/listener.h>
index 9bec9b42bd0c001b87d4a81288a237b69e8efd5f..d4da40c730896c52a365a5145df144e1f35ac005 100644 (file)
@@ -23,7 +23,7 @@
 #define _PROTO_QUEUE_H
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 #include <types/proxy.h>
 #include <types/queue.h>
index 522e43fe5adc01b5d9ec4988b8323471c339cbcb..866217ec2864fb53558a47adfe842a84e44b0e5b 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <haproxy/api.h>
 #include <common/buffer.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 #include <types/global.h>
 #include <types/session.h>
index b821cbae269dc41aaa071dfc541aa60d65f9fbc9..80c56ef8889f97c342abfe90b941f8a5955a4423 100644 (file)
@@ -23,7 +23,7 @@
 #define _PROTO_STREAM_H
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <types/action.h>
 #include <types/stream.h>
 #include <proto/fd.h>
index d5cded3cfa0916d4ebbc40de332e816b371aee9d..5a3d0210de5709cb1666b37ef565995c1fd74f1a 100644 (file)
@@ -26,7 +26,7 @@
 #include <sys/time.h>
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/intops.h>
 #include <haproxy/list.h>
 #include <common/ticks.h>
index cb897b66a299d75707590bd3bd6be06ab7d85202..1125eca1e94b91565951a7827300294325724def 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/list.h>
 #include <common/standard.h>
 
index c8d7a69f2c1c1cfefcaef8d7140a98e7b79975fe..ec07e76e6beb92534c230377dcf90554b10f6d82 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <haproxy/api.h>
 #include <common/buffer.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 #include <types/global.h>
 
index a1917fa238a60829499765b28ef22171e02f51b1..373a32194fac3d3af1e860f31dc1713423753532 100644 (file)
@@ -37,7 +37,7 @@
 #include <common/cfgparse.h>
 #include <common/chunk.h>
 #include <haproxy/errors.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <common/standard.h>
 #include <haproxy/time.h>
 #include <common/uri_auth.h>
index 154d629f8ed589c21823e2876dae3b81ab4328a8..45471c33397fd2acda7e873a6544cc0154cded02 100644 (file)
@@ -29,7 +29,7 @@
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
 #include <haproxy/thread.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 #include <types/global.h>
 #include <types/compression.h>
index df67a29d7a3c1cc02b97ca9604aea9ab23920c87..52771ef138c1e16c05e1ee9e5c92969ee848fcf2 100644 (file)
@@ -15,7 +15,7 @@
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
 #include <haproxy/thread.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/time.h>
 
 #include <types/arg.h>
index a2ceeec575e6a45bdde3befad0cf5e437ecea0cb..917b14fc0857562839b3f1cb9c557f3a7c5cedc2 100644 (file)
@@ -85,7 +85,7 @@
 #include <common/cfgparse.h>
 #include <common/chunk.h>
 #include <haproxy/errors.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/list.h>
 #include <common/namespace.h>
 #include <common/net_helper.h>
index fe71658da3b6385707447160d4a19628b051e0b3..c55c720992181278ee57fe5cde44aef38c90f91e 100644 (file)
@@ -19,7 +19,7 @@
 #include <haproxy/api.h>
 #include <common/chunk.h>
 #include <common/http.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <common/standard.h>
 #include <haproxy/version.h>
 
index da57d8fe049449fc20aaa005d143b8b0dac33b76..8e394cce9b14635ab25c7e5a1de39586304c1b54 100644 (file)
@@ -20,7 +20,7 @@
 #include <common/cfgparse.h>
 #include <common/chunk.h>
 #include <common/http.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <common/standard.h>
 #include <common/uri_auth.h>
 #include <haproxy/version.h>
index 109952145992d502ab984b93bea19091faa1a94f..b82883a48a23fe328afa5e5fc9333e8005e13b1b 100644 (file)
@@ -19,7 +19,7 @@
 #include <haproxy/api.h>
 #include <common/chunk.h>
 #include <common/http.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <common/standard.h>
 #include <haproxy/version.h>
 
index 96d44ab6072f0968a0aeeb0a6e80c3e0b4df6348..c253c8de93b6d0d60876db77e598a5201bece6dd 100644 (file)
@@ -22,7 +22,7 @@
 #include <common/h1.h>
 #include <common/http.h>
 #include <common/htx.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <common/standard.h>
 #include <haproxy/version.h>
 
index 6a5a5f33bd50d43fce60ef4810a4d8a5d56855ba..01a820ebd918b81cd1252e550038a8c6b9657efd 100644 (file)
@@ -20,7 +20,7 @@
 #include <common/cfgparse.h>
 #include <common/chunk.h>
 #include <common/http.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <common/standard.h>
 #include <haproxy/version.h>
 
index 8c828214a09425d4a12019f12b0d6430658771fd..6fe7b0524937890926214d8b15c38cd217693db1 100644 (file)
@@ -15,7 +15,7 @@
 
 #include <haproxy/api.h>
 #include <haproxy/thread.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 #include <types/global.h>
 #include <types/pipe.h>
similarity index 99%
rename from src/memory.c
rename to src/pool.c
index afab8f84f88574642e3a7a144344eaf097b80c82..3a4b34cf5c620104790f14af6cce90dee98d44b4 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <common/cfgparse.h>
 #include <haproxy/thread.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/list.h>
 #include <common/standard.h>
 
index 5e29ec95c34f1077380e53165b3e4e6fed968a56..a8ca53a318d7ecbb07f6dc5206cdf222a409d96e 100644 (file)
@@ -20,7 +20,7 @@
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
 #include <haproxy/errors.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/time.h>
 
 #include <import/eb32tree.h>
index e354e0a4844368979048bd0361091dd46418914b..43a21b1e1a7ad51ee471f255599fdcee0d6be107 100644 (file)
@@ -70,7 +70,7 @@
  */
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/time.h>
 #include <haproxy/thread.h>
 #include <import/eb32tree.h>
index 3f26cd47732b735d2b713c92740c668400974462..804416901c5b9afd190d47daad76e24b8e64c02f 100644 (file)
@@ -13,7 +13,7 @@
 #include <haproxy/api.h>
 #include <common/buffer.h>
 #include <common/http.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 #include <types/global.h>
 #include <types/session.h>
index a089318318c1f822d6a68a529952d8faba50abd1..0869d5499101d500c4236144dd00e66739b3d10e 100644 (file)
@@ -29,7 +29,7 @@
 #include <haproxy/debug.h>
 #include <common/http.h>
 #include <common/htx.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/list.h>
 #include <common/standard.h>
 #include <common/ticks.h>
index 0fb0927ba5f491652e755992e728d0bd6bcd6790..bd7f97f10d08fabcde9e50de16c516503df18333 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <haproxy/api.h>
 #include <common/cfgparse.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/list.h>
 #include <common/net_helper.h>
 #include <common/standard.h>
index 92c1b506405865e4c45f76bee72986da20052bc2..955bc4466b956dc0d709b35e29339702fbe9fe78 100644 (file)
@@ -19,7 +19,7 @@
 #include <common/buffer.h>
 #include <haproxy/thread.h>
 #include <common/htx.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 
 #include <types/applet.h>
 #include <types/capture.h>
index 96c09a388ea1169f547d3f0f5624fe8e6d8c3f3f..5663abac7ec5320cdd440d37655d5dc88391dfba 100644 (file)
@@ -13,7 +13,7 @@
 #include <string.h>
 
 #include <haproxy/api.h>
-#include <common/memory.h>
+#include <haproxy/pool.h>
 #include <haproxy/list.h>
 #include <common/standard.h>
 #include <haproxy/time.h>