]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stick-table: use a separate lock label for updates
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Apr 2025 12:01:13 +0000 (14:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Apr 2025 12:02:22 +0000 (14:02 +0200)
Too many locks were sharing STK_TABLE_LOCK making it hard to analyze.
Let's split the already heavily used update lock.

include/haproxy/thread-t.h
src/peers.c
src/stick_table.c
src/thread.c

index 631eeba8b34fa176ef4a1047c93b256f244d62a2..f1e7895a54089f89c78f212693069903092b48b5 100644 (file)
@@ -171,6 +171,7 @@ enum lock_label {
        LBPRM_LOCK,
        SIGNALS_LOCK,
        STK_TABLE_LOCK,
+       STK_TABLE_UPDT_LOCK,
        STK_SESS_LOCK,
        APPLETS_LOCK,
        PEER_LOCK,
index 3abfd2735fe1851e849965fb92df3b3454edc218..f6d9ade2c040e440bd185408740290c2a54d2b07 100644 (file)
@@ -1568,7 +1568,7 @@ static inline int peer_send_teachmsgs(struct appctx *appctx, struct peer *p,
        /* We force new pushed to 1 to force identifier in update message */
        new_pushed = 1;
 
-       HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &st->table->updt_lock);
+       HA_RWLOCK_RDLOCK(STK_TABLE_UPDT_LOCK, &st->table->updt_lock);
 
        while (1) {
                struct stksess *ts;
@@ -1590,10 +1590,10 @@ static inline int peer_send_teachmsgs(struct appctx *appctx, struct peer *p,
                }
 
                HA_ATOMIC_INC(&ts->ref_cnt);
-               HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &st->table->updt_lock);
+               HA_RWLOCK_RDUNLOCK(STK_TABLE_UPDT_LOCK, &st->table->updt_lock);
 
                ret = peer_send_updatemsg(st, appctx, ts, updateid, new_pushed, use_timed);
-               HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &st->table->updt_lock);
+               HA_RWLOCK_RDLOCK(STK_TABLE_UPDT_LOCK, &st->table->updt_lock);
                HA_ATOMIC_DEC(&ts->ref_cnt);
                if (ret <= 0)
                        break;
@@ -1622,7 +1622,7 @@ static inline int peer_send_teachmsgs(struct appctx *appctx, struct peer *p,
        }
 
  out:
-       HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &st->table->updt_lock);
+       HA_RWLOCK_RDUNLOCK(STK_TABLE_UPDT_LOCK, &st->table->updt_lock);
        return ret;
 }
 
@@ -2639,9 +2639,9 @@ static inline int peer_send_msgs(struct appctx *appctx,
                        if (!(peer->flags & PEER_F_TEACH_PROCESS)) {
                                int must_send;
 
-                               HA_RWLOCK_RDLOCK(STK_TABLE_LOCK, &st->table->updt_lock);
+                               HA_RWLOCK_RDLOCK(STK_TABLE_UPDT_LOCK, &st->table->updt_lock);
                                must_send = (peer->learnstate == PEER_LR_ST_NOTASSIGNED) && (st->last_pushed != st->table->localupdate);
-                               HA_RWLOCK_RDUNLOCK(STK_TABLE_LOCK, &st->table->updt_lock);
+                               HA_RWLOCK_RDUNLOCK(STK_TABLE_UPDT_LOCK, &st->table->updt_lock);
 
                                if (must_send) {
                                        repl = peer_send_teach_process_msgs(appctx, peer, st);
@@ -2834,7 +2834,7 @@ static inline void init_connected_peer(struct peer *peer, struct peers *peers)
                uint updateid, commitid;
 
                st->last_get = st->last_acked = 0;
-               HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &st->table->updt_lock);
+               HA_RWLOCK_WRLOCK(STK_TABLE_UPDT_LOCK, &st->table->updt_lock);
                /* if st->update appears to be in future it means
                 * that the last acked value is very old and we
                 * remain unconnected a too long time to use this
@@ -2858,7 +2858,7 @@ static inline void init_connected_peer(struct peer *peer, struct peers *peers)
                        __ha_cpu_relax();
                }
 
-               HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &st->table->updt_lock);
+               HA_RWLOCK_WRUNLOCK(STK_TABLE_UPDT_LOCK, &st->table->updt_lock);
        }
 
        /* Awake main task to ack the new peer state */
index bb73e5f699b60307cf4bab6d6f4d3a0e404806de..8b5192f9d76acd9eba146632cf166e4d860c44da 100644 (file)
@@ -146,7 +146,7 @@ int __stksess_kill(struct stktable *t, struct stksess *ts)
 
        if (ts->upd.node.leaf_p) {
                updt_locked = 1;
-               HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
+               HA_RWLOCK_WRLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
                if (HA_ATOMIC_LOAD(&ts->ref_cnt))
                        goto out_unlock;
        }
@@ -157,7 +157,7 @@ int __stksess_kill(struct stktable *t, struct stksess *ts)
 
   out_unlock:
        if (updt_locked)
-               HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->updt_lock);
+               HA_RWLOCK_WRUNLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
        return 1;
 }
 
