linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: miklos@szeredi.hu, akpm@linux-foundation.org, neilb@suse.de,
	dgc@sgi.com, tomoki.sekiyama.qu@hitachi.com,
	a.p.zijlstra@chello.nl, nikita@clusterfs.com,
	trond.myklebust@fys.uio.no, yingchao.zhou@gmail.com
Subject: [PATCH 15/15] mm: dirty balancing for tasks
Date: Thu, 10 May 2007 12:08:54 +0200	[thread overview]
Message-ID: <20070510101129.908781235@chello.nl> (raw)
In-Reply-To: <20070510100839.621199408@chello.nl>

[-- Attachment #1: dirty_pages2.patch --]
[-- Type: text/plain, Size: 6206 bytes --]

Based on ideas of Andrew:
  http://marc.info/?l=linux-kernel&m=102912915020543&w=2

Scale the bdi dirty limit inversly with the tasks dirty rate.
This makes heavy writers have a lower dirty limit than the occasional writer. 

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 include/linux/sched.h |    2 +
 kernel/exit.c         |    1 
 kernel/fork.c         |    1 
 mm/page-writeback.c   |   60 +++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 63 insertions(+), 1 deletion(-)

Index: linux-2.6/include/linux/sched.h
===================================================================
--- linux-2.6.orig/include/linux/sched.h	2007-05-10 11:06:12.000000000 +0200
+++ linux-2.6/include/linux/sched.h	2007-05-10 11:48:20.000000000 +0200
@@ -83,6 +83,7 @@ struct sched_param {
 #include <linux/timer.h>
 #include <linux/hrtimer.h>
 #include <linux/task_io_accounting.h>
+#include <linux/proportions.h>
 
 #include <asm/processor.h>
 
@@ -1092,6 +1093,7 @@ struct task_struct {
 #ifdef CONFIG_FAULT_INJECTION
 	int make_it_fail;
 #endif
+	struct prop_local dirties;
 };
 
 static inline pid_t process_group(struct task_struct *tsk)
Index: linux-2.6/kernel/exit.c
===================================================================
--- linux-2.6.orig/kernel/exit.c	2007-05-10 11:06:12.000000000 +0200
+++ linux-2.6/kernel/exit.c	2007-05-10 11:48:20.000000000 +0200
@@ -160,6 +160,7 @@ repeat:
 	ptrace_unlink(p);
 	BUG_ON(!list_empty(&p->ptrace_list) || !list_empty(&p->ptrace_children));
 	__exit_signal(p);
+	prop_local_destroy(&p->dirties);
 
 	/*
 	 * If we are the last non-leader member of the thread
Index: linux-2.6/kernel/fork.c
===================================================================
--- linux-2.6.orig/kernel/fork.c	2007-05-10 11:06:12.000000000 +0200
+++ linux-2.6/kernel/fork.c	2007-05-10 11:48:20.000000000 +0200
@@ -191,6 +191,7 @@ static struct task_struct *dup_task_stru
 	tsk->btrace_seq = 0;
 #endif
 	tsk->splice_pipe = NULL;
+	prop_local_init(&tsk->dirties);
 	return tsk;
 }
 
Index: linux-2.6/mm/page-writeback.c
===================================================================
--- linux-2.6.orig/mm/page-writeback.c	2007-05-10 11:06:12.000000000 +0200
+++ linux-2.6/mm/page-writeback.c	2007-05-10 11:54:56.000000000 +0200
@@ -118,6 +118,7 @@ static void background_writeout(unsigned
  *
  */
 struct prop_descriptor vm_completions;
+struct prop_descriptor vm_dirties;
 
 static unsigned long determine_dirtyable_memory(void);
 
@@ -146,6 +147,7 @@ int dirty_ratio_handler(ctl_table *table
 	if (ret == 0 && write && vm_dirty_ratio != old_ratio) {
 		int shift = calc_period_shift();
 		prop_change_shift(&vm_completions, shift);
+		prop_change_shift(&vm_dirties, shift);
 	}
 	return ret;
 }
@@ -161,6 +163,16 @@ static void __bdi_writeout_inc(struct ba
 	prop_put_global(&vm_completions, pg);
 }
 
+static void task_dirty_inc(struct task_struct *tsk)
+{
+	unsigned long flags;
+	struct prop_global *pg = prop_get_global(&vm_dirties);
+	local_irq_save(flags);
+	__prop_inc(pg, &tsk->dirties);
+	local_irq_restore(flags);
+	prop_put_global(&vm_dirties, pg);
+}
+
 /*
  * Obtain an accurate fraction of the BDI's portion.
  */
@@ -177,6 +189,14 @@ void bdi_writeout_fraction(struct backin
 	}
 }
 
+void task_dirties_fraction(struct task_struct *tsk,
+		long *numerator, long *denominator)
+{
+	struct prop_global *pg = prop_get_global(&vm_dirties);
+	prop_fraction(pg, &tsk->dirties, numerator, denominator);
+	prop_put_global(&vm_dirties, pg);
+}
+
 /*
  * Work out the current dirty-memory clamping and background writeout
  * thresholds.
@@ -310,6 +330,33 @@ clip_bdi_dirty_limit(struct backing_dev_
 }
 
 /*
+ * scale the dirty limit
+ *
+ * task specific dirty limit:
+ *
+ *   dirty -= (dirty/2) * p_{t}
+ */
+void task_dirty_limit(struct task_struct *tsk, long *pdirty)
+{
+	long numerator, denominator;
+	long dirty = *pdirty;
+	long long inv = dirty >> 1;
+
+	task_dirties_fraction(tsk, &numerator, &denominator);
+	inv *= numerator;
+	do_div(inv, denominator);
+
+	dirty -= inv;
+	if (dirty < *pdirty/2) {
+		printk("odd limit: %ld %ld %ld\n",
+				*pdirty, dirty, (long)inv);
+		dirty = *pdirty/2;
+	}
+
+	*pdirty = dirty;
+}
+
+/*
  * balance_dirty_pages() must be called by processes which are generating dirty
  * data.  It looks at the number of dirty pages in the machine and will force
  * the caller to perform writeback if the system is over `vm_dirty_ratio'.
@@ -340,6 +387,7 @@ static void balance_dirty_pages(struct a
 		get_dirty_limits(&background_thresh, &dirty_thresh,
 				&bdi_thresh, bdi);
 		clip_bdi_dirty_limit(bdi, dirty_thresh, &bdi_thresh);
+		task_dirty_limit(current, &bdi_thresh);
 		bdi_nr_reclaimable = bdi_stat(bdi, BDI_RECLAIMABLE);
 		bdi_nr_writeback = bdi_stat(bdi, BDI_WRITEBACK);
 		if (bdi_nr_reclaimable + bdi_nr_writeback <= bdi_thresh)
@@ -360,6 +408,7 @@ static void balance_dirty_pages(struct a
 			get_dirty_limits(&background_thresh, &dirty_thresh,
 				       &bdi_thresh, bdi);
 			clip_bdi_dirty_limit(bdi, dirty_thresh, &bdi_thresh);
+			task_dirty_limit(current, &bdi_thresh);
 
 			/*
 			 * In order to avoid the stacked BDI deadlock we need
@@ -732,6 +781,7 @@ void __init page_writeback_init(void)
 
 	shift = calc_period_shift();
 	prop_descriptor_init(&vm_completions, shift);
+	prop_descriptor_init(&vm_dirties, shift);
 }
 
 /**
@@ -1009,7 +1059,7 @@ EXPORT_SYMBOL(redirty_page_for_writepage
  * If the mapping doesn't provide a set_page_dirty a_op, then
  * just fall through and assume that it wants buffer_heads.
  */
-int fastcall set_page_dirty(struct page *page)
+static int __set_page_dirty(struct page *page)
 {
 	struct address_space *mapping = page_mapping(page);
 
@@ -1027,6 +1077,14 @@ int fastcall set_page_dirty(struct page 
 	}
 	return 0;
 }
+
+int fastcall set_page_dirty(struct page *page)
+{
+	int ret = __set_page_dirty(page);
+	if (ret)
+		task_dirty_inc(current);
+	return ret;
+}
 EXPORT_SYMBOL(set_page_dirty);
 
 /*

-- 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2007-05-10 10:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-10 10:08 [PATCH 00/15] per device dirty throttling -v6 Peter Zijlstra
2007-05-10 10:08 ` [PATCH 01/15] nfs: remove congestion_end() Peter Zijlstra
2007-05-10 10:08 ` [PATCH 02/15] lib: percpu_counter variable batch Peter Zijlstra
2007-05-10 10:08 ` [PATCH 03/15] lib: percpu_counter_mod64 Peter Zijlstra
2007-05-10 10:08 ` [PATCH 04/15] lib: percpu_counter_set Peter Zijlstra
2007-05-10 10:08 ` [PATCH 05/15] lib: percpu_count_sum_signed() Peter Zijlstra
2007-05-10 10:08 ` [PATCH 06/15] mm: bdi init hooks Peter Zijlstra
2007-05-10 10:08 ` [PATCH 07/15] mtd: give mtdconcat devices their own backing_dev_info Peter Zijlstra
2007-05-10 10:08 ` [PATCH 08/15] mm: scalable bdi statistics counters Peter Zijlstra
2007-05-10 10:08 ` [PATCH 09/15] mm: count reclaimable pages per BDI Peter Zijlstra
2007-05-10 10:08 ` [PATCH 10/15] mm: count writeback " Peter Zijlstra
2007-05-10 10:08 ` [PATCH 11/15] mm: expose BDI statistics in sysfs Peter Zijlstra
2007-05-10 10:08 ` [PATCH 12/15] mm: per device dirty threshold Peter Zijlstra
2007-05-10 10:08 ` [PATCH 13/15] debug: sysfs files for the current ratio/size/total Peter Zijlstra
2007-05-10 10:08 ` [PATCH 14/15] lib: abstract the floating proportion Peter Zijlstra
2007-05-10 10:08 ` Peter Zijlstra [this message]
2007-05-15  4:48 ` [PATCH 00/15] per device dirty throttling -v6 Neil Brown
2007-05-15  7:44   ` Peter Zijlstra

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=20070510101129.908781235@chello.nl \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=dgc@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=miklos@szeredi.hu \
    --cc=neilb@suse.de \
    --cc=nikita@clusterfs.com \
    --cc=tomoki.sekiyama.qu@hitachi.com \
    --cc=trond.myklebust@fys.uio.no \
    --cc=yingchao.zhou@gmail.com \
    /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