void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size);
void *pool_destroy(struct pool_head *pool);
void pool_destroy_all(void);
-int mem_should_fail(const struct pool_head *pool);
void *__pool_alloc(struct pool_head *pool, unsigned int flags);
void __pool_free(struct pool_head *pool, void *ptr);
static struct list pools __read_mostly = LIST_HEAD_INIT(pools);
int mem_poison_byte __read_mostly = -1;
-uint pool_debugging __read_mostly = 0; /* set of POOL_DBG_* flags */
-
+uint pool_debugging __read_mostly = /* set of POOL_DBG_* flags */
#ifdef DEBUG_FAIL_ALLOC
-static int mem_fail_rate __read_mostly = 0;
+ POOL_DBG_FAIL_ALLOC |
#endif
+ 0;
+static int mem_fail_rate __read_mostly = 0;
static int using_default_allocator __read_mostly = 1;
static int(*my_mallctl)(const char *, void *, size_t *, void *, size_t) = NULL;
return using_default_allocator;
}
+static int mem_should_fail(const struct pool_head *pool)
+{
+ int ret = 0;
+
+ if (mem_fail_rate > 0 && !(global.mode & MODE_STARTING)) {
+ if (mem_fail_rate > statistical_prng_range(100))
+ ret = 1;
+ else
+ ret = 0;
+ }
+ return ret;
+}
+
/* 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. Two flags are supported :
void *p = NULL;
void *caller = NULL;
-#ifdef DEBUG_FAIL_ALLOC
- if (unlikely(!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool)))
- return NULL;
-#endif
+ if (unlikely(pool_debugging & POOL_DBG_FAIL_ALLOC))
+ if (!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool))
+ return NULL;
#if defined(DEBUG_POOL_TRACING)
caller = __builtin_return_address(0);
INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
-#ifdef DEBUG_FAIL_ALLOC
-
-int mem_should_fail(const struct pool_head *pool)
-{
- int ret = 0;
-
- if (mem_fail_rate > 0 && !(global.mode & MODE_STARTING)) {
- if (mem_fail_rate > statistical_prng_range(100))
- ret = 1;
- else
- ret = 0;
- }
- return ret;
-
-}
/* config parser for global "tune.fail-alloc" */
static int mem_parse_global_fail_alloc(char **args, int section_type, struct proxy *curpx,
}
return 0;
}
-#endif
/* register global config keywords */
static struct cfg_kw_list mem_cfg_kws = {ILH, {
-#ifdef DEBUG_FAIL_ALLOC
{ CFG_GLOBAL, "tune.fail-alloc", mem_parse_global_fail_alloc },
-#endif
{ 0, NULL, NULL }
}};