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

@@ -32,6 +32,7 @@
#include <common/config.h>
#include <common/http-hdr.h>
#include <common/ist.h>
#include <common/memory.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
@@ -133,6 +134,7 @@ enum {
/* static header table as in RFC7541 Appendix A. [0] unused. */
#define HPACK_SHT_SIZE 62
extern const struct http_hdr hpack_sht[HPACK_SHT_SIZE];
extern struct pool_head *pool_head_hpack_tbl;
extern int __hpack_dht_make_room(struct hpack_dht *dht, unsigned int needed);
extern int hpack_dht_insert(struct hpack_dht *dht, struct ist name, struct ist value);
@@ -233,23 +235,24 @@ static inline void hpack_dht_init(struct hpack_dht *dht, uint32_t size)
dht->used = 0;
}
/* allocate a dynamic headers table of <size> bytes and return it initialized */
static inline struct hpack_dht *hpack_dht_alloc(uint32_t size)
/* allocate a dynamic headers table from the pool and return it initialized */
static inline struct hpack_dht *hpack_dht_alloc()
{
struct hpack_dht *dht;
dht = malloc(size);
if (!dht)
return dht;
if (unlikely(!pool_head_hpack_tbl))
return NULL;
hpack_dht_init(dht, size);
dht = pool_alloc(pool_head_hpack_tbl);
if (dht)
hpack_dht_init(dht, pool_head_hpack_tbl->size);
return dht;
}
/* free a dynamic headers table */
static inline void hpack_dht_free(struct hpack_dht *dht)
{
free(dht);
pool_free(pool_head_hpack_tbl, dht);
}
#endif /* _COMMON_HPACK_TBL_H */