From aad6b771dd270680e3cf1850fa47fbfc8d0f1538 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 15 Sep 2024 23:05:50 +0200 Subject: [PATCH] OPTIM: vars: remove the unneeded lock in vars_prune_* vars_prune() and vars_prune_all() take the variable lock while purging all variables from a head. However this is not needed: - proc scope variables are only purged during deinit, hence no lock is needed ; - all other scopes are attached to entities bound to a single thread so no lock is needed either. Removing the lock saves about 0.5% CPU on variables-intensive setups, but above all simplify the code, so let's do it. --- src/vars.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/vars.c b/src/vars.c index 0e2029de7..772ae3402 100644 --- a/src/vars.c +++ b/src/vars.c @@ -203,11 +203,10 @@ void vars_prune(struct vars *vars, struct session *sess, struct stream *strm) struct var *var, *tmp; unsigned int size = 0; - vars_wrlock(vars); list_for_each_entry_safe(var, tmp, &vars->head, l) { size += var_clear(var, 1); } - vars_wrunlock(vars); + var_accounting_diff(vars, sess, strm, -size); } @@ -219,11 +218,9 @@ void vars_prune_per_sess(struct vars *vars) struct var *var, *tmp; unsigned int size = 0; - vars_wrlock(vars); list_for_each_entry_safe(var, tmp, &vars->head, l) { size += var_clear(var, 1); } - vars_wrunlock(vars); if (var_sess_limit) _HA_ATOMIC_SUB(&vars->size, size);