On 1/18/24 11:51 AM, Bart Van Assche wrote: > On 1/18/24 10:45, Jens Axboe wrote: >> Do you read the replies to the emails, from the other thread? > > Yes. Well it's been a bit frustrating to say the least, as you seem to either not read them or just ignore what's in them. > > And secondly, this avoids a RMW if it's already set. > From the spinlock implementation (something I looked up before I wrote > my previous reply): > > static __always_inline int queued_spin_trylock(struct qspinlock *lock) > { > int val = atomic_read(&lock->val); > > if (unlikely(val)) > return 0; > > return likely(atomic_try_cmpxchg_acquire(&lock->val, &val, > _Q_LOCKED_VAL)); > } > > I think this implementation does not perform a RMW if the spinlock is > already locked. This looks like a generic trylock, is the same true for the arch variants? Because your attempt either failed because of RMW or because you are hammering it repeatedly, or both. In any case, even if any trylock would avoid the initial atomic, it doesn't give you anything that a bitop would not just do, and we use the latter trick elsewhere in blk-mq. -- Jens Axboe