linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: viro@ZenIV.linux.org.uk
Cc: dhowells@redhat.com, nfsv4@linux-nfs.org,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 03/43] Make the slow work pool configurable [ver #46]
Date: Thu, 02 Apr 2009 00:03:37 +0100	[thread overview]
Message-ID: <20090401230337.28177.81683.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20090401230321.28177.12010.stgit@warthog.procyon.org.uk>

Make the slow work pool configurable through /proc/sys/kernel/slow-work.

 (*) /proc/sys/kernel/slow-work/min-threads

     The minimum number of threads that should be in the pool as long as 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.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Acked-by: Steve Dickson <steved@redhat.com>
Acked-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---

 include/linux/slow-work.h |    5 ++
 kernel/slow-work.c        |  118 ++++++++++++++++++++++++++++++++++++++++++++-
 kernel/sysctl.c           |    9 +++
 3 files changed, 130 insertions(+), 2 deletions(-)


diff --git a/include/linux/slow-work.h b/include/linux/slow-work.h
index 4dd754a..8262809 100644
--- a/include/linux/slow-work.h
+++ b/include/linux/slow-work.h
@@ -14,6 +14,8 @@
 
 #ifdef CONFIG_SLOW_WORK
 
+#include <linux/sysctl.h>
+
 struct slow_work;
 
 /*
@@ -83,6 +85,9 @@ extern int slow_work_enqueue(struct slow_work *work);
 extern int slow_work_register_user(void);
 extern void slow_work_unregister_user(void);
 
+#ifdef CONFIG_SYSCTL
+extern ctl_table slow_work_sysctls[];
+#endif
 
 #endif /* CONFIG_SLOW_WORK */
 #endif /* _LINUX_SLOW_WORK_H */
diff --git a/kernel/slow-work.c b/kernel/slow-work.c
index 454abb2..3f65900 100644
--- a/kernel/slow-work.c
+++ b/kernel/slow-work.c
@@ -14,7 +14,6 @@
 #include <linux/kthread.h>
 #include <linux/freezer.h>
 #include <linux/wait.h>
-#include <asm/system.h>
 
 #define SLOW_WORK_CULL_TIMEOUT (5 * HZ)	/* cull threads 5s after running out of
 					 * things to do */
@@ -24,6 +23,14 @@
 static void slow_work_cull_timeout(unsigned long);
 static void slow_work_oom_timeout(unsigned long);
 
+#ifdef CONFIG_SYSCTL
+static int slow_work_min_threads_sysctl(struct ctl_table *, int, struct file *,
+					void __user *, size_t *, loff_t *);
+
+static int slow_work_max_threads_sysctl(struct ctl_table *, int , struct file *,
+					void __user *, size_t *, loff_t *);
+#endif
+
 /*
  * The pool of threads has at least min threads in it as long as someone is
  * using the facility, and may have as many as max.
@@ -34,6 +41,51 @@ static unsigned slow_work_min_threads = 2;
 static unsigned slow_work_max_threads = 4;
 static unsigned vslow_work_proportion = 50; /* % of threads that may process
 					     * very slow work */
+
+#ifdef CONFIG_SYSCTL
+static const int slow_work_min_min_threads = 2;
+static int slow_work_max_max_threads = 255;
+static const int slow_work_min_vslow = 1;
+static const int slow_work_max_vslow = 99;
+
+ctl_table slow_work_sysctls[] = {
+	{
+		.ctl_name	= CTL_UNNUMBERED,
+		.procname	= "min-threads",
+		.data		= &slow_work_min_threads,
+		.maxlen		= sizeof(unsigned),
+		.mode		= 0644,
+		.proc_handler	= slow_work_min_threads_sysctl,
+		.extra1		= (void *) &slow_work_min_min_threads,
+		.extra2		= &slow_work_max_threads,
+	},
+	{
+		.ctl_name	= CTL_UNNUMBERED,
+		.procname	= "max-threads",
+		.data		= &slow_work_max_threads,
+		.maxlen		= sizeof(unsigned),
+		.mode		= 0644,
+		.proc_handler	= slow_work_max_threads_sysctl,
+		.extra1		= &slow_work_min_threads,
+		.extra2		= (void *) &slow_work_max_max_threads,
+	},
+	{
+		.ctl_name	= CTL_UNNUMBERED,
+		.procname	= "vslow-percentage",
+		.data		= &vslow_work_proportion,
+		.maxlen		= sizeof(unsigned),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec_minmax,
+		.extra1		= (void *) &slow_work_min_vslow,
+		.extra2		= (void *) &slow_work_max_vslow,
+	},
+	{ .ctl_name = 0 }
+};
+#endif
+
+/*
+ * The active state of the thread pool
+ */
 static atomic_t slow_work_thread_count;
 static atomic_t vslow_work_executing_count;
 
@@ -427,6 +479,64 @@ static void slow_work_oom_timeout(unsigned long data)
 	slow_work_may_not_start_new_thread = false;
 }
 
