From: NeilBrown <neilb@suse.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, NFS <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH/RFC] SCHED: allow wait_on_bit functions to support a timeout.
Date: Tue, 29 Apr 2014 23:00:10 +1000 [thread overview]
Message-ID: <20140429230010.32cea174@notabene.brown> (raw)
In-Reply-To: <20140429103217.GQ27561@twins.programming.kicks-ass.net>
[-- Attachment #1: Type: text/plain, Size: 3638 bytes --]
On Tue, 29 Apr 2014 12:32:17 +0200 Peter Zijlstra <peterz@infradead.org>
wrote:
> On Tue, Apr 29, 2014 at 07:44:06PM +1000, NeilBrown wrote:
> >
> >
> > It is currently not possible for various wait_on_bit functions to
> > implement a timeout.
> > While the "action" function that is called to do the waiting could
> > certainly use schedule_timeout(), there is no way to carry forward the
> > remaining timeout after a false wake-up.
> > As false-wakeups a clearly possible at least due to possible
> > hash collisions in bit_waitqueue(), this is a real problem.
> >
> > The 'action' function is currently passed a pointer to the word
> > containing the bit being waited on. Of the 27 currently defined
> > action functions, zero of them use this pointer.
> > So changing it to something else will be a little noisy but will have
> > no immediate effect.
> >
> > This patch changes the 'action' function to take a pointer to the
> > "struct wait_bit_key", which contains a pointer to the word
> > containing the bit so nothing is really lost.
> >
> > It also adds a 'private' field to "struct wait_bit_key", which is
> > initialized to zero.
> >
> > An action function can now implement a timeout with something like
> >
> > static int timed_out_waiter(struct wait_bit_key *key)
> > {
> > unsigned long waited;
> > if (key->private == 0) {
> > key->private = jiffies;
> > if (key->private == 0)
> > key->private -= 1;
> > }
> > waited = jiffies - key->private;
> > if (waited > 10 * HZ)
> > return -EAGAIN;
> > schedule_timeout(waited - 10 * HZ);
> > return 0;
> > }
> >
> > If any other need for context in a waiter were found it would be easy
> > to use ->private for some other purpose, or even extend "struct
> > wait_bit_key".
> >
> > My particular need is to support timeouts in nfs_release_page() to
> > avoid deadlocks with loopback mounted NFS.
>
> So I'm sure I'm not getting it; but why is all the wait_bit crap so
> entirely different from the normal wait stuff?
>
> Surely something like:
>
> wait_event_timeout(&wq, test_bit(bit, word), timeout);
>
> Is pretty much the same, no? The only thing that's different is the wake
> function, but surely we can thread that into there somehow without all
> this silly repetition.
>
> Furthermore, I count about 23 action functions, of which there appear to
> be only like 4 actual variants. Surely such repetition sucks arse and
> should be avoided?
>
Sure, we could replace the interface with something that matches a more
common pattern.
The wait_queue is chosen based on a hash of the bit and the word, and we
sometimes want "test_and_set_bit", and sometimes "test_bit" but we could
probably come up with reasonable definitions for
wait_bit{,_lock}{,_interruptible,_killable}{,_io}{,_freezable}{,_timeout}(
bit, word [, timeout]);
there are 48 functions there. We don't need all of them of course.
My particular use case (as currently designed) wouldn't actually be met by
these. In the 'action' function I current check to see if the connection
that the NFS client has is to the local machine or a remote machine and
adjust the timeout accordingly (and this state can change while waiting).
So I guess we add a "_cmd" set of interfaces too.
I'm not sure it's worth the effort - can we just stick with my idea?
Maybe defined and export action wrappers for
io_schedule schedule schedule(interruptible),
that covers everything except a couple of NFS/RPC things which which should
probably stay local to NFS/RPC.
NeilBrown
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
next prev parent reply other threads:[~2014-04-29 13:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-29 9:44 [PATCH/RFC] SCHED: allow wait_on_bit functions to support a timeout NeilBrown
2014-04-29 10:32 ` Peter Zijlstra
2014-04-29 13:00 ` NeilBrown [this message]
2014-04-30 2:29 ` NeilBrown
2014-04-30 7:31 ` Peter Zijlstra
2014-04-30 7:38 ` Peter Zijlstra
2014-04-30 7:52 ` NeilBrown
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=20140429230010.32cea174@notabene.brown \
--to=neilb@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=mingo@redhat.com \
--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;
as well as URLs for NNTP newsgroup(s).