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.
This commit is contained in:
Willy Tarreau 2024-09-15 23:05:50 +02:00
parent 51ade2f1db
commit aad6b771dd

View File

@ -203,11 +203,10 @@ void vars_prune(struct vars *vars, struct session *sess, struct stream *strm)
struct var *var, *tmp; struct var *var, *tmp;
unsigned int size = 0; unsigned int size = 0;
vars_wrlock(vars);
list_for_each_entry_safe(var, tmp, &vars->head, l) { list_for_each_entry_safe(var, tmp, &vars->head, l) {
size += var_clear(var, 1); size += var_clear(var, 1);
} }
vars_wrunlock(vars);
var_accounting_diff(vars, sess, strm, -size); var_accounting_diff(vars, sess, strm, -size);
} }
@ -219,11 +218,9 @@ void vars_prune_per_sess(struct vars *vars)
struct var *var, *tmp; struct var *var, *tmp;
unsigned int size = 0; unsigned int size = 0;
vars_wrlock(vars);
list_for_each_entry_safe(var, tmp, &vars->head, l) { list_for_each_entry_safe(var, tmp, &vars->head, l) {
size += var_clear(var, 1); size += var_clear(var, 1);
} }
vars_wrunlock(vars);
if (var_sess_limit) if (var_sess_limit)
_HA_ATOMIC_SUB(&vars->size, size); _HA_ATOMIC_SUB(&vars->size, size);