MEDIUM: memory: use pool_destroy_all() to destroy all pools on deinit()

Instead of exporting a number of pools and having to manually delete
them in deinit() or to have dedicated destructors to remove them, let's
simply kill all pools on deinit().

For this a new function pool_destroy_all() was introduced. As its name
implies, it destroys and frees all pools (provided they don't have any
user anymore of course).

This allowed to remove 4 implicit destructors, 2 explicit ones, and 11
individual calls to pool_destroy(). In addition it properly removes
the mux_pt_ctx pool which was not cleared on exit (no backport needed
here since it's 1.9 only). The sig_handler pool doesn't need to be
exported anymore and became static now.
This commit is contained in:
Willy Tarreau 2018-11-26 15:57:34 +01:00
parent 8ceae72d44
commit 2455cebe00
14 changed files with 12 additions and 66 deletions

View File

@ -47,7 +47,6 @@ extern struct list buffer_wq;
__decl_hathreads(extern HA_SPINLOCK_T buffer_wq_lock);
int init_buffer();
void deinit_buffer();
void buffer_dump(FILE *o, struct buffer *b, int from, int to);
/*****************************************************************/

View File

@ -47,7 +47,6 @@ int chunk_strcasecmp(const struct buffer *chk, const char *str);
struct buffer *get_trash_chunk(void);
struct buffer *alloc_trash_chunk(void);
int init_trash_buffers(int first);
void deinit_trash_buffers(void);
/*
* free a trash chunk allocated by alloc_trash_chunk(). NOP on NULL.

View File

@ -161,6 +161,7 @@ void pool_gc(struct pool_head *pool_ctx);
* This should be called only under extreme circumstances.
*/
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)

View File

@ -20,7 +20,6 @@
extern int signal_queue_len;
extern struct signal_descriptor signal_state[];
extern struct pool_head *pool_head_sig_handlers;
__decl_hathreads(extern HA_SPINLOCK_T signals_lock);

View File

@ -54,11 +54,6 @@ int init_buffer()
return 1;
}
void deinit_buffer()
{
pool_destroy(pool_head_buffer);
}
/*
* Dumps part or all of a buffer.
*/

View File

@ -101,14 +101,6 @@ int init_trash_buffers(int first)
return 1;
}
/*
* free the trash buffers
*/
void deinit_trash_buffers(void)
{
pool_destroy(pool_head_trash);
}
/*
* Allocate a trash chunk from the reentrant pool. The buffer starts at the
* end of the chunk. This chunk must be freed using free_trash_chunk(). This

View File

@ -1839,9 +1839,6 @@ static void dns_deinit(void)
LIST_DEL(&srvrq->list);
free(srvrq);
}
pool_destroy(dns_answer_item_pool);
pool_destroy(dns_resolution_pool);
}
/* Finalizes the DNS configuration by allocating required resources and checking

View File

@ -1192,13 +1192,6 @@ static struct cfg_kw_list cfg_kws = {ILH, {
INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
__attribute__((destructor))
static void
__filters_deinit(void)
{
pool_destroy(pool_head_filter);
}
REGISTER_POST_CHECK(flt_init_all);
REGISTER_PER_THREAD_INIT(flt_init_all_per_thread);
REGISTER_PER_THREAD_DEINIT(flt_deinit_all_per_thread);

View File

@ -4676,11 +4676,3 @@ static struct action_kw_list http_res_action_kws = { { }, {
};
INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_action_kws);
__attribute__((destructor))
static void
__spoe_deinit(void)
{
pool_destroy(pool_head_spoe_ctx);
pool_destroy(pool_head_spoe_appctx);
}

View File

@ -2500,7 +2500,6 @@ void deinit(void)
cfg_unregister_sections();
deinit_log_buffers();
deinit_trash_buffers();
protocol_unbind_all();
@ -2534,20 +2533,7 @@ void deinit(void)
}
vars_prune(&global.vars, NULL, NULL);
deinit_buffer();
pool_destroy(pool_head_stream);
pool_destroy(pool_head_session);
pool_destroy(pool_head_connection);
pool_destroy(pool_head_connstream);
pool_destroy(pool_head_requri);
pool_destroy(pool_head_task);
pool_destroy(pool_head_capture);
pool_destroy(pool_head_pendconn);
pool_destroy(pool_head_sig_handlers);
pool_destroy(pool_head_hdr_idx);
pool_destroy(pool_head_http_txn);
pool_destroy_all();
deinit_pollers();
} /* end deinit() */

View File

@ -436,6 +436,15 @@ void *pool_destroy(struct pool_head *pool)
return NULL;
}
/* This destroys all pools on exit. It is *not* thread safe. */
void pool_destroy_all()
{
struct pool_head *entry, *back;
list_for_each_entry_safe(entry, back, &pools, list)
pool_destroy(entry);
}
/* This function dumps memory usage information into the trash buffer. */
void dump_pools_to_trash()
{

View File

@ -1826,14 +1826,6 @@ static struct mux_proto_list mux_proto_htx =
INITCALL1(STG_REGISTER, register_mux_proto, &mux_proto_htx);
static void __h1_deinit(void)
{
pool_destroy(pool_head_h1c);
pool_destroy(pool_head_h1s);
}
REGISTER_POST_DEINIT(__h1_deinit);
/*
* Local variables:
* c-indent-level: 8

View File

@ -3845,11 +3845,3 @@ static struct cfg_kw_list cfg_kws = {ILH, {
}};
INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
static void __h2_deinit(void)
{
pool_destroy(pool_head_h2s);
pool_destroy(pool_head_h2c);
}
REGISTER_POST_DEINIT(__h2_deinit);

View File

@ -32,7 +32,7 @@ struct signal_descriptor signal_state[MAX_SIGNAL];
sigset_t blocked_sig;
int signal_pending = 0; /* non-zero if t least one signal remains unprocessed */
DECLARE_POOL(pool_head_sig_handlers, "sig_handlers", sizeof(struct sig_handler));
DECLARE_STATIC_POOL(pool_head_sig_handlers, "sig_handlers", sizeof(struct sig_handler));
/* Common signal handler, used by all signals. Received signals are queued.
* Signal number zero has a specific status, as it cannot be delivered by the