linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [RFC] locking/rwsem: dont wake up wwaiter in case of lock holder
       [not found] <20220326134059.4082-1-hdanton@sina.com>
@ 2022-03-28 14:18 ` David Hildenbrand
  2022-03-28 15:11   ` Waiman Long
  0 siblings, 1 reply; 2+ messages in thread
From: David Hildenbrand @ 2022-03-28 14:18 UTC (permalink / raw)
  To: Hillf Danton, Waiman Long; +Cc: Peter Zijlstra, MM, LKML

On 26.03.22 14:40, Hillf Danton wrote:
> In the slowpath of down for write, we bail out in case of signal received and
> try to wake up any pending waiter but it makes no sense to wake up a write
> waiter given any lock holder, either write or read.

But is handling this better really worth additional code and runtime
checks? IOW, does this happen often enough that we actually care about
optimizing this? I have no idea :)

> 
> The RFC is do nothing for wwaiter if any lock holder present - they will fill
> their duty at lock release time.
> 
> Only for thoughts now.
> 
> Hillf
> 
> --- x/kernel/locking/rwsem.c
> +++ y/kernel/locking/rwsem.c
> @@ -418,6 +418,8 @@ static void rwsem_mark_wake(struct rw_se
>  	waiter = rwsem_first_waiter(sem);
>  
>  	if (waiter->type == RWSEM_WAITING_FOR_WRITE) {
> +		if (RWSEM_LOCK_MASK & atomic_long_read(&sem->count))
> +			return;
>  		if (wake_type == RWSEM_WAKE_ANY) {
>  			/*
>  			 * Mark writer at the front of the queue for wakeup.
> --
> 


-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFC] locking/rwsem: dont wake up wwaiter in case of lock holder
  2022-03-28 14:18 ` [RFC] locking/rwsem: dont wake up wwaiter in case of lock holder David Hildenbrand
@ 2022-03-28 15:11   ` Waiman Long
  0 siblings, 0 replies; 2+ messages in thread
From: Waiman Long @ 2022-03-28 15:11 UTC (permalink / raw)
  To: David Hildenbrand, Hillf Danton; +Cc: Peter Zijlstra, MM, LKML

On 3/28/22 10:18, David Hildenbrand wrote:
> On 26.03.22 14:40, Hillf Danton wrote:
>> In the slowpath of down for write, we bail out in case of signal received and
>> try to wake up any pending waiter but it makes no sense to wake up a write
>> waiter given any lock holder, either write or read.
> But is handling this better really worth additional code and runtime
> checks? IOW, does this happen often enough that we actually care about
> optimizing this? I have no idea :)
>
>> The RFC is do nothing for wwaiter if any lock holder present - they will fill
>> their duty at lock release time.
>>
>> Only for thoughts now.
>>
>> Hillf
>>
>> --- x/kernel/locking/rwsem.c
>> +++ y/kernel/locking/rwsem.c
>> @@ -418,6 +418,8 @@ static void rwsem_mark_wake(struct rw_se
>>   	waiter = rwsem_first_waiter(sem);
>>   
>>   	if (waiter->type == RWSEM_WAITING_FOR_WRITE) {
>> +		if (RWSEM_LOCK_MASK & atomic_long_read(&sem->count))
>> +			return;
>>   		if (wake_type == RWSEM_WAKE_ANY) {
>>   			/*
>>   			 * Mark writer at the front of the queue for wakeup.
>> --

That check isn't good enough. First of all, any reader count in 
sem->count can be transient due to the fact that we do an unconditional 
atomic_long_add() on down_read(). The reader may then remove its reader 
count in the slow path. This patch may cause missed wakeup which is a 
much bigger problem than spending a bit of cpu time to check for lock 
availability and sleep again.

The write lock bit, however, is real. We do support the first writer in 
the wait queue to spin on the lock when the handoff bit is set. So 
waking up a writer when the rwsem is currently write-locked can still be 
useful.

BTW, I didn't see this RFC patch in LKML. Is it only posted on linux-mm 
originally?

Cheers,
Longman


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-28 15:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220326134059.4082-1-hdanton@sina.com>
2022-03-28 14:18 ` [RFC] locking/rwsem: dont wake up wwaiter in case of lock holder David Hildenbrand
2022-03-28 15:11   ` Waiman Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).