mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Tejun Heo <tj@kernel.org>
Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: Is it really safe to use workqueues to drive expedited grace periods?
Date: Mon, 13 Feb 2017 16:16:00 -0800	[thread overview]
Message-ID: <20170214001600.GZ30506@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170211023541.GB19050@mtj.duckdns.org>

On Sat, Feb 11, 2017 at 11:35:41AM +0900, Tejun Heo wrote:
> Hello, Paul.
> 
> On Fri, Feb 10, 2017 at 01:21:58PM -0800, Paul E. McKenney wrote:
> > So RCU's expedited grace periods have been using workqueues for a
> > little while, and things seem to be working.  But as usual, I worry...
> > Is this use subject to some sort of deadlock where RCU's workqueue cannot
> > start running until after a grace period completes, but that grace
> > period is the one needing the workqueue?  Note that there are ways to
> > set up your kernel so that all RCU grace periods are expedited.
> > 
> > Should I be worried?  If not, what prevents this from being a problem,
> > especially given that workqueue handlers are allowed to wait for RCU
> > grace periods to complete?
> 
> A per-cpu (normal) workqueue's concurrency is regulated automatically
> so that there are at least one worker running for the worker pool on a
> given CPU.
> 
> Let's say there are two work items queued on a workqueue.  The first
> one is something which will do synchronize_rcu() and the second is the
> expedited grace period work item.  When the first one runs
> synchronize_rcu(), it'd block.  If there are no other work items
> running at the time, workqueue will dispatch another worker so that
> there's at least one actively running, which in this case will be the
> expedited rcu grace period work item.
> 
> The dispatching of a new worker can be delayed by two things - memory
> pressure preventing creation of a new worker and the workqueue hitting
> maximum concurrency limit.
> 
> If expedited RCU grace period is something that memory reclaim path
> may depend on, the workqueue that it executes on should have
> WQ_MEM_RECLAIM set, which will guarantee that there's at least one
> worker (across all CPUs) which is ready to serve the work items on
> that workqueue regardless of memory pressure.
> 
> The latter, concurrency limit, would only matter if the RCU work items
> use system_wq.  system_wq's concurrency limit is very high (512 per
> CPU), but it is theoretically possible to fill all up with work items
> doing synchronize_rcu() with the expedited RCU work item scheduled
> behind it.  The system would already be in a very messed up state
> outside the RCU situation tho.

Thank you for the information!  So if I am to continue using workqueues
for expedited RCU grace periods, I believe that need to do the following:

1.	Use alloc_workqueue() to create my own WQ_MEM_RECLAIM
	workqueue.

2.	Rework my workqueue handler to avoid blocking waiting for
	the expedited grace period to complete.  I should be able
	to do a small number of timed wait, but if I actually
	wait for the grace period to complete, I might end up
	hogging the reserved items.  (Or does my workqueue supply
	them for me?  If so, so much the better!)

3.	Concurrency would not be a problem -- there can be no more
	four work elements in flight across both possible flavors
	of expedited grace periods.

Anything I am missing here?

							Thanx, Paul

  reply	other threads:[~2017-02-14  0:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10 21:21 Paul E. McKenney
2017-02-11  2:35 ` Tejun Heo
2017-02-14  0:16   ` Paul E. McKenney [this message]
2017-03-03 19:30     ` Tejun Heo
2017-03-04  0:17       ` Paul E. McKenney

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=20170214001600.GZ30506@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.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

Powered by JetHome