public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Con Kolivas <kernel@kolivas.org>
To: Andrew Morton <akpm@osdl.org>
Cc: ck kernel mailing list <ck@vds.kolivas.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] Autotune swappiness
Date: Fri, 09 Jul 2004 02:24:20 +1000	[thread overview]
Message-ID: <40ED7534.4010409@kolivas.org> (raw)
In-Reply-To: <20040708010842.2064a706.akpm@osdl.org>


[-- Attachment #1.1: Type: text/plain, Size: 1657 bytes --]

Here is another try at providing feedback to tune the vm_swappiness.

This patch tries to tune it dynamically according to the mapped_ratio. 
After some consideration I thought it would be easiest to simply remove 
the vm_swappiness tunable entirely, since that is the point of this patch.

Some in the field modelling and testing showed a biased downwards 
feedback based on the mapped ratio provided good performance under 
different workloads especially improving the desktop experience. The 
practical upshot of this is the machine will only ever swap very lightly 
while the percentage of mapped pages is low and allow more generous 
swapping as the percentage rises within the higher ranges.

The earlier design of this patch was much more complicated and the 
practical upshot of it was that it would make

vm_swappiness = mapped_ratio * mapped_ratio / 100


This had it's effect on the swappiness value in the setting of 
swap_tendency which was:

swap_tendency = mapped_ratio / 2 + distress + vm_swappiness


A close approximation was to make vm_swappiness a range of 0-150 instead 
of 100 and simplify swap tendency to be equal to this:

swap_tendency = distress + vm_swappiness


A follow up patch will use the vm_swappiness value to alter the rate of 
page inactivation as well, but for the moment I'll offer this one change 
for comments.

Patch applies to 2.6.7-mm6
Signed-off-by: Con Kolivas <kernel@kolivas.org>

  include/linux/swap.h   |    1 -
  include/linux/sysctl.h |   15 +++++++--------
  kernel/sysctl.c        |   11 -----------
  mm/vmscan.c            |   15 ++++++++-------
  4 files changed, 15 insertions(+), 27 deletions(-)


[-- Attachment #1.2: autotune_swappiness.diff --]
[-- Type: text/x-patch, Size: 3962 bytes --]

Index: linux-2.6.7-mm6/include/linux/swap.h
===================================================================
--- linux-2.6.7-mm6.orig/include/linux/swap.h	2004-07-09 02:15:07.509902884 +1000
+++ linux-2.6.7-mm6/include/linux/swap.h	2004-07-09 02:15:10.949349575 +1000
@@ -174,7 +174,6 @@
 /* linux/mm/vmscan.c */
 extern int try_to_free_pages(struct zone **, unsigned int, unsigned int);
 extern int shrink_all_memory(int);
-extern int vm_swappiness;
 
 #ifdef CONFIG_MMU
 /* linux/mm/shmem.c */
Index: linux-2.6.7-mm6/include/linux/sysctl.h
===================================================================
--- linux-2.6.7-mm6.orig/include/linux/sysctl.h	2004-07-09 02:15:07.509902884 +1000
+++ linux-2.6.7-mm6/include/linux/sysctl.h	2004-07-09 02:15:10.950349415 +1000
@@ -157,14 +157,13 @@
 	VM_OVERCOMMIT_RATIO=16, /* percent of RAM to allow overcommit in */
 	VM_PAGEBUF=17,		/* struct: Control pagebuf parameters */
 	VM_HUGETLB_PAGES=18,	/* int: Number of available Huge Pages */
-	VM_SWAPPINESS=19,	/* Tendency to steal mapped memory */
-	VM_LOWER_ZONE_PROTECTION=20,/* Amount of protection of lower zones */
-	VM_MIN_FREE_KBYTES=21,	/* Minimum free kilobytes to maintain */
-	VM_MAX_MAP_COUNT=22,	/* int: Maximum number of mmaps/address-space */
-	VM_LAPTOP_MODE=23,	/* vm laptop mode */
-	VM_BLOCK_DUMP=24,	/* block dump mode */
-	VM_HUGETLB_GROUP=25,	/* permitted hugetlb group */
-	VM_VFS_CACHE_PRESSURE=26, /* dcache/icache reclaim pressure */
+	VM_LOWER_ZONE_PROTECTION=19,/* Amount of protection of lower zones */
+	VM_MIN_FREE_KBYTES=20,	/* Minimum free kilobytes to maintain */
+	VM_MAX_MAP_COUNT=21,	/* int: Maximum number of mmaps/address-space */
+	VM_LAPTOP_MODE=22,	/* vm laptop mode */
+	VM_BLOCK_DUMP=23,	/* block dump mode */
+	VM_HUGETLB_GROUP=24,	/* permitted hugetlb group */
+	VM_VFS_CACHE_PRESSURE=25, /* dcache/icache reclaim pressure */
 };
 
 
Index: linux-2.6.7-mm6/kernel/sysctl.c
===================================================================
--- linux-2.6.7-mm6.orig/kernel/sysctl.c	2004-07-09 02:15:07.496904975 +1000
+++ linux-2.6.7-mm6/kernel/sysctl.c	2004-07-09 02:15:10.951349254 +1000
@@ -700,17 +700,6 @@
 		.mode		= 0444 /* read-only*/,
 		.proc_handler	= &proc_dointvec,
 	},
