From: Christoph Lameter <cl@linux-foundation.org>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
"hannes@cmpxchg.org" <hannes@cmpxchg.org>,
"peterz@infradead.org" <peterz@infradead.org>,
"riel@redhat.com" <riel@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"tytso@mit.edu" <tytso@mit.edu>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"elladan@eskimo.com" <elladan@eskimo.com>,
"npiggin@suse.de" <npiggin@suse.de>,
"minchan.kim@gmail.com" <minchan.kim@gmail.com>
Subject: Re: [PATCH -mm] vmscan: protect a fraction of file backed mapped pages from reclaim
Date: Tue, 12 May 2009 16:54:21 -0400 (EDT) [thread overview]
Message-ID: <alpine.DEB.1.10.0905121650090.14226@qirst.com> (raw)
In-Reply-To: <20090512120002.D616.A69D9226@jp.fujitsu.com>
All these expiration modifications do not take into account that a desktop
may sit idle for hours while some other things run in the background (like
backups at night or updatedb and other maintenance things). This still
means that the desktop will be usuable in the morning.
I have had some success with a patch that protects a pages in the file
cache from being unmapped if the mapped pages are below a certain
percentage of the file cache. Its another VM knob to define the percentage
though.
Subject: Do not evict mapped pages
It is quite annoying when important executable pages of the user interface
are evicted from memory because backup or some other function runs and no one
is clicking any buttons for awhile. Once you get back to the desktop and
try to click a link one is in for a surprise. It can take quite a long time
for the desktop to recover from the swap outs.
This patch ensures that mapped pages in the file cache are not evicted if there
are a sufficient number of unmapped pages present. A similar technique is
already in use under NUMA for zone reclaim. The same method can be used to
protect mapped pages from reclaim.
The percentage of file backed pages protected is set via
/proc/sys/vm/file_mapped_ratio. This defaults to 20%.
Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
---
Documentation/sysctl/vm.txt | 14 ++++++++++++++
include/linux/swap.h | 1 +
kernel/sysctl.c | 13 ++++++++++++-
mm/vmscan.c | 32 ++++++++++++++++++++++++++++----
4 files changed, 55 insertions(+), 5 deletions(-)
Index: linux-2.6/mm/vmscan.c
===================================================================
--- linux-2.6.orig/mm/vmscan.c 2009-05-11 21:37:15.397876418 -0500
+++ linux-2.6/mm/vmscan.c 2009-05-11 21:37:23.287875742 -0500
@@ -585,7 +585,8 @@ void putback_lru_page(struct page *page)
*/
static unsigned long shrink_page_list(struct list_head *page_list,
struct scan_control *sc,
- enum pageout_io sync_writeback)
+ enum pageout_io sync_writeback,
+ int unmap_mapped)
{
LIST_HEAD(ret_pages);
struct pagevec freed_pvec;
@@ -616,7 +617,7 @@ static unsigned long shrink_page_list(st
if (unlikely(!page_evictable(page, NULL)))
goto cull_mlocked;
- if (!sc->may_unmap && page_mapped(page))
+ if (!unmap_mapped && page_mapped(page))
goto keep_locked;
/* Double the slab pressure for mapped and swapcache pages */
@@ -1047,6 +1048,12 @@ int isolate_lru_page(struct page *page)
}
/*
+ * Percentage of pages of the file lru necessary for unmapping of
+ * pages to occur during reclaim.
+ */
+int sysctl_file_unmap_ratio = 20;
+
+/*
* shrink_inactive_list() is a helper for shrink_zone(). It returns the number
* of reclaimed pages
*/
@@ -1059,10 +1066,26 @@ static unsigned long shrink_inactive_lis
unsigned long nr_scanned = 0;
unsigned long nr_reclaimed = 0;
struct zone_reclaim_stat *reclaim_stat = get_reclaim_stat(zone, sc);
+ int unmap_mapped = 0;
pagevec_init(&pvec, 1);
lru_add_drain();
+
+ /*
+ * Only allow unmapping of file backed pages if the amount of file
+ * mapped page becomes greater than a certain percentage of the file
+ * lru (+ free memory in order to avoid useless unmaps before memory
+ * fills up).
+ */
+ if (sc->may_unmap && (!file ||
+ zone_page_state(zone, NR_FILE_MAPPED) * 100 >
+ (zone_page_state(zone, NR_FREE_PAGES) +
+ zone_page_state(zone, NR_ACTIVE_FILE) +
+ zone_page_state(zone, NR_INACTIVE_FILE))
+ * sysctl_file_unmap_ratio))
+ unmap_mapped = 1;
+
spin_lock_irq(&zone->lru_lock);
do {
struct page *page;
@@ -1111,7 +1134,8 @@ static unsigned long shrink_inactive_lis
spin_unlock_irq(&zone->lru_lock);
nr_scanned += nr_scan;
- nr_freed = shrink_page_list(&page_list, sc, PAGEOUT_IO_ASYNC);
+ nr_freed = shrink_page_list(&page_list, sc, PAGEOUT_IO_ASYNC,
+ unmap_mapped);
/*
* If we are direct reclaiming for contiguous pages and we do
@@ -1131,7 +1155,7 @@ static unsigned long shrink_inactive_lis
count_vm_events(PGDEACTIVATE, nr_active);
nr_freed += shrink_page_list(&page_list, sc,
- PAGEOUT_IO_SYNC);
+ PAGEOUT_IO_SYNC, unmap_mapped);
}
nr_reclaimed += nr_freed;
Index: linux-2.6/include/linux/swap.h
===================================================================
--- linux-2.6.orig/include/linux/swap.h 2009-05-11 21:37:15.417879047 -0500
+++ linux-2.6/include/linux/swap.h 2009-05-11 21:37:23.287875742 -0500
@@ -221,6 +221,7 @@ extern unsigned long shrink_all_memory(u
extern int vm_swappiness;
extern int remove_mapping(struct address_space *mapping, struct page *page);
extern long vm_total_pages;
+extern int sysctl_file_unmap_ratio;
#ifdef CONFIG_NUMA
extern int zone_reclaim_mode;
Index: linux-2.6/kernel/sysctl.c
===================================================================
--- linux-2.6.orig/kernel/sysctl.c 2009-05-11 21:37:15.467877848 -0500
+++ linux-2.6/kernel/sysctl.c 2009-05-11 21:37:23.307877270 -0500
@@ -92,7 +92,6 @@ extern int rcutorture_runnable;
/* Constants used for minimum and maximum */
#ifdef CONFIG_DETECT_SOFTLOCKUP
-static int sixty = 60;
static int neg_one = -1;
#endif
@@ -100,6 +99,7 @@ static int zero;
static int __maybe_unused one = 1;
static int __maybe_unused two = 2;
static unsigned long one_ul = 1;
+static int sixty = 60;
static int one_hundred = 100;
static int one_thousand = 1000;
@@ -1141,6 +1141,17 @@ static struct ctl_table vm_table[] = {
.strategy = &sysctl_intvec,
.extra1 = &min_percpu_pagelist_fract,
},
+ {
+ .ctl_name = CTL_UNNUMBERED,
+ .procname = "file_mapped_ratio",
+ .data = &sysctl_file_unmap_ratio,
+ .maxlen = sizeof(sysctl_file_unmap_ratio),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec_minmax,
+ .strategy = &sysctl_intvec,
+ .extra1 = &zero,
+ .extra2 = &sixty,
+ },
#ifdef CONFIG_MMU
{
.ctl_name = VM_MAX_MAP_COUNT,
Index: linux-2.6/Documentation/sysctl/vm.txt
===================================================================
--- linux-2.6.orig/Documentation/sysctl/vm.txt 2009-05-11 21:45:43.937878597 -0500
+++ linux-2.6/Documentation/sysctl/vm.txt 2009-05-11 21:52:57.217874275 -0500
@@ -26,6 +26,7 @@ Currently, these files are in /proc/sys/
- dirty_ratio
- dirty_writeback_centisecs
- drop_caches
+- file_mapped_ratio
- hugepages_treat_as_movable
- hugetlb_shm_group
- laptop_mode
@@ -140,6 +141,19 @@ user should run `sync' first.
==============================================================
+file_mapped_ratio
+
+A percentage of the file backed pages in memory. If there are more
+mapped pages than this percentage then reclaim will unmap pages
+from the memory of processes.
+
+The main function of this ratio is to protect pags in use
+by proceses from streaming I/O and other operations that
+put a lot of churn on the page cache and would usually evict
+most pages.
+
+==============================================================
+
hugepages_treat_as_movable
This parameter is only useful when kernelcore= is specified at boot time to
--
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>
next prev parent reply other threads:[~2009-05-12 16:55 UTC|newest]
Thread overview: 168+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20090428044426.GA5035@eskimo.com>
2009-04-28 5:35 ` Swappiness vs. mmap() and interactive response KOSAKI Motohiro
2009-04-28 6:36 ` Elladan
2009-04-28 6:52 ` KOSAKI Motohiro
2009-04-28 7:26 ` Elladan
2009-04-28 7:44 ` KOSAKI Motohiro
2009-04-28 7:48 ` Peter Zijlstra
2009-04-28 7:58 ` Balbir Singh
2009-04-28 8:11 ` Peter Zijlstra
2009-04-28 8:23 ` KAMEZAWA Hiroyuki
2009-04-28 8:25 ` Balbir Singh
2009-04-28 8:03 ` KOSAKI Motohiro
2009-04-28 9:09 ` Wu Fengguang
2009-04-28 9:26 ` Wu Fengguang
2009-04-28 12:08 ` Theodore Tso
2009-04-29 5:51 ` KOSAKI Motohiro
2009-04-29 6:34 ` Andrew Morton
2009-04-29 7:47 ` KOSAKI Motohiro
2009-04-30 4:14 ` Elladan
2009-04-30 4:43 ` Andrew Morton
2009-04-30 4:55 ` KOSAKI Motohiro
2009-04-30 4:55 ` Elladan
2009-04-29 7:48 ` KOSAKI Motohiro
2009-04-30 11:59 ` KOSAKI Motohiro
2009-04-30 13:46 ` Elladan
2009-05-06 11:04 ` KOSAKI Motohiro
2009-04-28 15:28 ` Rik van Riel
2009-04-28 23:29 ` [PATCH] vmscan: evict use-once pages first Rik van Riel
2009-04-29 3:36 ` Elladan
2009-04-29 17:06 ` Christoph Hellwig
2009-04-29 6:42 ` Peter Zijlstra
2009-04-29 13:30 ` Rik van Riel
2009-04-29 15:47 ` [PATCH] vmscan: evict use-once pages first (v2) Rik van Riel
2009-04-29 16:07 ` KOSAKI Motohiro
2009-04-29 16:18 ` Rik van Riel
2009-04-29 17:14 ` [PATCH] vmscan: evict use-once pages first (v3) Rik van Riel
2009-04-30 0:39 ` KOSAKI Motohiro
2009-04-30 8:10 ` Johannes Weiner
2009-05-01 22:32 ` Andrew Morton
2009-05-01 23:05 ` Rik van Riel
2009-05-01 23:25 ` Andrew Morton
2009-05-03 1:28 ` Wu Fengguang
2009-05-03 1:15 ` Wu Fengguang
2009-05-03 1:33 ` Rik van Riel
2009-05-03 1:46 ` Wu Fengguang
2009-04-29 16:10 ` [PATCH] vmscan: evict use-once pages first (v2) Peter Zijlstra
2009-04-30 7:20 ` Elladan
2009-04-30 13:08 ` Rik van Riel
2009-04-30 14:00 ` Elladan
2009-05-01 0:45 ` Andrew Morton
2009-05-01 0:59 ` Rik van Riel
2009-05-01 1:13 ` Andrew Morton
2009-05-01 1:50 ` Rik van Riel
2009-05-01 2:54 ` Andrew Morton
2009-05-01 14:05 ` Rik van Riel
2009-05-01 18:04 ` Ray Lee
2009-05-01 19:34 ` Rik van Riel
2009-05-01 19:44 ` Ray Lee
2009-05-01 20:08 ` Rik van Riel
2009-05-01 20:17 ` Elladan
2009-05-01 19:35 ` Andrew Morton
2009-05-01 20:05 ` Rik van Riel
2009-05-01 20:45 ` Andrew Morton
2009-05-01 21:46 ` Rik van Riel
2009-05-03 3:15 ` Wu Fengguang
2009-05-03 3:24 ` Rik van Riel
2009-05-03 3:43 ` Wu Fengguang
2009-05-04 10:23 ` Peter Zijlstra
2009-05-07 12:11 ` [PATCH -mm] vmscan: make mapped executable pages the first class citizen Wu Fengguang
2009-05-07 13:39 ` Christoph Lameter
2009-05-07 14:15 ` Peter Zijlstra
2009-05-07 14:18 ` Christoph Lameter
2009-05-07 14:38 ` Peter Zijlstra
2009-05-07 15:36 ` Christoph Lameter
2009-05-07 15:59 ` Rik van Riel
2009-05-07 15:06 ` Rik van Riel
2009-05-07 16:00 ` Lee Schermerhorn
2009-05-07 16:32 ` Christoph Lameter
2009-05-07 17:11 ` Rik van Riel
2009-05-08 3:40 ` Elladan
2009-05-08 16:04 ` Rik van Riel
2009-05-09 4:04 ` Elladan
2009-05-08 17:18 ` Christoph Lameter
2009-05-09 10:20 ` KOSAKI Motohiro
2009-05-08 17:37 ` Alan Cox
2009-05-07 15:10 ` Johannes Weiner
2009-05-07 15:17 ` Peter Zijlstra
2009-05-07 15:21 ` Rik van Riel
2009-05-08 3:30 ` Wu Fengguang
2009-05-08 4:17 ` [RFC][PATCH] vmscan: report vm_flags in page_referenced() Wu Fengguang
2009-05-08 12:09 ` Minchan Kim
2009-05-08 12:15 ` Wu Fengguang
2009-05-08 14:01 ` Minchan Kim
2009-05-09 6:56 ` Wu Fengguang
2009-05-10 23:45 ` Minchan Kim
2009-05-17 11:25 ` Wu Fengguang
2009-05-07 20:44 ` [PATCH -mm] vmscan: make mapped executable pages the first class citizen Andrew Morton
2009-05-08 8:16 ` Wu Fengguang
2009-05-08 8:28 ` Wu Fengguang
2009-05-08 19:58 ` Andrew Morton
2009-05-08 22:00 ` Alan Cox
2009-05-08 22:15 ` Andrew Morton
2009-05-08 22:53 ` Elladan
2009-05-08 22:20 ` Rik van Riel
2009-05-10 8:59 ` KOSAKI Motohiro
2009-05-10 9:07 ` Peter Zijlstra
2009-05-10 9:35 ` Wu Fengguang
2009-05-10 10:06 ` KOSAKI Motohiro
2009-05-10 9:36 ` KOSAKI Motohiro
2009-05-10 13:45 ` Alan Cox
2009-05-10 13:56 ` KOSAKI Motohiro
2009-05-10 14:51 ` Rik van Riel
2009-05-10 14:59 ` KOSAKI Motohiro
2009-05-10 20:13 ` Alan Cox
2009-05-10 20:37 ` Rik van Riel
2009-05-10 21:23 ` Arjan van de Ven
2009-05-11 10:03 ` Johannes Weiner
2009-05-10 21:29 ` Alan Cox
2009-05-10 9:20 ` Wu Fengguang
2009-05-10 9:29 ` KOSAKI Motohiro
2009-05-10 10:03 ` Wu Fengguang
2009-05-10 10:15 ` KOSAKI Motohiro
2009-05-10 11:21 ` Wu Fengguang
2009-05-10 11:39 ` KOSAKI Motohiro
2009-05-10 11:44 ` Wu Fengguang
2009-05-10 12:19 ` Peter Zijlstra
2009-05-10 12:39 ` KOSAKI Motohiro
2009-05-10 13:17 ` Peter Zijlstra
2009-05-12 2:50 ` Wu Fengguang
2009-05-12 4:35 ` Wu Fengguang
2009-05-12 13:20 ` Rik van Riel
2009-05-16 9:26 ` Wu Fengguang
2009-05-12 2:51 ` [PATCH -mm] vmscan: report vm_flags in page_referenced() Wu Fengguang
2009-05-12 6:23 ` Peter Zijlstra
2009-05-12 6:44 ` Minchan Kim
2009-05-12 11:44 ` Wu Fengguang
2009-05-12 2:52 ` [PATCH -mm] vmscan: make mapped executable pages the first class citizen Wu Fengguang
2009-05-12 3:00 ` KOSAKI Motohiro
2009-05-12 20:54 ` Christoph Lameter [this message]
2009-05-12 17:06 ` [PATCH -mm] vmscan: protect a fraction of file backed mapped pages from reclaim Rik van Riel
2009-05-12 21:20 ` Christoph Lameter
2009-05-12 17:39 ` Rik van Riel
2009-05-12 22:02 ` Christoph Lameter
2009-05-12 20:17 ` Rik van Riel
2009-05-12 20:26 ` Christoph Lameter
2009-05-13 0:45 ` KOSAKI Motohiro
2009-05-14 20:14 ` Christoph Lameter
2009-05-14 23:28 ` KOSAKI Motohiro
2009-05-14 23:42 ` Rik van Riel
2009-05-15 18:09 ` Christoph Lameter
2009-05-16 8:54 ` Wu Fengguang
2009-05-12 8:17 ` [PATCH -mm] vmscan: make mapped executable pages the first class citizen Minchan Kim
2009-05-12 2:53 ` [PATCH -mm] vmscan: merge duplicate code in shrink_active_list() Wu Fengguang
2009-05-12 2:58 ` KOSAKI Motohiro
2009-05-12 3:03 ` Wu Fengguang
2009-05-12 7:26 ` Minchan Kim
2009-05-12 11:48 ` Wu Fengguang
2009-05-12 11:57 ` Minchan Kim
2009-05-12 13:32 ` Rik van Riel
2009-05-16 9:30 ` Wu Fengguang
2009-05-08 3:02 ` [PATCH -mm] vmscan: make mapped executable pages the first class citizen Wu Fengguang
2009-05-08 7:30 ` Minchan Kim
2009-05-08 8:09 ` Wu Fengguang
2009-05-08 9:34 ` Minchan Kim
2009-05-08 14:25 ` Christoph Lameter
2009-05-08 14:34 ` Rik van Riel
2009-05-08 17:41 ` KOSAKI Motohiro
2009-05-04 8:04 ` [PATCH] vmscan: evict use-once pages first (v2) Peter Zijlstra
2009-05-01 3:09 ` Elladan
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=alpine.DEB.1.10.0905121650090.14226@qirst.com \
--to=cl@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=elladan@eskimo.com \
--cc=fengguang.wu@intel.com \
--cc=hannes@cmpxchg.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan.kim@gmail.com \
--cc=npiggin@suse.de \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=tytso@mit.edu \
/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