linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] Give kjournald a IOPRIO_CLASS_RT io priority
@ 2007-10-15 17:46 Arjan van de Ven
  2007-10-15 18:47 ` Andrew Morton
  0 siblings, 1 reply; 76+ messages in thread
From: Arjan van de Ven @ 2007-10-15 17:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, jens.axboe, mingo


Subject: Give kjournald a IOPRIO_CLASS_RT io priority
From: Arjan van de Ven <arjan@linux.intel.com>

With latencytop, I noticed that the (in memory) atime updates during a
kernel build had latencies of 600 msec or longer; this is obviously not so
nice behavior. Other EXT3 journal related operations had similar or even
longer latencies.

Digging into this a bit more, it appears to be an interaction between EXT3
and CFQ in that CFQ tries to be fair to everyone, including kjournald.
However, in reality, kjournald is "special" in that it does a lot of journal
work and effectively this leads to a twisted kind of "mass priority
inversion" type of behavior.

The good news is that CFQ already has the infrastructure to make certain
processes special... JBD just wasn't using that quite yet.

The patch below makes kjournald of the IOPRIO_CLASS_RT priority to break
this priority inversion behavior. With this patch, the latencies for atime
updates (and similar operation) go down by a factor of 3x to 4x !


Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>


diff -purN linux-2.6.23-rc9.org/fs/jbd/journal.c linux-2.6.23-rc9.lt/fs/jbd/journal.c
--- linux-2.6.23-rc9.org/fs/jbd/journal.c	2007-10-02 05:24:52.000000000 +0200
+++ linux-2.6.23-rc9.lt/fs/jbd/journal.c	2007-10-14 00:06:55.000000000 +0200
@@ -35,6 +35,7 @@
 #include <linux/kthread.h>
 #include <linux/poison.h>
 #include <linux/proc_fs.h>
+#include <linux/ioprio.h>
 
 #include <asm/uaccess.h>
 #include <asm/page.h>
@@ -131,6 +132,8 @@ static int kjournald(void *arg)
 	printk(KERN_INFO "kjournald starting.  Commit interval %ld seconds\n",
 			journal->j_commit_interval / HZ);
 
+	current->ioprio =  (IOPRIO_CLASS_RT << IOPRIO_CLASS_SHIFT) | 4;
+
 	/*
 	 * And now, wait forever for commit wakeup events.
 	 */

^ permalink raw reply	[flat|nested] 76+ messages in thread
* [PATCH] Give kjournald a IOPRIO_CLASS_RT io priority
@ 2008-10-02  3:00 Arjan van de Ven
  2008-10-02  4:56 ` Andrew Morton
  0 siblings, 1 reply; 76+ messages in thread
From: Arjan van de Ven @ 2008-10-02  3:00 UTC (permalink / raw)
  To: Jens Axboe, linux-kernel; +Cc: Alan Cox


From: Arjan van de Ven <arjan@linux.intel.com>
Date: Wed, 1 Oct 2008 19:58:18 -0700
Subject: [PATCH] Give kjournald a IOPRIO_CLASS_RT io priority

With latencytop, I noticed that the (in memory) atime updates during a
kernel build had latencies of 6 seconds or longer; this is obviously not so
nice behavior. Other EXT3 journal related operations had similar or even
longer latencies.

Digging into this a bit more, it appears to be an interaction between EXT3
and CFQ in that CFQ tries to be fair to everyone, including kjournald.
However, in reality, kjournald is "special" in that it does a lot of journal
work on behalf of other processes and effectively this leads to a twisted 
kind of "mass priority inversion" type of behavior.

The good news is that CFQ already has the infrastructure to make certain
processes special... JBD just wasn't using that quite yet.

The patch below makes kjournald of the IOPRIO_CLASS_RT priority to break
this priority inversion behavior. With this patch, the latencies for atime
updates (and similar operation) go down by a factor of 3x to 4x !

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 fs/ioprio.c            |    3 ++-
 fs/jbd/journal.c       |   12 ++++++++++++
 include/linux/ioprio.h |    2 ++
 3 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/fs/ioprio.c b/fs/ioprio.c
index da3cc46..3bd95dc 100644
--- a/fs/ioprio.c
+++ b/fs/ioprio.c
@@ -27,7 +27,7 @@
 #include <linux/security.h>
 #include <linux/pid_namespace.h>
 
-static int set_task_ioprio(struct task_struct *task, int ioprio)
+int set_task_ioprio(struct task_struct *task, int ioprio)
 {
 	int err;
 	struct io_context *ioc;
@@ -64,6 +64,7 @@ static int set_task_ioprio(struct task_struct *task, int ioprio)
 	task_unlock(task);
 	return err;
 }
+EXPORT_SYMBOL_GPL(set_task_ioprio);
 
 asmlinkage long sys_ioprio_set(int which, int who, int ioprio)
 {
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
index aa7143a..2ed3d8f 100644
--- a/fs/jbd/journal.c
+++ b/fs/jbd/journal.c
@@ -36,6 +36,7 @@
 #include <linux/poison.h>
 #include <linux/proc_fs.h>
 #include <linux/debugfs.h>
+#include <linux/ioprio.h>
 
 #include <asm/uaccess.h>
 #include <asm/page.h>
@@ -131,6 +132,17 @@ static int kjournald(void *arg)
 			journal->j_commit_interval / HZ);
 
 	/*
+	 * kjournald is the process on which most other processes depend on
+	 * for doing the filesystem portion of their IO. As such, there exists
+	 * the equivalent of a priority inversion situation, where kjournald
+	 * would get less priority as it should.
+	 *
+	 * For this reason we set to "medium real time priority", which is higher
+	 * than regular tasks, but not infinitely powerful.
+	 */
+	set_task_ioprio(current, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_RT, 4));
+
+	/*
 	 * And now, wait forever for commit wakeup events.
 	 */
 	spin_lock(&journal->j_state_lock);
