MEDIUM: stktable: index table names using compact trees

Here we're saving 64 bytes per stick-table, from 3392 to 3328, and the
change was really straightforward so there's no reason not to do it.
This commit is contained in:
Willy Tarreau 2025-07-15 13:50:03 +02:00
parent d0d60a007d
commit f4059ea42f
2 changed files with 8 additions and 18 deletions

View File

@ -23,6 +23,7 @@
#ifndef _HAPROXY_STICK_TABLE_T_H
#define _HAPROXY_STICK_TABLE_T_H
#include <import/cebtree.h>
#include <import/ebtree-t.h>
#include <haproxy/api-t.h>
@ -166,13 +167,13 @@ struct stksess {
/* stick table */
struct stktable {
char *id; /* local table id name. */
size_t idlen; /* local table id name length. */
char *id; /* local table id name, indexed by <id_node> below. */
size_t idlen; /* local table id name length. */
char *nid; /* table id name sent over the network with peers protocol. */
struct stktable *next; /* The stick-table may be linked when belonging to
* the same configuration section.
*/
struct ebpt_node name; /* Stick-table are lookup by name here. */
struct ceb_node id_node; /* Stick-table are lookup by name here, indexes <id> above. */
struct pool_head *pool; /* pool used to allocate sticky sessions */
struct task *exp_task; /* expiration task */
struct task *sync_task; /* sync task */

View File

@ -14,9 +14,9 @@
#include <string.h>
#include <errno.h>
#include <import/cebis_tree.h>
#include <import/ebmbtree.h>
#include <import/ebsttree.h>
#include <import/ebistree.h>
#include <haproxy/api.h>
#include <haproxy/applet.h>
@ -64,7 +64,7 @@ static THREAD_LOCAL struct stktable_key static_table_key;
static int (*smp_fetch_src)(const struct arg *, struct sample *, const char *, void *);
struct pool_head *pool_head_stk_ctr __read_mostly = NULL;
struct stktable *stktables_list;
struct eb_root stktable_by_name = EB_ROOT;
struct ceb_root *stktable_by_name = NULL;
#define round_ptr_size(i) (((i) + (sizeof(void *) - 1)) &~ (sizeof(void *) - 1))
@ -74,23 +74,12 @@ struct eb_root stktable_by_name = EB_ROOT;
*/
void stktable_store_name(struct stktable *t)
{
t->name.key = t->id;
ebis_insert(&stktable_by_name, &t->name);
cebis_item_insert(&stktable_by_name, id_node, id, t);
}
struct stktable *stktable_find_by_name(const char *name)
{
struct ebpt_node *node;
struct stktable *t;
node = ebis_lookup(&stktable_by_name, name);
if (node) {
t = container_of(node, struct stktable, name);
if (strcmp(t->id, name) == 0)
return t;
}
return NULL;
return cebis_item_lookup(&stktable_by_name, id_node, id, name, struct stktable);
}
/*