From: David Howells <dhowells@redhat.com>
To: Tejun Heo <tj@kernel.org>
Cc: dhowells@redhat.com, torvalds@linux-foundation.org,
mingo@elte.hu, peterz@infradead.org, awalls@radix.net,
linux-kernel@vger.kernel.org, jeff@garzik.org,
akpm@linux-foundation.org, jens.axboe@oracle.com,
rusty@rustcorp.com.au, cl@linux-foundation.org,
arjan@linux.intel.com, avi@redhat.com, johannes@sipsolutions.net,
andi@firstfloor.org
Subject: Re: [PATCH 35/40] fscache: convert object to use workqueue instead of slow-work
Date: Mon, 15 Feb 2010 15:04:56 +0000 [thread overview]
Message-ID: <27102.1266246296@redhat.com> (raw)
In-Reply-To: <4B763C17.5080707@kernel.org>
Tejun Heo <tj@kernel.org> wrote:
> > Okay, how do you stop the workqueue from having all its threads
> > blocking on pending work? The reason the code you've removed
> > interacts with the slow work facility in this way is that there can
> > be a dependency whereby an executing work item depends on something
> > that is queued. This code allows the thread to be given back to the
> > pool and processing deferred.
>
> How deep the dependency chain can be?
There only needs to be a single dependency in the chain. The problem is that a
pool thread gets blocked waiting for an item on the queue - but if there's a
limited number of pool threads, then all of them can wind up blocked waiting on
the contents of the queue.
The problem I've seen is that a someone goes and bulk-updates a bunch of files
on, say, an NFS server; then FS-Cache flushes all the altered objects and then
attempts to create new replacement ones. However, it was stipulated that all
this had to happen asynchronously - so the new objects have to wait for the old
objects to go away so that they can replace them in the namespace.
So what happens is that the obsolete objects being deleted get executed to
begin deletion, but the deletions then get deferred because the objects are
still undergoing I/O - and so the objects get requeued *behind* the new objects
that are going to wait for them.
> As I wrote in the patch description, wake-me-up-on-another-enqueue can be
> implemented in similar way but I wasn't sure how useful it would be. If the
> dependency chain is strictly bound and significantly shorter than the
> allowed concurrency, it might be better to just leave them sleep.
The problem there is that the timeouts add up and can significantly slow the
system.
> If it's mainly because there can be many concurrent long waiters (but
> no dependency), implementing staggered timeout might be better option.
> I wasn't sure about the requirement there.
We don't really want to time out if we've got threads to spare, and if our
dependency is getting or will get CPU time.
> > Note that just creating more threads isn't a good answer - that can
> > run you out of resources instead.
>
> It depends. The only resource taken up by an idle kthread is small
> amount of memory and it can definitely be traded off against code
> complexity and processing overhead.
And PIDs...
Also the definition of a 'small amount of memory' is dependent on how much
memory you actually have.
> Anyways, this really depends on what is the concurrency requirement there,
> can you please explain what would the bad cases be?
See above. But I've come across this problem and dealt with it, generally
without resorting to timeouts.
> >> + ret = -ENOMEM;
> >> + fscache_object_wq =
> >> + __create_workqueue("fscache_object", WQ_SINGLE_CPU, 99);
> >> + if (!fscache_object_wq)
> >> + goto error_object_wq;
> >> +
> >
> > What does fscache_object_wq being WQ_SINGLE_CPU imply? Does that mean there
> > can only be one CPU processing object state changes?
>
> Yes.
That has scalability implications.
> > I'm not sure that's a good idea - something like a tar command can
> > create thousands of objects, all of which will start undergoing
> > state changes.
>
> The default concurrency level for slow-work is pretty low. Is it
> expected to be tuned to a very high value in certain configurations?
That's why I have a tuning knob. I don't really have the facilities for
working up profiles of different loads, but I expect there's a sweet spot for
any particular load. You have to trade the amount of time and resources it
takes to waggle the disk around off against the number of things you want to
cache.
> > Why did you do this? Is it because cmwq does _not_ prevent reentrance to
> > executing work items? I take it that's why you can get away with this:
>
> and yes, I used it as a cheap way to avoid reentrance. For most
> cases, it works just fine. For slow work, it might not be enough.
Most cases don't think they need to avoid reentrance. They might even be
right. I've been bitten by it a number of times.
> > - slow_work_enqueue(&object->work);
> > + if (fscache_get_object(object) >= 0)
> > + if (!queue_work(fscache_object_wq, &object->work))
> > + fscache_put_object(object);
> >
> > One of the reasons I _don't_ want to use the old workqueue facility is that
> > it doesn't manage reentrancy. That can end up tying up multiple threads
> > for one long-duration work item.
>
> Yeap, it's a drawback of the workqueue API although I don't think it
> would be big enough to warrant a completely separate workpool
> mechanism. It's usually enough to implement synchronization from the
> callback or guarantee that running works don't get queued some other
> way. What would happen if fscache object works are reentered? Would
> there be correctness issues?
Definitely. In the last rewrite, I started off by writing a thread pool that
was non-reentrant, and then built everything on top of that assumption. This
means I don't have to do a whole bunch of locking because I _know_ each object
can only be under execution by one thread at any one time.
> How likely are they to get scheduled while being executed?
Reasonably likely, and the events aren't entirely within the control of the
local system.
> If this is something critical, I have a draft implementation which avoids
> reentrance.
If you can provide it, I can simplify RxRPC and AFS too. Those suffer from
reentrancy issues too that I'd dearly like to avoid, but workqueues don't.
> I was gonna apply it for all works but it would cause too much cross CPU
> access when the wq users can already handle reentrance but it can be
> implemented as optional behavior along with SINGLE_CPU.
How many of them actually *handle* it? For some of them it won't matter
because they're only scheduled once, but I bet that some of them it *is* an
issue that no one has considered, and the window of opportunity is small enough
that it's not happened or the has not been reported or successfully pinpointed.
> > Note that it would still be useful to know whether an object was queued for
> > work or being executed.
>
> Adding wouldn't be difficult but would it justify having a dedicated
> function for that in workqueue where fscache would be the only user?
> Also please note that such information is only useful for debugging or
> as hints due to lack of synchronization.
Agreed, but debugging still has to be done sometimes. Of course, it's much
easier for slow-work, since it has to manage reentrancy anyway, and so keeps
hold of the object till afterwards.
Oh, btw, I've run up your patches with FS-Cache. They quickly create a couple
of hundred threads. Is that right? To be fair, the threads do go away again
after a period of quiscence.
David
next prev parent reply other threads:[~2010-02-15 15:11 UTC|newest]
Thread overview: 102+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-18 0:57 [PATCHSET] concurrency managed workqueue, take#3 Tejun Heo
2010-01-18 0:57 ` [PATCH 01/40] sched: consult online mask instead of active in select_fallback_rq() Tejun Heo
2010-01-18 10:13 ` Peter Zijlstra
2010-01-18 11:26 ` Tejun Heo
2010-01-18 0:57 ` [PATCH 02/40] sched: rename preempt_notifiers to sched_notifiers and refactor implementation Tejun Heo
2010-01-18 0:57 ` [PATCH 03/40] sched: refactor try_to_wake_up() Tejun Heo
2010-01-18 0:57 ` [PATCH 04/40] sched: implement __set_cpus_allowed() Tejun Heo
2010-01-18 9:56 ` Peter Zijlstra
2010-01-18 11:22 ` Tejun Heo
2010-01-18 11:41 ` Peter Zijlstra
2010-01-19 1:07 ` Tejun Heo
2010-01-19 8:37 ` Peter Zijlstra
2010-01-20 8:35 ` Tejun Heo
2010-01-20 8:50 ` Peter Zijlstra
2010-01-20 9:00 ` Tejun Heo
2010-01-20 8:59 ` Peter Zijlstra
2010-01-24 8:18 ` Tejun Heo
2010-01-18 0:57 ` [PATCH 05/40] sched: make sched_notifiers unconditional Tejun Heo
2010-01-18 0:57 ` [PATCH 06/40] sched: add wakeup/sleep sched_notifiers and allow NULL notifier ops Tejun Heo
2010-01-18 9:57 ` Peter Zijlstra
2010-01-18 11:31 ` Tejun Heo
2010-01-18 12:49 ` Peter Zijlstra
2010-01-19 1:04 ` Tejun Heo
2010-01-19 8:28 ` Tejun Heo
2010-01-19 8:55 ` Peter Zijlstra
2010-01-20 8:47 ` Tejun Heo
2010-01-18 0:57 ` [PATCH 07/40] sched: implement try_to_wake_up_local() Tejun Heo
2010-01-18 0:57 ` [PATCH 08/40] acpi: use queue_work_on() instead of binding workqueue worker to cpu0 Tejun Heo
2010-01-18 0:57 ` [PATCH 09/40] stop_machine: reimplement without using workqueue Tejun Heo
2010-01-18 0:57 ` [PATCH 10/40] workqueue: misc/cosmetic updates Tejun Heo
2010-01-18 0:57 ` [PATCH 11/40] workqueue: merge feature parameters into flags Tejun Heo
2010-01-18 0:57 ` [PATCH 12/40] workqueue: define both bit position and mask for work flags Tejun Heo
2010-01-18 0:57 ` [PATCH 13/40] workqueue: separate out process_one_work() Tejun Heo
2010-01-18 0:57 ` [PATCH 14/40] workqueue: temporarily disable workqueue tracing Tejun Heo
2010-01-18 0:57 ` [PATCH 15/40] workqueue: kill cpu_populated_map Tejun Heo
2010-01-18 0:57 ` [PATCH 16/40] workqueue: update cwq alignement Tejun Heo
2010-01-18 0:57 ` [PATCH 17/40] workqueue: reimplement workqueue flushing using color coded works Tejun Heo
2010-01-18 0:57 ` [PATCH 18/40] workqueue: introduce worker Tejun Heo
2010-01-18 0:57 ` [PATCH 19/40] workqueue: reimplement work flushing using linked works Tejun Heo
2010-01-18 0:57 ` [PATCH 20/40] workqueue: implement per-cwq active work limit Tejun Heo
2010-01-18 0:57 ` [PATCH 21/40] workqueue: reimplement workqueue freeze using max_active Tejun Heo
2010-01-18 0:57 ` [PATCH 22/40] workqueue: introduce global cwq and unify cwq locks Tejun Heo
2010-01-18 0:57 ` [PATCH 23/40] workqueue: implement worker states Tejun Heo
2010-01-18 0:57 ` [PATCH 24/40] workqueue: reimplement CPU hotplugging support using trustee Tejun Heo
2010-01-18 0:57 ` [PATCH 25/40] workqueue: make single thread workqueue shared worker pool friendly Tejun Heo
2010-01-18 0:57 ` [PATCH 26/40] workqueue: use shared worklist and pool all workers per cpu Tejun Heo
2010-01-18 0:57 ` [PATCH 27/40] workqueue: implement concurrency managed dynamic worker pool Tejun Heo
2010-01-18 0:57 ` [PATCH 28/40] workqueue: increase max_active of keventd and kill current_is_keventd() Tejun Heo
2010-01-18 0:57 ` [PATCH 29/40] workqueue: add system_wq and system_single_wq Tejun Heo
2010-01-18 0:57 ` [PATCH 30/40] workqueue: implement work_busy() Tejun Heo
2010-01-18 2:52 ` Andy Walls
2010-01-18 5:41 ` Tejun Heo
2010-01-18 0:57 ` [PATCH 31/40] libata: take advantage of cmwq and remove concurrency limitations Tejun Heo
2010-01-18 15:48 ` Stefan Richter
2010-01-19 0:49 ` Tejun Heo
2010-01-18 0:57 ` [PATCH 32/40] async: introduce workqueue based alternative implementation Tejun Heo
2010-01-18 6:01 ` Arjan van de Ven
2010-01-18 8:49 ` Tejun Heo
2010-01-18 15:25 ` Arjan van de Ven
2010-01-19 0:57 ` Tejun Heo
2010-01-19 0:57 ` Arjan van de Ven
2010-01-19 7:56 ` Tejun Heo
2010-01-19 14:37 ` Arjan van de Ven
2010-01-20 0:19 ` Tejun Heo
2010-01-20 0:31 ` Arjan van de Ven
2010-01-20 2:08 ` Tejun Heo
2010-01-20 6:03 ` Arjan van de Ven
2010-01-20 8:24 ` Tejun Heo
2010-01-22 10:59 ` [PATCH] async: use workqueue for worker pool Tejun Heo
2010-01-18 0:57 ` [PATCH 33/40] async: convert async users to use the new implementation Tejun Heo
2010-01-18 0:57 ` [PATCH 34/40] async: kill original implementation Tejun Heo
2010-01-18 0:57 ` [PATCH 35/40] fscache: convert object to use workqueue instead of slow-work Tejun Heo
2010-02-12 18:03 ` David Howells
2010-02-13 5:43 ` Tejun Heo
2010-02-15 15:04 ` David Howells [this message]
2010-02-16 3:40 ` Tejun Heo
2010-02-16 3:59 ` Tejun Heo
2010-02-16 18:05 ` David Howells
2010-02-16 23:50 ` Tejun Heo
2010-02-18 11:50 ` David Howells
2010-02-18 12:33 ` Tejun Heo
2010-01-18 0:57 ` [PATCH 36/40] fscache: convert operation " Tejun Heo
2010-01-18 0:57 ` [PATCH 37/40] fscache: drop references to slow-work Tejun Heo
2010-01-18 0:57 ` [PATCH 38/40] cifs: use workqueue instead of slow-work Tejun Heo
2010-01-19 12:20 ` Jeff Layton
2010-01-20 0:15 ` Tejun Heo
2010-01-20 0:56 ` Jeff Layton
2010-01-20 1:23 ` Tejun Heo
2010-01-22 11:14 ` [PATCH UPDATED " Tejun Heo
2010-01-22 11:45 ` Jeff Layton
2010-01-24 8:25 ` Tejun Heo
2010-01-24 12:13 ` Jeff Layton
2010-01-25 15:25 ` Tejun Heo
2010-01-18 0:57 ` [PATCH 39/40] gfs2: " Tejun Heo
2010-01-18 9:45 ` Steven Whitehouse
2010-01-18 11:24 ` Tejun Heo
2010-01-18 12:07 ` Steven Whitehouse
2010-01-19 1:00 ` Tejun Heo
2010-01-19 8:46 ` [PATCH UPDATED " Tejun Heo
2010-01-18 0:57 ` [PATCH 40/40] slow-work: kill it Tejun Heo
2010-01-18 1:03 ` perf-wq.c used to generate synthetic workload Tejun Heo
2010-01-18 16:13 ` [PATCHSET] concurrency managed workqueue, take#3 Stefan Richter
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=27102.1266246296@redhat.com \
--to=dhowells@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=arjan@linux.intel.com \
--cc=avi@redhat.com \
--cc=awalls@radix.net \
--cc=cl@linux-foundation.org \
--cc=jeff@garzik.org \
--cc=jens.axboe@oracle.com \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rusty@rustcorp.com.au \
--cc=tj@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.