From: Willy Tarreau Date: Sun, 15 Sep 2024 21:05:50 +0000 (+0200) Subject: OPTIM: vars: remove the unneeded lock in vars_prune_* X-Git-Tag: v3.1-dev8~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aad6b771dd270680e3cf1850fa47fbfc8d0f1538;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/vars.c b/src/vars.c index 0e2029de77..772ae34022 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);