@@ -365,7 +365,7 @@ int stktable_trash_oldest(struct stktable *t, int to_batch)
                        if (ts->upd.node.leaf_p) {
                                if (!updt_locked) {
                                        updt_locked = 1;
-                                       HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                                       HA_RWLOCK_WRLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
                                }
                                /* now we're locked, new peers can't grab it anymore,
                                 * existing ones already have the ref_cnt.
@@ -383,7 +383,7 @@ int stktable_trash_oldest(struct stktable *t, int to_batch)
                }
 
                if (updt_locked)
-                       HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                       HA_RWLOCK_WRUNLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
 
                HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
 
@@ -603,7 +603,7 @@ void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local,
                         */
                        if (!ts->upd.node.leaf_p || _HA_ATOMIC_LOAD(&ts->seen)) {
                                /* Time to upgrade the read lock to write lock */
-                               HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                               HA_RWLOCK_WRLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
                                use_wrlock = 1;
 
                                /* here we're write-locked */
@@ -633,7 +633,7 @@ void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local,
                         */
                        if (!ts->upd.node.leaf_p) {
                                /* Time to upgrade the read lock to write lock if needed */
-                               HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                               HA_RWLOCK_WRLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
                                use_wrlock = 1;
 
                                /* here we're write-locked */
@@ -651,7 +651,7 @@ void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int local,
 
                /* drop the lock now */
                if (use_wrlock)
-                       HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                       HA_RWLOCK_WRUNLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
        }
 
        if (decrefcnt)
@@ -941,7 +941,7 @@ struct task *process_table_expire(struct task *task, void *context, unsigned int
                        if (ts->upd.node.leaf_p) {
                                if (!updt_locked) {
                                        updt_locked = 1;
-                                       HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                                       HA_RWLOCK_WRLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
                                }
                                /* now we're locked, new peers can't grab it anymore,
                                 * existing ones already have the ref_cnt.
@@ -961,7 +961,7 @@ struct task *process_table_expire(struct task *task, void *context, unsigned int
 
        out_unlock:
                if (updt_locked)
-                       HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->updt_lock);
+                       HA_RWLOCK_WRUNLOCK(STK_TABLE_UPDT_LOCK, &t->updt_lock);
 
                task_exp = tick_first(task_exp, exp_next);
                HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock);
index ab55e89fec1d697ca1bbaa7b9c45a30402193181..ef98648f2aa6c4c3df1f1e7bf8689c0be458edcb 100644 (file)
@@ -410,6 +410,7 @@ static const char *lock_label(enum lock_label label)
        case LBPRM_LOCK:           return "LBPRM";
        case SIGNALS_LOCK:         return "SIGNALS";
        case STK_TABLE_LOCK:       return "STK_TABLE";
+       case STK_TABLE_UPDT_LOCK:       return "STK_TABLE_UPDT";
        case STK_SESS_LOCK:        return "STK_SESS";
        case APPLETS_LOCK:         return "APPLETS";
        case PEER_LOCK:            return "PEER";