MEDIUM: server: switch the host_dn member to cebis_tree

This member is used to index the hostname_dn contents for DNS resolution.
Let's replace it with a cebis_tree to save another 32 bytes (24 for the
node + 8 by avoiding the duplication of the pointer). The struct server is
now at 3904 bytes.
This commit is contained in:
Willy Tarreau 2025-07-07 17:11:33 +02:00
parent 413e903a22
commit fdf6fd5b45
4 changed files with 15 additions and 20 deletions

View File

@ -297,7 +297,7 @@ struct resolv_srvrq {
int hostname_dn_len; /* string length of the server hostname in Domain Name format */ int hostname_dn_len; /* string length of the server hostname in Domain Name format */
struct resolv_requester *requester; /* used to link to its DNS resolution */ struct resolv_requester *requester; /* used to link to its DNS resolution */
struct list attached_servers; /* List of the servers free to use */ struct list attached_servers; /* List of the servers free to use */
struct eb_root named_servers; /* tree of servers indexed by hostnames found in server state file */ struct ceb_root *named_servers; /* tree of servers indexed by hostnames found in server state file */
struct list list; /* Next SRV RQ for the same proxy */ struct list list; /* Next SRV RQ for the same proxy */
}; };

View File

@ -454,7 +454,8 @@ struct server {
char *lastaddr; /* the address string provided by the server-state file */ char *lastaddr; /* the address string provided by the server-state file */
struct resolv_options resolv_opts; struct resolv_options resolv_opts;
int hostname_dn_len; /* string length of the server hostname in Domain Name format */ int hostname_dn_len; /* string length of the server hostname in Domain Name format */
char *hostname_dn; /* server hostname in Domain Name format (name is lower cased) */ char *hostname_dn; /* server hostname in Domain Name format (name is lower cased), key to host_dn below */
char *hostname; /* server hostname */ char *hostname; /* server hostname */
struct sockaddr_storage init_addr; /* plain IP address specified on the init-addr line */ struct sockaddr_storage init_addr; /* plain IP address specified on the init-addr line */
unsigned int init_addr_methods; /* initial address setting, 3-bit per method, ends at 0, enough to store 10 entries */ unsigned int init_addr_methods; /* initial address setting, 3-bit per method, ends at 0, enough to store 10 entries */
@ -505,7 +506,7 @@ struct server {
struct resolv_srvrq *srvrq; /* Pointer representing the DNS SRV requeest, if any */ struct resolv_srvrq *srvrq; /* Pointer representing the DNS SRV requeest, if any */
struct list srv_rec_item; /* to attach server to a srv record item */ struct list srv_rec_item; /* to attach server to a srv record item */
struct list ip_rec_item; /* to attach server to a A or AAAA record item */ struct list ip_rec_item; /* to attach server to a A or AAAA record item */
struct ebpt_node host_dn; /* hostdn store for srvrq and state file matching*/ struct ceb_node host_dn; /* hostdn store for srvrq and state file matching (uses hostname_dn above) */
struct list pp_tlvs; /* to send out PROXY protocol v2 TLVs */ struct list pp_tlvs; /* to send out PROXY protocol v2 TLVs */
struct task *srvrq_check; /* Task testing SRV record expiration date for this server */ struct task *srvrq_check; /* Task testing SRV record expiration date for this server */
struct { struct {

View File

@ -18,7 +18,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <import/ebistree.h> #include <import/cebis_tree.h>
#include <haproxy/action.h> #include <haproxy/action.h>
#include <haproxy/api.h> #include <haproxy/api.h>
@ -308,7 +308,7 @@ struct resolv_srvrq *new_resolv_srvrq(struct server *srv, char *fqdn)
goto err; goto err;
} }
LIST_INIT(&srvrq->attached_servers); LIST_INIT(&srvrq->attached_servers);
srvrq->named_servers = EB_ROOT; srvrq->named_servers = NULL;
LIST_APPEND(&resolv_srvrq_list, &srvrq->list); LIST_APPEND(&resolv_srvrq_list, &srvrq->list);
return srvrq; return srvrq;
@ -744,8 +744,7 @@ static void resolv_srvrq_cleanup_srv(struct server *srv)
HA_SPIN_LOCK(SERVER_LOCK, &srv->lock); HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
srvrq_set_srv_down(srv); srvrq_set_srv_down(srv);
ebpt_delete(&srv->host_dn); cebis_item_delete(&srv->srvrq->named_servers, host_dn, hostname_dn, srv);
srv->host_dn.key = NULL;
ha_free(&srv->hostname); ha_free(&srv->hostname);
ha_free(&srv->hostname_dn); ha_free(&srv->hostname_dn);
@ -836,7 +835,6 @@ static void resolv_check_response(struct resolv_resolution *res)
/* Now process SRV records */ /* Now process SRV records */
list_for_each_entry(req, &res->requesters, list) { list_for_each_entry(req, &res->requesters, list) {
struct ebpt_node *node;
char target[DNS_MAX_NAME_SIZE+1]; char target[DNS_MAX_NAME_SIZE+1];
int i; int i;
@ -856,7 +854,7 @@ static void resolv_check_response(struct resolv_resolution *res)
/* If not empty we try to match a server /* If not empty we try to match a server
* in server state file tree with the same hostname * in server state file tree with the same hostname
*/ */
if (!eb_is_empty(&srvrq->named_servers)) { if (!srvrq->named_servers) {
srv = NULL; srv = NULL;
/* convert the key to lookup in lower case */ /* convert the key to lookup in lower case */
@ -864,9 +862,8 @@ static void resolv_check_response(struct resolv_resolution *res)
target[i] = tolower((unsigned char)item->data.target[i]); target[i] = tolower((unsigned char)item->data.target[i]);
target[i] = 0; target[i] = 0;
node = ebis_lookup(&srvrq->named_servers, target); srv = cebis_item_lookup(&srvrq->named_servers, host_dn, hostname_dn, target, struct server);
if (node) { if (srv) {
srv = ebpt_entry(node, struct server, host_dn);
HA_SPIN_LOCK(SERVER_LOCK, &srv->lock); HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
/* an entry was found with the same hostname /* an entry was found with the same hostname
@ -877,18 +874,16 @@ static void resolv_check_response(struct resolv_resolution *res)
while (1) { while (1) {
if (srv->svc_port == item->port) { if (srv->svc_port == item->port) {
/* server found, we remove it from tree */ /* server found, we remove it from tree */
ebpt_delete(node); cebis_item_delete(&srvrq->named_servers, host_dn, hostname_dn, srv);
srv->host_dn.key = NULL;
goto srv_found; goto srv_found;
} }
HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock); HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
node = ebpt_next(node); srv = cebis_item_next(&srvrq->named_servers, host_dn, hostname_dn, srv);
if (!node) if (!srv)
break; break;
srv = ebpt_entry(node, struct server, host_dn);
HA_SPIN_LOCK(SERVER_LOCK, &srv->lock); HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
if ((item->data_len != srv->hostname_dn_len) if ((item->data_len != srv->hostname_dn_len)

View File

@ -13,7 +13,7 @@
#include <errno.h> #include <errno.h>
#include <import/eb64tree.h> #include <import/eb64tree.h>
#include <import/ebistree.h> #include <import/cebis_tree.h>
#include <haproxy/api.h> #include <haproxy/api.h>
#include <haproxy/backend.h> #include <haproxy/backend.h>
@ -415,10 +415,9 @@ static void srv_state_srv_update(struct server *srv, int version, char **params)
* since this server has an hostname * since this server has an hostname
*/ */
LIST_DEL_INIT(&srv->srv_rec_item); LIST_DEL_INIT(&srv->srv_rec_item);
srv->host_dn.key = srv->hostname_dn;
/* insert in tree and set the srvrq expiration date */ /* insert in tree and set the srvrq expiration date */
ebis_insert(&srv->srvrq->named_servers, &srv->host_dn); cebis_item_insert(&srv->srvrq->named_servers, host_dn, hostname_dn, srv);
task_schedule(srv->srvrq_check, tick_add(now_ms, srv->srvrq->resolvers->timeout.resolve + task_schedule(srv->srvrq_check, tick_add(now_ms, srv->srvrq->resolvers->timeout.resolve +
srv->srvrq->resolvers->resolve_retries * srv->srvrq->resolvers->resolve_retries *
srv->srvrq->resolvers->timeout.retry)); srv->srvrq->resolvers->timeout.retry));