-	{
-		.ctl_name	= VM_SWAPPINESS,
-		.procname	= "swappiness",
-		.data		= &vm_swappiness,
-		.maxlen		= sizeof(vm_swappiness),
-		.mode		= 0644,
-		.proc_handler	= &proc_dointvec_minmax,
-		.strategy	= &sysctl_intvec,
-		.extra1		= &zero,
-		.extra2		= &one_hundred,
-	},
 #ifdef CONFIG_HUGETLB_PAGE
 	 {
 		.ctl_name	= VM_HUGETLB_PAGES,
Index: linux-2.6.7-mm6/mm/vmscan.c
===================================================================
--- linux-2.6.7-mm6.orig/mm/vmscan.c	2004-07-09 02:15:07.495905136 +1000
+++ linux-2.6.7-mm6/mm/vmscan.c	2004-07-09 02:15:21.366673884 +1000
@@ -116,9 +116,9 @@
 #endif
 
 /*
- * From 0 .. 100.  Higher means more swappy.
+ * From 0 .. 150.  Higher means more swappy.
  */
-int vm_swappiness = 60;
+static int vm_swappiness = 0;
 static long total_memory;
 
 static LIST_HEAD(shrinker_list);
@@ -690,17 +690,18 @@
 	 * is mapped.
 	 */
 	mapped_ratio = (sc->nr_mapped * 100) / total_memory;
-
+	
 	/*
 	 * Now decide how much we really want to unmap some pages.  The mapped
-	 * ratio is downgraded - just because there's a lot of mapped memory
+	 * ratio effect is downgraded by biasing downwards the value of
+	 * vm_swappiness - just because there's a lot of mapped memory
 	 * doesn't necessarily mean that page reclaim isn't succeeding.
 	 *
 	 * The distress ratio is important - we don't want to start going oom.
-	 *
-	 * A 100% value of vm_swappiness overrides this algorithm altogether.
 	 */
-	swap_tendency = mapped_ratio / 2 + distress + vm_swappiness;
+	vm_swappiness = mapped_ratio * 150 / 100;
+	vm_swappiness = vm_swappiness * vm_swappiness / 150;
+	swap_tendency = distress + vm_swappiness;
 
 	/*
 	 * Now use this metric to decide whether to start moving mapped memory

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]

  parent reply	other threads:[~2004-07-08 16:24 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-07 15:16 2.6.7-ck5 Con Kolivas
2004-07-07 15:39 ` 2.6.7-ck5 John Richard Moser
2004-07-07 15:47   ` 2.6.7-ck5 Con Kolivas
2004-07-07 15:53     ` 2.6.7-ck5 Prakash K. Cheemplavam
2004-07-07 16:11       ` 2.6.7-ck5 P
2004-07-07 17:10         ` 2.6.7-ck5 Prakash K. Cheemplavam
2004-07-07 16:17       ` 2.6.7-ck5 Redeeman
2004-07-08  4:38     ` 2.6.7-ck5 Andrew Morton
2004-07-08  6:40       ` [PATCH] Autoregulate swappiness & inactivation Con Kolivas
2004-07-08  6:45         ` Con Kolivas
2004-07-08  7:06         ` [PATCH] " Nick Piggin
2004-07-08  7:12           ` Con Kolivas
2004-07-08  7:31             ` Nick Piggin
2004-07-08  8:03               ` Con Kolivas
2004-07-08  8:12                 ` Nick Piggin
2004-07-08 17:06                   ` John Richard Moser
2004-07-08 17:14                   ` [ck] " Mikhail Ramendik
2004-07-08 17:10           ` [ck] Re: [PATCH] " Mikhail Ramendik
2004-07-09  1:03             ` Nick Piggin
2004-07-08  7:10         ` Andrew Morton
2004-07-08  7:58           ` Con Kolivas
2004-07-08  8:08             ` Andrew Morton
2004-07-08  8:27               ` Con Kolivas
2004-07-08 10:54                 ` FabF
2004-07-09  1:05                   ` Con Kolivas
2004-07-09  9:48                     ` FabF
2004-07-09 10:43                       ` Nick Piggin
2004-07-09 11:14                         ` FabF
2004-07-09 11:24                           ` Nick Piggin
2004-07-10  9:44                             ` FabF
     [not found]                               ` <40EFC076.9050504@yahoo.com.au>
2004-07-10 10:57                                 ` rss recovery FabF
2004-07-10 12:03                                   ` Nick Piggin
2004-07-13 13:12                                     ` FabF
2004-07-08 16:26                 ` Autoregulate swappiness & inactivation Timothy Miller
2004-07-08 17:12                   ` John Richard Moser
2004-07-08 18:37                     ` Timothy Miller
2004-07-08 21:40                       ` John Richard Moser
2004-07-09  7:44                     ` Felipe Alfaro Solana
2004-07-08 16:24               ` Con Kolivas [this message]
2004-07-08 16:44                 ` [PATCH] Autotune swappiness Andrew Morton
2004-07-09  0:39                   ` Con Kolivas
2004-07-09  1:19                     ` [ck] " Kerin Millar
2004-07-09 14:23                     ` Martin J. Bligh
2004-07-09 14:26                       ` Con Kolivas
2004-07-08 15:57       ` [ck] Re: 2.6.7-ck5 GSehp
2004-07-07 16:45 ` 2.6.7-ck5 John Richard Moser
2004-07-07 17:10   ` 2.6.7-ck5 Prakash K. Cheemplavam
2004-07-07 22:26 ` 2.6.7-ck5 Wes Janzen
2004-07-07 22:53   ` 2.6.7-ck5 Con Kolivas

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=40ED7534.4010409@kolivas.org \
    --to=kernel@kolivas.org \
    --cc=akpm@osdl.org \
    --cc=ck@vds.kolivas.org \
    --cc=linux-kernel@vger.kernel.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