linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Tony Battersby <tonyb@cybernetics.com>,
	linux-raid@vger.kernel.org, lkml <linux-kernel@vger.kernel.org>,
	axboe@kernel.dk, Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: RAID1 might_sleep() warning on 3.19-rc7
Date: Fri, 13 Feb 2015 19:49:53 +1100	[thread overview]
Message-ID: <20150213194953.0368355d@notabene.brown> (raw)
In-Reply-To: <20150213083250.GN2896@worktop.programming.kicks-ass.net>

[-- Attachment #1: Type: text/plain, Size: 3876 bytes --]

On Fri, 13 Feb 2015 09:32:50 +0100 Peter Zijlstra <peterz@infradead.org>
wrote:

> On Fri, Feb 13, 2015 at 04:26:00PM +1100, NeilBrown wrote:
> > I choose ... Buzz Lightyear !!!
> 
> Great choice!
> 
> > From: NeilBrown <neilb@suse.de>
> > Date: Fri, 13 Feb 2015 15:49:17 +1100
> > Subject: [PATCH] sched: prevent recursion in io_schedule()
> > 
> > io_schedule() calls blk_flush_plug() which, depending on the
> > contents of current->plug, can initiate arbitrary blk-io requests.
> > 
> > Note that this contrasts with blk_schedule_flush_plug() which requires
> > all non-trivial work to be handed off to a separate thread.
> > 
> > This makes it possible for io_schedule() to recurse, and initiating
> > block requests could possibly call mempool_alloc() which, in times of
> > memory pressure, uses io_schedule().
> > 
> > Apart from any stack usage issues, io_schedule() will not behave
> > correctly when called recursively as delayacct_blkio_start() does
> > not allow for repeated calls.
> 
> Which seems to still be an issue with this patch.
> 
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 1f37fe7f77a4..90f3de8bc7ca 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -4420,30 +4420,27 @@ EXPORT_SYMBOL_GPL(yield_to);
> >   */
> >  void __sched io_schedule(void)
> >  {
> > +	io_schedule_timeout(MAX_SCHEDULE_TIMEOUT);
> >  }
> >  EXPORT_SYMBOL(io_schedule);
> 
> Might as well move it to sched.h as an inline or so..
> 
> >  long __sched io_schedule_timeout(long timeout)
> >  {
> > +	struct rq *rq;
> >  	long ret;
> > +	int old_iowait = current->in_iowait;
> > +
> > +	current->in_iowait = 1;
> > +	if (old_iowait)
> > +		blk_schedule_flush_plug(current);
> > +	else
> > +		blk_flush_plug(current);
> >  
> >  	delayacct_blkio_start();
> > +	rq = raw_rq();
> >  	atomic_inc(&rq->nr_iowait);
> >  	ret = schedule_timeout(timeout);
> > +	current->in_iowait = old_iowait;
> >  	atomic_dec(&rq->nr_iowait);
> >  	delayacct_blkio_end();
> >  	return ret;
> 
> Like said, that will still recursive call delayacct_blkio_*() and would
> increase nr_iowait for a second time; while arguably its still the same
> one io-wait instance.

No it doesn't.  There is no "blk_flush_plug" call between the
delayacct_blkio_*() calls.

I've moved blk_flush_plug to the beginning of the function.

> 
> So would a little something like:
> 
> long __sched io_schedule_timeout(long timeout)
> {
> 	struct rq *rq;
> 	long ret;
> 
> 	/*
> 	 * Recursive io_schedule() call; make sure to not recurse
> 	 * on the blk_flush_plug() stuff again.
> 	 */
> 	if (unlikely(current->in_iowait)) {
> 		/*
> 		 * Our parent io_schedule() call will already have done
> 		 * all the required io-wait accounting.
> 		 */
> 		blk_schedule_flush_plug(current);
> 		return schedule_timeout(timeout);
> 	}
> 
> 	current->in_iowait = 1;
> 	delayacct_blkio_start();
> 	rq = raw_rq();
> 	atomic_inc(&rq->nr_iowait);
> 	blk_flush_plug(current);
> 	ret = schedule_timeout(timeout);
> 	atomic_dec(&rq->nr_iowait);
> 	delayacct_blkio_end();
> 	current->in_iowait = 0;
> 
> 	return ret;
> }
> 
> not make more sense? 

That does make a similar amount of sense at least....

I wondered if it really make sense to call blk_flush_plug with nr_iowait
elevated and delayacct_blkio active.  blk_flush_plug() could call schedule()
for non-"io" reasons and maybe that could upset stuff???

I don't really know.  I'm happy with your version.  I don't suppose anyone
else is paying attention and could give a third opinion....

Thanks,
NeilBrown



> --
> To unsubscribe from this list: send the line "unsubscribe linux-raid" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 811 bytes --]

  reply	other threads:[~2015-02-13  8:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-05 20:27 RAID1 might_sleep() warning on 3.19-rc7 Tony Battersby
2015-02-05 21:51 ` NeilBrown
2015-02-06 11:39   ` Peter Zijlstra
2015-02-09  1:13     ` NeilBrown
2015-02-09  9:10       ` Peter Zijlstra
2015-02-10  2:50         ` NeilBrown
2015-02-10  9:29           ` Peter Zijlstra
2015-02-10 11:01             ` Peter Zijlstra
2015-02-13  5:26             ` NeilBrown
2015-02-13  8:32               ` Peter Zijlstra
2015-02-13  8:49                 ` NeilBrown [this message]
2015-02-13 10:27                   ` Peter Zijlstra
2015-02-13 14:48                     ` Peter Zijlstra
2015-02-18  1:09                       ` NeilBrown
2015-02-18 13:47                         ` Peter Zijlstra

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=20150213194953.0368355d@notabene.brown \
    --to=neilb@suse.de \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tonyb@cybernetics.com \
    --cc=torvalds@linux-foundation.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).