MINOR: stick-table: use a separate lock label for updates

Too many locks were sharing STK_TABLE_LOCK making it hard to analyze.
Let's split the already heavily used update lock.
This commit is contained in:
Willy Tarreau 2025-04-24 14:01:13 +02:00
parent f192e446d6
commit 1af592c511
4 changed files with 19 additions and 17 deletions

View 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,

View 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 */

View 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);

View 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";