]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: vars: remove the unneeded lock in vars_prune_*
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Sep 2024 21:05:50 +0000 (23:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 15 Sep 2024 21:05:50 +0000 (23:05 +0200)
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

index 0e2029de77e4a7f5a527d72fb98ca0e6c6628859..772ae340224c7feb6e08825ca46461a0116fbdf2 100644 (file)
@@ -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);