]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stick-table: permit stksess_new() to temporarily allocate more entries
authorWilly Tarreau <w@1wt.eu>
Tue, 9 Sep 2025 14:39:08 +0000 (16:39 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 9 Sep 2025 15:56:37 +0000 (17:56 +0200)
stksess_new() calls stktable_trash_oldest() to release some entries.
If it fails however, it will fail to allocate an entry. This is a problem
because it doesn't permit stktable_trash_oldest() to be used in best effort
mode, which forces it to impose high contention. There's no problem with
allocating slightly more in practice. In the worst case if all entries are
in use, it's not shocking to temporarily exceed the number of entries by a
few units.

Let's relax this problematic rule. This patch might need to be backported
to 3.2 after a bit more testing in order to support locking relaxation.

src/stick_table.c

index a73b30a95a69e6f56394d183767e122bd05cca0d..def13d14d79b0fce4fd90e27881d98fbd33ef657 100644 (file)
@@ -430,11 +430,15 @@ struct stksess *stksess_new(struct stktable *t, struct stktable_key *key)
 
        if (unlikely(current >= t->size)) {
                /* the table was already full, we may have to purge entries */
-               if ((t->flags & STK_FL_NOPURGE) ||
-                   !stktable_trash_oldest(t, (t->size >> 8) + 1)) {
+               if (t->flags & STK_FL_NOPURGE) {
                        HA_ATOMIC_DEC(&t->current);
                        return NULL;
                }
+               /* note that it may fail to find any releasable slot due to
+                * locking contention but it's not a problem in practice,
+                * these will be recovered later.
+                */
+               stktable_trash_oldest(t, (t->size >> 8) + 1);
        }
 
        ts = pool_alloc(t->pool);