diff --git a/include/linux/ioprio.h b/include/linux/ioprio.h
index f98a656..76dad48 100644
--- a/include/linux/ioprio.h
+++ b/include/linux/ioprio.h
@@ -86,4 +86,6 @@ static inline int task_nice_ioclass(struct task_struct *task)
  */
 extern int ioprio_best(unsigned short aprio, unsigned short bprio);
 
+extern int set_task_ioprio(struct task_struct *task, int ioprio);
+
 #endif
-- 
1.5.5.1



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

^ permalink raw reply related	[flat|nested] 76+ messages in thread
[parent not found: <bimJN-4cO-5@gated-at.bofh.it>]

end of thread, other threads:[~2008-10-09  8:48 UTC | newest]

Thread overview: 76+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-15 17:46 [patch] Give kjournald a IOPRIO_CLASS_RT io priority Arjan van de Ven
2007-10-15 18:47 ` Andrew Morton
2007-10-15 19:28   ` Jens Axboe
2007-10-22  9:10     ` Ingo Molnar
2007-10-22  9:23       ` Andrew Morton
2007-10-22  9:27         ` Ingo Molnar
2007-10-22  9:40         ` Ingo Molnar
2007-10-22  9:49           ` Andrew Morton
2007-10-15 20:13   ` Rik van Riel
2007-10-15 21:12     ` Andrew Morton
     [not found]       ` <473B18BA.5000709@hp.com>
2007-11-14 17:14         ` Andrew Morton
2007-11-14 17:18           ` Ingo Molnar
2007-11-14 17:51             ` Arjan van de Ven
2007-11-14 18:55               ` Ingo Molnar
2007-11-14 19:43               ` Alan D. Brunelle
2007-11-14 19:24           ` Alan D. Brunelle
2007-11-14 19:50             ` Arjan van de Ven
2007-11-14 19:56             ` Alan D. Brunelle
2007-11-16 16:25           ` Alan D. Brunelle
2007-11-16 16:40             ` Alan D. Brunelle
2007-11-16 18:35             ` Ray Lee
2007-11-16 18:39               ` Alan D. Brunelle
  -- strict thread matches above, loose matches on Subject: below --
2008-10-02  3:00 [PATCH] " Arjan van de Ven
2008-10-02  4:56 ` Andrew Morton
2008-10-02  6:27   ` Jens Axboe
2008-10-02  6:55     ` Andrew Morton
2008-10-02  7:45       ` Jens Axboe
2008-10-02  8:03         ` Andrew Morton
2008-10-02  8:22           ` Jens Axboe
2008-10-02  8:43             ` Andrew Morton
2008-10-02  8:46               ` Jens Axboe
2008-10-02 12:04           ` Theodore Tso
2008-10-02 13:16             ` Arjan van de Ven
2008-10-02 13:46               ` Theodore Tso
2008-10-02 14:33                 ` Arjan van de Ven
2008-10-04 14:12                   ` Theodore Tso
2008-10-04 17:14                     ` Joseph Fannin
2008-10-04 21:27                       ` Theodore Tso
2008-10-02 13:12       ` Arjan van de Ven
2008-10-02 20:24         ` Andrew Morton
2008-10-03  4:01           ` Arjan van de Ven
2008-10-03  4:23             ` Arjan van de Ven
2008-10-03  4:40               ` Andrew Morton
2008-10-03  4:43                 ` Arjan van de Ven
2008-10-03  4:50                   ` Andrew Morton
2008-10-03  5:00                     ` Arjan van de Ven
2008-10-03  5:24                       ` Andrew Morton
2008-10-03 17:21                         ` Arjan van de Ven
2008-10-09  3:00                         ` Theodore Tso
2008-10-09  3:38                           ` Andrew Morton
2008-10-03  4:45                 ` Arjan van de Ven
2008-10-02  6:57   ` Andi Kleen
2008-10-02  7:55     ` Jens Axboe
2008-10-02  9:33       ` Dave Chinner
2008-10-02  9:45         ` Jens Axboe
2008-10-02 13:14           ` Arjan van de Ven
2008-10-02 13:27             ` Jens Axboe
2008-10-02 13:36               ` Arjan van de Ven
2008-10-02 13:47                 ` Jens Axboe
2008-10-02 14:26                   ` Arjan van de Ven
2008-10-02 16:42                     ` Jens Axboe
2008-10-02 19:04           ` Arjan van de Ven
2008-10-02 19:22             ` Jens Axboe
2008-10-02 21:37               ` Andrew Morton
2008-10-02 23:58                 ` Dave Chinner
2008-10-03  0:06                   ` Andrew Morton
2008-10-03  0:20                     ` Andrew Morton
2008-10-02 13:05   ` Arjan van de Ven
2008-10-02 17:11     ` Jens Axboe
     [not found] <bimJN-4cO-5@gated-at.bofh.it>
     [not found] ` <biosl-6bq-9@gated-at.bofh.it>
     [not found]   ` <biqkw-aK-3@gated-at.bofh.it>
     [not found]     ` <birgx-1pQ-9@gated-at.bofh.it>
     [not found]       ` <bisPe-3xx-9@gated-at.bofh.it>
     [not found]         ` <bisYW-3HQ-13@gated-at.bofh.it>
2008-10-02 15:32           ` Bodo Eggert
2008-10-02 23:34             ` Dave Chinner
2008-10-04  7:45               ` Aaron Carroll
2008-10-06  3:18                 ` Dave Chinner
2008-10-07 18:06                   ` Jens Axboe
2008-10-07 22:22                     ` Dave Chinner
2008-10-09  8:48                       ` Jens Axboe

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).