]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stick-tables: Stop as soon as stktable_trash_oldest succeeds.
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 15 Oct 2025 14:01:21 +0000 (16:01 +0200)
committerOlivier Houchard <cognet@ci0.org>
Mon, 20 Oct 2025 13:04:47 +0000 (15:04 +0200)
stktable_trash_oldest() goes through all the shards, trying to free a
number of entries. Going through each shard is expensive, as we have to
take the shard lock, so stop as soon as we free'd at least one entry, as
it is only called when we want to make room for one entry.

src/stick_table.c

index 2d889b48a0bb86bb16c3e45417fa3a0e44720794..0d50a9d63178ee56559c149682e8fc9c8961d127 100644 (file)
@@ -414,6 +414,14 @@ int stktable_trash_oldest(struct stktable *t)
 
                HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
 
+               /*
+                * There is not much point in trying to purge more entries,
+                * it will be as costly to acquire the lock for the next shard,
+                * as it would be for the next session creation, so if we
+                * managed to purge at least one entry, give up now.
+                */
+               if (batched > 0)
+                       break;
                shard++;
                if (shard >= CONFIG_HAP_TBL_BUCKETS)
                        shard = 0;