mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-18 11:36:53 +02:00
This practice relying on POOL_LINK() dates from the era where there were no pool caches, but given that the structures are a bit more complex now and that pool caches do not make use of this feature, it is totally useless since released elements have already been overwritten, and yet it complicates the architecture and prevents from making simplifications and optimizations. Let's just get rid of this feature. The pointer to the origin pool is preserved though, as it helps detect incorrect frees and serves as a canary for overflows.
109 lines
4.0 KiB
C
109 lines
4.0 KiB
C
/*
|
|
* 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-t.h>
|
|
#include <haproxy/list-t.h>
|
|
|
|
#define MEM_F_SHARED 0x1
|
|
#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)
|
|
#endif
|
|
|
|
/* A special pointer for the pool's free_list that indicates someone is
|
|
* currently manipulating it. Serves as a short-lived lock.
|
|
*/
|
|
#define POOL_BUSY ((void *)1)
|
|
|
|
#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
|
|
#define POOL_F_NO_FAIL 0x00000004 // do not randomly fail
|
|
|
|
|
|
/* This is the head of a thread-local cache */
|
|
struct pool_cache_head {
|
|
struct list list; /* head of objects in this pool */
|
|
unsigned int count; /* number of objects in this pool */
|
|
} THREAD_ALIGNED(64);
|
|
|
|
/* This represents one item stored in the thread-local cache. <by_pool> links
|
|
* the object to the list of objects in the pool, and <by_lru> links the object
|
|
* to the local thread's list of hottest objects. This way it's possible to
|
|
* allocate a fresh object from the cache, or to release cold objects from any
|
|
* pool (no bookkeeping is needed since shared pools do not know how many
|
|
* objects they store).
|
|
*/
|
|
struct pool_cache_item {
|
|
struct list by_pool; /* link to objects in this pool */
|
|
struct list by_lru; /* link to objects by LRU order */
|
|
};
|
|
|
|
/* This describes a complete pool, with its status, usage statistics and the
|
|
* thread-local caches if any. Even if pools are disabled, these descriptors
|
|
* are valid and are used at least to get names and sizes. For small builds
|
|
* using neither threads nor pools, this structure might be reduced, and
|
|
* alignment could be removed.
|
|
*/
|
|
struct pool_head {
|
|
void **free_list;
|
|
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 */
|
|
/* 32-bit hole here */
|
|
struct list list; /* list of all known pools */
|
|
char name[12]; /* name of the pool */
|
|
#ifdef CONFIG_HAP_POOLS
|
|
struct pool_cache_head cache[MAX_THREADS]; /* pool caches */
|
|
#endif
|
|
} __attribute__((aligned(64)));
|
|
|
|
#endif /* _HAPROXY_POOL_T_H */
|
|
|
|
/*
|
|
* Local variables:
|
|
* c-indent-level: 8
|
|
* c-basic-offset: 8
|
|
* End:
|
|
*/
|