+#ifdef CONFIG_SYSCTL
+/*
+ * Handle adjustment of the minimum number of threads
+ */
+static int slow_work_min_threads_sysctl(struct ctl_table *table, int write,
+					struct file *filp, void __user *buffer,
+					size_t *lenp, loff_t *ppos)
+{
+	int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos);
+	int n;
+
+	if (ret == 0) {
+		mutex_lock(&slow_work_user_lock);
+		if (slow_work_user_count > 0) {
+			/* see if we need to start or stop threads */
+			n = atomic_read(&slow_work_thread_count) -
+				slow_work_min_threads;
+
+			if (n < 0 && !slow_work_may_not_start_new_thread)
+				slow_work_enqueue(&slow_work_new_thread);
+			else if (n > 0)
+				mod_timer(&slow_work_cull_timer,
+					  jiffies + SLOW_WORK_CULL_TIMEOUT);
+		}
+		mutex_unlock(&slow_work_user_lock);
+	}
+
+	return ret;
+}
+
+/*
+ * Handle adjustment of the maximum number of threads
+ */
+static int slow_work_max_threads_sysctl(struct ctl_table *table, int write,
+					struct file *filp, void __user *buffer,
+					size_t *lenp, loff_t *ppos)
+{
+	int ret = proc_dointvec_minmax(table, write, filp, buffer, lenp, ppos);
+	int n;
+
+	if (ret == 0) {
+		mutex_lock(&slow_work_user_lock);
+		if (slow_work_user_count > 0) {
+			/* see if we need to stop threads */
+			n = slow_work_max_threads -
+				atomic_read(&slow_work_thread_count);
+
+			if (n < 0)
+				mod_timer(&slow_work_cull_timer,
+					  jiffies + SLOW_WORK_CULL_TIMEOUT);
+		}
+		mutex_unlock(&slow_work_user_lock);
+	}
+
+	return ret;
+}
+#endif /* CONFIG_SYSCTL */
+
 /**
  * slow_work_register_user - Register a user of the facility
  *
@@ -516,8 +626,12 @@ static int __init init_slow_work(void)
 {
 	unsigned nr_cpus = num_possible_cpus();
 
-	if (nr_cpus > slow_work_max_threads)
+	if (slow_work_max_threads < nr_cpus)
 		slow_work_max_threads = nr_cpus;
+#ifdef CONFIG_SYSCTL
+	if (slow_work_max_max_threads < nr_cpus * 2)
+		slow_work_max_max_threads = nr_cpus * 2;
+#endif
 	return 0;
 }
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 2e490a3..8a9b696 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -48,6 +48,7 @@
 #include <linux/acpi.h>
 #include <linux/reboot.h>
 #include <linux/ftrace.h>
+#include <linux/slow-work.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -900,6 +901,14 @@ static struct ctl_table kern_table[] = {
 		.proc_handler	= &scan_unevictable_handler,
 	},
 #endif
+#ifdef CONFIG_SLOW_WORK
+	{
+		.ctl_name	= CTL_UNNUMBERED,
+		.procname	= "slow-work",
+		.mode		= 0555,
+		.child		= slow_work_sysctls,
+	},
+#endif
 /*
  * NOTE: do not add new entries to this table unless you have read
  * Documentation/sysctl/ctl_unnumbered.txt


  parent reply	other threads:[~2009-04-01 23:03 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-01 23:03 [PATCH 00/43] Permit filesystem local caching [ver #46] David Howells
2009-04-01 23:03 ` [PATCH 01/43] Create a dynamically sized pool of threads for doing very slow work items " David Howells
2009-04-01 23:03 ` [PATCH 02/43] Make slow-work thread pool actually dynamic " David Howells
2009-04-01 23:03 ` David Howells [this message]
2009-04-01 23:03 ` [PATCH 04/43] Document the slow work thread pool " David Howells
2009-04-01 23:03 ` [PATCH 05/43] FS-Cache: Release page->private after failed readahead " David Howells
2009-04-02 13:51   ` Nick Piggin
2009-04-02 14:21   ` David Howells
2009-04-02 17:17   ` Rik van Riel
2009-04-01 23:03 ` [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management " David Howells
2009-04-02 13:55   ` Nick Piggin
2009-04-02 14:36   ` David Howells
2009-04-02 15:25     ` Nick Piggin
2009-04-02 15:51     ` David Howells
2009-04-02 16:15       ` Nick Piggin
2009-04-02 16:53         ` Nick Piggin
2009-04-02 17:09         ` David Howells
2009-04-02 17:31           ` Nick Piggin
2009-04-02 17:40           ` David Howells
2009-04-02 18:14             ` Nick Piggin
2009-04-02 19:19             ` Trond Myklebust
2009-04-03  1:11             ` David Howells
2009-04-02 16:48       ` What I mean by a 'netfs' when dealing with FS-Cache David Howells
2009-04-02 17:06       ` David Howells
2009-04-02 18:23   ` [PATCH 06/43] FS-Cache: Recruit a couple of page flags for cache management [ver #46] Rik van Riel
2009-04-01 23:03 ` [PATCH 07/43] FS-Cache: Add the FS-Cache netfs API and documentation " David Howells
2009-04-01 23:04 ` [PATCH 08/43] FS-Cache: Add the FS-Cache cache backend " David Howells
2009-04-01 23:04 ` [PATCH 09/43] FS-Cache: Add main configuration option, module entry points and debugging " David Howells
2009-04-01 23:04 ` [PATCH 10/43] FS-Cache: Add use of /proc and presentation of statistics " David Howells
2009-04-01 23:04 ` [PATCH 11/43] FS-Cache: Root index definition " David Howells
2009-04-01 23:04 ` [PATCH 12/43] FS-Cache: Add cache tag handling " David Howells
2009-04-01 23:04 ` [PATCH 13/43] FS-Cache: Add cache management " David Howells
2009-04-01 23:04 ` [PATCH 14/43] FS-Cache: Provide a slab for cookie allocation " David Howells
2009-04-01 23:04 ` [PATCH 15/43] FS-Cache: Add netfs registration " David Howells
2009-04-01 23:04 ` [PATCH 16/43] FS-Cache: Bit waiting helpers " David Howells
2009-04-01 23:04 ` [PATCH 17/43] FS-Cache: Object management state machine " David Howells
2009-04-01 23:04 ` [PATCH 18/43] FS-Cache: Implement the cookie management part of the netfs API " David Howells
2009-04-01 23:04 ` [PATCH 19/43] FS-Cache: Add and document asynchronous operation handling " David Howells
2009-04-01 23:05 ` [PATCH 20/43] FS-Cache: Implement data I/O part of netfs API " David Howells
2009-04-01 23:05 ` [PATCH 21/43] CacheFiles: Be consistent about the use of mapping vs file->f_mapping in Ext3 " David Howells
2009-04-02 18:52   ` Rik van Riel
2009-04-01 23:05 ` [PATCH 22/43] CacheFiles: Add a hook to write a single page of data to an inode " David Howells
2009-04-02 14:00   ` Nick Piggin
2009-04-02 14:55   ` David Howells
2009-04-02 15:32     ` Nick Piggin
2009-04-02 16:37       ` Christoph Hellwig
2009-04-02 16:47         ` Nick Piggin
2009-04-02 16:55           ` Christoph Hellwig
2009-04-02 17:07             ` Nick Piggin
2009-04-02 17:26               ` Jan Kara
2009-04-02 17:22           ` David Howells
2009-04-02 18:18           ` David Howells
2009-04-02 22:44           ` David Howells
2009-04-03 13:41           ` David Howells
2009-04-02 16:02     ` David Howells
2009-04-02 15:32   ` Peter Staubach
2009-04-02 16:03   ` David Howells
2009-04-02 18:48   ` Rik van Riel
2009-04-01 23:05 ` [PATCH 23/43] CacheFiles: Permit the page lock state to be monitored " David Howells
2009-04-02 15:37   ` Nick Piggin
2009-04-02 16:14   ` David Howells
2009-04-02 16:35     ` Nick Piggin
2009-04-02 17:05     ` David Howells
2009-04-02 18:03       ` Nick Piggin
2009-04-02 18:51   ` Rik van Riel
2009-04-01 23:05 ` [PATCH 24/43] CacheFiles: Export things for CacheFiles " David Howells
2009-04-02 18:53   ` Rik van Riel
2009-04-01 23:05 ` [PATCH 25/43] CacheFiles: A cache that backs onto a mounted filesystem " David Howells
2009-04-01 23:05 ` [PATCH 26/43] FS-Cache: Make kAFS use FS-Cache " David Howells
2009-04-01 23:05 ` [PATCH 27/43] NFS: Add comment banners to some NFS functions " David Howells
2009-04-01 23:05 ` [PATCH 28/43] NFS: Add FS-Cache option bit and debug bit " David Howells
2009-04-01 23:05 ` [PATCH 29/43] NFS: Permit local filesystem caching to be enabled for NFS " David Howells
2009-04-01 23:05 ` [PATCH 30/43] NFS: Register NFS for caching and retrieve the top-level index " David Howells
2009-04-01 23:06 ` [PATCH 31/43] NFS: Define and create server-level objects " David Howells
2009-04-01 23:06 ` [PATCH 32/43] NFS: Define and create superblock-level " David Howells
2009-04-01 23:06 ` [PATCH 33/43] NFS: Define and create inode-level cache " David Howells
2009-04-01 23:06 ` [PATCH 34/43] NFS: Use local disk inode cache " David Howells
2009-04-01 23:06 ` [PATCH 35/43] NFS: Invalidate FsCache page flags when cache removed " David Howells
2009-04-01 23:06 ` [PATCH 36/43] NFS: Add some new I/O counters for FS-Cache doing things for NFS " David Howells
2009-04-01 23:06 ` [PATCH 37/43] NFS: FS-Cache page management " David Howells
2009-04-01 23:06 ` [PATCH 38/43] NFS: Add read context retention for FS-Cache to call back with " David Howells
2009-04-01 23:06 ` [PATCH 39/43] NFS: nfs_readpage_async() needs to be accessible as a fallback for local caching " David Howells
2009-04-01 23:06 ` [PATCH 40/43] NFS: Read pages from FS-Cache into an NFS inode " David Howells
2009-04-01 23:06 ` [PATCH 41/43] NFS: Store pages from an NFS inode into a local cache " David Howells
2009-04-01 23:06 ` [PATCH 42/43] NFS: Display local caching state " David Howells
2009-04-01 23:07 ` [PATCH 43/43] 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=20090401230337.28177.81683.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 \
    --cc=viro@ZenIV.linux.org.uk \
    /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).