From: David Howells <dhowells@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, nfsv4@linux-nfs.org
Subject: [PATCH 04/41] Document the slow work thread pool [ver #48]
Date: Fri, 03 Apr 2009 16:54:57 +0100 [thread overview]
Message-ID: <20090403155457.28714.45072.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20090403155436.28714.23368.stgit@warthog.procyon.org.uk>
Document the slow work thread pool.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Steve Dickson <steved@redhat.com>
Acked-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Tested-by: Daire Byrne <Daire.Byrne@framestore.com>
---
Documentation/slow-work.txt | 174 +++++++++++++++++++++++++++++++++++++++++++
include/linux/slow-work.h | 2
kernel/slow-work.c | 2
3 files changed, 178 insertions(+), 0 deletions(-)
create mode 100644 Documentation/slow-work.txt
diff --git a/Documentation/slow-work.txt b/Documentation/slow-work.txt
new file mode 100644
index 0000000..ebc50f8
--- /dev/null
+++ b/Documentation/slow-work.txt
@@ -0,0 +1,174 @@
+ ====================================
+ SLOW WORK ITEM EXECUTION THREAD POOL
+ ====================================
+
+By: David Howells <dhowells@redhat.com>
+
+The slow work item execution thread pool is a pool of threads for performing
+things that take a relatively long time, such as making mkdir calls.
+Typically, when processing something, these items will spend a lot of time
+blocking a thread on I/O, thus making that thread unavailable for doing other
+work.
+
+The standard workqueue model is unsuitable for this class of work item as that
+limits the owner to a single thread or a single thread per CPU. For some
+tasks, however, more threads - or fewer - are required.
+
+There is just one pool per system. It contains no threads unless something
+wants to use it - and that something must register its interest first. When
+the pool is active, the number of threads it contains is dynamic, varying
+between a maximum and minimum setting, depending on the load.
+
+
+====================
+CLASSES OF WORK ITEM
+====================
+
+This pool support two classes of work items:
+
+ (*) Slow work items.
+
+ (*) Very slow work items.
+
+The former are expected to finish much quicker than the latter.
+
+An operation of the very slow class may do a batch combination of several
+lookups, mkdirs, and a create for instance.
+
+An operation of the ordinarily slow class may, for example, write stuff or
+expand files, provided the time taken to do so isn't too long.
+
+Operations of both types may sleep during execution, thus tying up the thread
+loaned to it.
+
+
+THREAD-TO-CLASS ALLOCATION
+--------------------------
+
+Not all the threads in the pool are available to work on very slow work items.
+The number will be between one and one fewer than the number of active threads.
+This is configurable (see the "Pool Configuration" section).
+
+All the threads are available to work on ordinarily slow work items, but a
+percentage of the threads will prefer to work on very slow work items.
+
+The configuration ensures that at least one thread will be available to work on
+very slow work items, and at least one thread will be available that won't work
+on very slow work items at all.
+
+
+=====================
+USING SLOW WORK ITEMS
+=====================
+
+Firstly, a module or subsystem wanting to make use of slow work items must
+register its interest:
+
+ int ret = slow_work_register_user();
+
+This will return 0 if successful, or a -ve error upon failure.
+
+
+Slow work items may then be set up by:
+
+ (1) Declaring a slow_work struct type variable:
+
+ #include <linux/slow-work.h>
+
+ struct slow_work myitem;
+
+ (2) Declaring the operations to be used for this item:
+
+ struct slow_work_ops myitem_ops = {
+ .get_ref = myitem_get_ref,
+ .put_ref = myitem_put_ref,
+ .execute = myitem_execute,
+ };
+
+ [*] For a description of the ops, see section "Item Operations".
+
+ (3) Initialising the item:
+
+ slow_work_init(&myitem, &myitem_ops);
+
+ or:
+
+ vslow_work_init(&myitem, &myitem_ops);
+
+ depending on its class.
+
+A suitably set up work item can then be enqueued for processing:
+
+ int ret = slow_work_enqueue(&myitem);
+
+This will return a -ve error if the thread pool is unable to gain a reference
+on the item, 0 otherwise.
+
+
+The items are reference counted, so there ought to be no need for a flush
+operation. When all a module's slow work items have been processed, and the
+module has no further interest in the facility, it should unregister its
+interest:
+
+ slow_work_unregister_user();
+
+
+===============
+ITEM OPERATIONS
+===============
+
+Each work item requires a table of operations of type struct slow_work_ops.
+All members are required:
+
+ (*) Get a reference on an item:
+
+ int (*get_ref)(struct slow_work *work);
+
+ This allows the thread pool to attempt to pin an item by getting a
+ reference on it. This function should return 0 if the reference was
+ granted, or a -ve error otherwise. If an error is returned,
+ slow_work_enqueue() will fail.
+
+ The reference is held whilst the item is queued and whilst it is being
+ executed. The item may then be requeued with the same reference held, or
+ the reference will be released.
+
+ (*) Release a reference on an item:
+
+ void (*put_ref)(struct slow_work *work);
+
+ This allows the thread pool to unpin an item by releasing the reference on
+ it. The thread pool will not touch the item again once this has been
+ called.
+
+ (*) Execute an item:
+
+ void (*execute)(struct slow_work *work);
+
+ This should perform the work required of the item. It may sleep, it may
+ perform disk I/O and it may wait for locks.
+
+
+==================
+POOL CONFIGURATION
+==================
+
+The slow-work thread pool has a number of configurables:
+
+ (*) /proc/sys/kernel/slow-work/min-threads
+
+ The minimum number of threads that should be in the pool whilst it is in
+ use. This may be anywhere between 2 and max-threads.
+
+ (*) /proc/sys/kernel/slow-work/max-threads
+
+ The maximum number of threads that should in the pool. This may be
+ anywhere between min-threads and 255 or NR_CPUS * 2, whichever is greater.
+
+ (*) /proc/sys/kernel/slow-work/vslow-percentage
+
+ The percentage of active threads in the pool that may be used to execute
+ very slow work items. This may be between 1 and 99. The resultant number
+ is bounded to between 1 and one fewer than the number of active threads.
+ This ensures there is always at least one thread that can process very
+ slow work items, and always at least one thread that won't.
diff --git a/include/linux/slow-work.h b/include/linux/slow-work.h
index 8262809..8595827 100644
--- a/include/linux/slow-work.h
+++ b/include/linux/slow-work.h
@@ -7,6 +7,8 @@
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version
* 2 of the Licence, or (at your option) any later version.
+ *
+ * See Documentation/slow-work.txt
*/
#ifndef _LINUX_SLOW_WORK_H
diff --git a/kernel/slow-work.c b/kernel/slow-work.c
index 3f65900..cf2bc01 100644
--- a/kernel/slow-work.c
+++ b/kernel/slow-work.c
@@ -7,6 +7,8 @@
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version
* 2 of the Licence, or (at your option) any later version.
+ *
+ * See Documentation/slow-work.txt
*/
#include <linux/module.h>
next prev parent reply other threads:[~2009-04-03 15:54 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-03 15:54 [PATCH 00/41] Permit filesystem local caching [ver #48] David Howells
2009-04-03 15:54 ` [PATCH 01/41] Create a dynamically sized pool of threads for doing very slow work items " David Howells
2009-04-03 15:54 ` [PATCH 02/41] Make slow-work thread pool actually dynamic " David Howells
2009-04-03 15:54 ` [PATCH 03/41] Make the slow work pool configurable " David Howells
2009-04-03 15:54 ` David Howells [this message]
2009-04-03 15:55 ` [PATCH 05/41] FS-Cache: Release page->private after failed readahead " David Howells
2009-04-04 6:00 ` Nick Piggin
2009-04-03 15:55 ` [PATCH 06/41] FS-Cache: Recruit a page flags for cache management " David Howells
2009-04-04 6:04 ` Nick Piggin
2009-04-03 15:55 ` [PATCH 07/41] FS-Cache: Add the FS-Cache netfs API and documentation " David Howells
2009-04-03 15:55 ` [PATCH 08/41] FS-Cache: Add the FS-Cache cache backend " David Howells
2009-04-03 15:55 ` [PATCH 09/41] FS-Cache: Add main configuration option, module entry points and debugging " David Howells
2009-04-03 15:55 ` [PATCH 10/41] FS-Cache: Add use of /proc and presentation of statistics " David Howells
2009-04-04 17:39 ` Christoph Hellwig
2009-04-03 15:55 ` [PATCH 11/41] FS-Cache: Root index definition " David Howells
2009-04-03 15:55 ` [PATCH 12/41] FS-Cache: Add cache tag handling " David Howells
2009-04-03 15:55 ` [PATCH 13/41] FS-Cache: Add cache management " David Howells
2009-04-03 15:55 ` [PATCH 14/41] FS-Cache: Provide a slab for cookie allocation " David Howells
2009-04-03 15:55 ` [PATCH 15/41] FS-Cache: Add netfs registration " David Howells
2009-04-03 15:55 ` [PATCH 16/41] FS-Cache: Bit waiting helpers " David Howells
2009-04-03 15:56 ` [PATCH 17/41] FS-Cache: Object management state machine " David Howells
2009-04-03 15:56 ` [PATCH 18/41] FS-Cache: Implement the cookie management part of the netfs API " David Howells
2009-04-03 15:56 ` [PATCH 19/41] FS-Cache: Add and document asynchronous operation handling " David Howells
2009-04-03 15:56 ` [PATCH 20/41] FS-Cache: Implement data I/O part of netfs API " David Howells
2009-04-03 15:56 ` [PATCH 21/41] CacheFiles: Permit the page lock state to be monitored " David Howells
2009-04-04 6:09 ` Nick Piggin
2009-04-04 14:22 ` Nick Piggin
2009-04-04 22:13 ` David Howells
2009-04-06 8:31 ` Nick Piggin
2009-04-04 11:31 ` David Howells
2009-04-06 9:34 ` Nick Piggin
2009-04-03 15:56 ` [PATCH 22/41] CacheFiles: Export things for CacheFiles " David Howells
2009-04-03 15:56 ` [PATCH 23/41] CacheFiles: A cache that backs onto a mounted filesystem " David Howells
2009-04-03 15:56 ` [PATCH 24/41] FS-Cache: Make kAFS use FS-Cache " David Howells
2009-04-03 15:56 ` [PATCH 25/41] NFS: Add comment banners to some NFS functions " David Howells
2009-04-03 15:56 ` [PATCH 26/41] NFS: Add FS-Cache option bit and debug bit " David Howells
2009-04-03 15:56 ` [PATCH 27/41] NFS: Permit local filesystem caching to be enabled for NFS " David Howells
2009-04-03 15:57 ` [PATCH 28/41] NFS: Register NFS for caching and retrieve the top-level index " David Howells
2009-04-03 15:57 ` [PATCH 29/41] NFS: Define and create server-level objects " David Howells
2009-04-03 15:57 ` [PATCH 30/41] NFS: Define and create superblock-level " David Howells
2009-04-03 15:57 ` [PATCH 31/41] NFS: Define and create inode-level cache " David Howells
2009-04-03 15:57 ` [PATCH 32/41] NFS: Use local disk inode cache " David Howells
2009-04-03 15:57 ` [PATCH 33/41] NFS: Invalidate FsCache page flags when cache removed " David Howells
2009-04-03 15:57 ` [PATCH 34/41] NFS: Add some new I/O counters for FS-Cache doing things for NFS " David Howells
2009-04-03 15:57 ` [PATCH 35/41] NFS: FS-Cache page management " David Howells
2009-04-03 15:57 ` [PATCH 36/41] NFS: Add read context retention for FS-Cache to call back with " David Howells
2009-04-03 15:57 ` [PATCH 37/41] NFS: nfs_readpage_async() needs to be accessible as a fallback for local caching " David Howells
2009-04-03 15:57 ` [PATCH 38/41] NFS: Read pages from FS-Cache into an NFS inode " David Howells
2009-04-03 15:57 ` [PATCH 39/41] NFS: Store pages from an NFS inode into a local cache " David Howells
2009-04-03 15:58 ` [PATCH 40/41] NFS: Display local caching state " David Howells
2009-04-03 15:58 ` [PATCH 41/41] NFS: Add mount options to enable local caching on NFS " David Howells
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=20090403155457.28714.45072.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nfsv4@linux-nfs.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).