MEDIUM: hpack: use a pool for the hpack table

Instead of using malloc/free to allocate an HPACK table, let's declare
a pool. However the HPACK size is configured by the H2 mux, so it's
also this one which allocates it after post_check.
This commit is contained in:
Willy Tarreau
2020-05-19 11:31:11 +02:00
parent 957ec59571
commit 2bdcc70fa7
3 changed files with 29 additions and 9 deletions

View File

@@ -101,6 +101,8 @@ const struct http_hdr hpack_sht[HPACK_SHT_SIZE] = {
[61] = { .n = IST("www-authenticate"), .v = IST("") },
};
struct pool_head *pool_head_hpack_tbl = NULL;
/* returns the slot number of the oldest entry (tail). Must not be used on an
* empty table.
*/
@@ -173,7 +175,7 @@ static struct hpack_dht *hpack_dht_defrag(struct hpack_dht *dht)
/* Note: for small tables we could use alloca() instead but
* portability especially for large tables can be problematic.
*/
alt_dht = hpack_dht_alloc(dht->size);
alt_dht = hpack_dht_alloc();
if (!alt_dht)
return NULL;

View File

@@ -823,7 +823,7 @@ static int h2_init(struct connection *conn, struct proxy *prx, struct session *s
h2c->wait_event.tasklet->context = h2c;
h2c->wait_event.events = 0;
h2c->ddht = hpack_dht_alloc(h2_settings_header_table_size);
h2c->ddht = hpack_dht_alloc();
if (!h2c->ddht)
goto fail;
@@ -6195,3 +6195,18 @@ static struct cfg_kw_list cfg_kws = {ILH, {
}};
INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
/* initialize internal structs after the config is parsed.
* Returns zero on success, non-zero on error.
*/
static int init_h2()
{
pool_head_hpack_tbl = create_pool("hpack_tbl",
h2_settings_header_table_size,
MEM_F_SHARED|MEM_F_EXACT);
if (!pool_head_hpack_tbl)
return -1;
return 0;
}
REGISTER_POST_CHECK(init_h2);