From: Davidlohr Bueso <dbueso@suse.de>
To: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
mingo@kernel.org, peterz@infradead.org,
akpm@linux-foundation.org, jack@suse.cz,
kirill.shutemov@linux.intel.com, mhocko@suse.com,
mgorman@techsingularity.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] locking: Introduce range reader/writer lock
Date: Thu, 30 Mar 2017 10:13:12 -0700 [thread overview]
Message-ID: <eef28924b290b3d9e737a4527002fc8b@suse.de> (raw)
In-Reply-To: <1901e378-c18a-3cca-a68a-044867078433@linux.vnet.ibm.com>
On 2017-03-30 07:56, Laurent Dufour wrote:
> On 07/03/2017 06:03, Davidlohr Bueso wrote:
>> +static inline int wait_for_ranges(struct range_rwlock_tree *tree,
>> + struct range_rwlock *lock, long state)
>> +{
>> + int ret = 0;
>> +
>> + while (true) {
>> + set_current_state(state);
>> +
>> + if (unlikely(signal_pending_state(state, current))) {
>> + unsigned long flags;
>> +
>> + ret = -EINTR;
>> + /*
>> + * We're not taking the lock after all, cleanup
>> + * after ourselves.
>> + */
>> + spin_lock_irqsave(&tree->lock, flags);
>> + lock->reader = false;
>> + __range_tree_remove(tree, lock);
>> + spin_unlock_irqrestore(&tree->lock, flags);
>> + break;
>> + }
>> +
>> + /* do we need to go to sleep? */
>> + if (!lock->blocking_ranges)
>> + break;
>
> Hi Davidlohr,
>
> While building a kernel on top of a patched kernel using full range
> lock
> in the place of mmap_sem, I found that fork() sometimes failed
> returning
> ENOMEM.
> It happens that if fork() get called at the time signal is sent to the
> calling process, the call to range_write_lock_interruptible() is
> failing
> even if there is no contention on the lock. This is because we check
> for
> the signal pending before checking for the lock contention in
> wait_for_ranges().
>
> The loop here should rather be :
>
> while (true) {
> /* do we need to go to sleep? */
> if (!lock->blocking_ranges)
> break;
>
Thanks, this makes sense, and is actually the standard way of waiting in
most locks.
> if (unlikely(signal_pending_state(state, current))) {
> unsigned long flags;
>
> ret = -EINTR;
> /*
> * We're not taking the lock after all, cleanup
> * after ourselves.
> */
> spin_lock_irqsave(&tree->lock, flags);
> lock->reader = false;
> __range_tree_remove(tree, lock);
> spin_unlock_irqrestore(&tree->lock, flags);
> break;
> }
>
> set_current_state(state);
>
> schedule();
> }
>
> I also moved the call to set_current_state() before calling schedule(),
> not sure this has to be done this way, but my system seems to work fine
> like this.
No, we do not hold any locks. Please keep set_current_state() the very
first
thing we do in the loop. You can check Documentation/memory-barriers.txt
for details :-)
Thanks,
Davidlohr
next prev parent reply other threads:[~2017-03-30 17:13 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-07 5:03 [PATCH 0/5] locking Introduce range reader/writer lock Davidlohr Bueso
2017-03-07 5:03 ` [PATCH 1/5] locking: " Davidlohr Bueso
2017-03-09 11:03 ` Jan Kara
2017-03-28 10:00 ` Laurent Dufour
2017-03-28 16:39 ` Davidlohr Bueso
2017-03-28 16:58 ` Kirill A. Shutemov
2017-03-29 8:38 ` Laurent Dufour
2017-03-29 15:31 ` Davidlohr Bueso
2017-03-29 15:40 ` Kirill A. Shutemov
2017-03-29 16:10 ` Davidlohr Bueso
2017-04-03 14:19 ` Laurent Dufour
2017-04-03 15:26 ` Davidlohr Bueso
2017-04-03 16:06 ` Jan Kara
2017-04-04 15:31 ` Davidlohr Bueso
2017-03-29 8:56 ` Peter Zijlstra
2017-03-29 15:12 ` Davidlohr Bueso
2017-03-29 8:59 ` Peter Zijlstra
2017-03-29 9:08 ` Peter Zijlstra
2017-03-29 15:05 ` Davidlohr Bueso
2017-03-29 9:11 ` Peter Zijlstra
2017-03-29 9:44 ` Peter Zijlstra
2017-03-29 10:35 ` Peter Zijlstra
2017-03-29 10:49 ` Peter Zijlstra
2017-03-29 15:14 ` Davidlohr Bueso
2017-03-30 14:56 ` Laurent Dufour
2017-03-30 17:13 ` Davidlohr Bueso [this message]
2017-03-07 5:03 ` [PATCH 2/5] locking/locktorture: Fix rwsem reader_delay Davidlohr Bueso
2017-03-07 5:03 ` [PATCH 3/5] locking/locktorture: Fix num reader/writer corner cases Davidlohr Bueso
2017-03-07 5:03 ` [PATCH 4/5] locking/locktorture: Support range rwlocks Davidlohr Bueso
2017-03-07 5:03 ` [PATCH 5/5] staging/lustre: Use generic range rwlock Davidlohr Bueso
2017-03-07 6:05 ` Oleg Drokin
2017-03-08 15:02 ` Davidlohr Bueso
2017-03-09 8:56 ` kbuild test robot
2017-03-09 14:40 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eef28924b290b3d9e737a4527002fc8b@suse.de \
--to=dbueso@suse.de \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=jack@suse.cz \
--cc=kirill.shutemov@linux.intel.com \
--cc=ldufour@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@suse.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox