REORG: include: move common/memory.h to haproxy/pool.h
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.
This commit is contained in:
parent
ed891fda52
commit
d0ef439699
2
Makefile
2
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 \
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
|
||||
@ -31,36 +31,6 @@
|
||||
#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:
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
#include <haproxy/api.h>
|
||||
#include <common/memory.h>
|
||||
#include <haproxy/pool.h>
|
||||
#include <haproxy/list.h>
|
||||
#include <common/standard.h>
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include <haproxy/api.h>
|
||||
#include <common/buffer.h>
|
||||
#include <common/memory.h>
|
||||
#include <haproxy/pool.h>
|
||||
|
||||
#include <types/global.h>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user