linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Minchan Kim <minchan.kim@gmail.com>
To: Wu Fengguang <fengguang.wu@intel.com>
Cc: 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>,
	"cl@linux-foundation.org" <cl@linux-foundation.org>,
	"kosaki.motohiro@jp.fujitsu.com" <kosaki.motohiro@jp.fujitsu.com>,
	"minchan.kim@gmail.com" <minchan.kim@gmail.com>
Subject: Re: [PATCH -mm] vmscan: make mapped executable pages the first class citizen
Date: Tue, 12 May 2009 17:17:29 +0900	[thread overview]
Message-ID: <20090512171729.3fe475d1.minchan.kim@barrios-desktop> (raw)
In-Reply-To: <20090512025246.GC7518@localhost>

On Tue, 12 May 2009 10:52:46 +0800
Wu Fengguang <fengguang.wu@intel.com> wrote:

That is great explanation. :)

Now, we just need any numbers. 
But, as you know, It is difficult to get the numbers for various workloads. 

I don't know it is job of you or us ?? 
MM tree is always not stable. It's place to test freely for various workloads.

If we can justify patch at least, we can test it after merge once. 
(Of course, It depends on Andrew )
After long testing without any regresssions, we can merge this into linus tree. 

I think this patch is enough. 

Wu Fengguang 
Please, resend this patch series with modifying 'merge duplicate code in shrink_active_list' patch. 

Thanks for your great effort. :)

> Protect referenced PROT_EXEC mapped pages from being deactivated.
> 
> PROT_EXEC(or its internal presentation VM_EXEC) pages normally belong to some
> currently running executables and their linked libraries, they shall really be
> cached aggressively to provide good user experiences.
> 
> Thanks to Johannes Weiner for the advice to reuse the VMA walk in
> page_referenced() to get the PROT_EXEC bit.
> 
> 
> [more details]
> 
> ( The consequences of this patch will have to be discussed together with
>   Rik van Riel's recent patch "vmscan: evict use-once pages first". )
> 
> ( Some of the good points and insights are taken into this changelog.
>   Thanks to all the involved people for the great LKML discussions. )
> 
> the problem
> -----------
> 
> For a typical desktop, the most precious working set is composed of
> *actively accessed*
> 	(1) memory mapped executables
> 	(2) and their anonymous pages
> 	(3) and other files
> 	(4) and the dcache/icache/.. slabs
> while the least important data are
> 	(5) infrequently used or use-once files
> 
> For a typical desktop, one major problem is busty and large amount of (5)
> use-once files flushing out the working set.
> 
> Inside the working set, (4) dcache/icache have already been too sticky ;-)
> So we only have to care (2) anonymous and (1)(3) file pages.
> 
> anonymous pages
> ---------------
> Anonymous pages are effectively immune to the streaming IO attack, because we
> now have separate file/anon LRU lists. When the use-once files crowd into the
> file LRU, the list's "quality" is significantly lowered. Therefore the scan
> balance policy in get_scan_ratio() will choose to scan the (low quality) file
> LRU much more frequently than the anon LRU.
> 
> file pages
> ----------
> Rik proposed to *not* scan the active file LRU when the inactive list grows
> larger than active list. This guarantees that when there are use-once streaming
> IO, and the working set is not too large(so that active_size < inactive_size),
> the active file LRU will *not* be scanned at all. So the not-too-large working
> set can be well protected.
> 
> But there are also situations where the file working set is a bit large so that
> (active_size >= inactive_size), or the streaming IOs are not purely use-once.
> In these cases, the active list will be scanned slowly. Because the current
> shrink_active_list() policy is to deactivate active pages regardless of their
> referenced bits. The deactivated pages become susceptible to the streaming IO
> attack: the inactive list could be scanned fast (500MB / 50MBps = 10s) so that
> the deactivated pages don't have enough time to get re-referenced. Because a
> user tend to switch between windows in intervals from seconds to minutes.
> 
> This patch holds mapped executable pages in the active list as long as they
> are referenced during each full scan of the active list.  Because the active
> list is normally scanned much slower, they get longer grace time (eg. 100s)
> for further references, which better matches the pace of user operations.
> 
> side effects
> ------------
> 
> This patch is safe in general, it restores the pre-2.6.28 mmap() behavior
> but in a much smaller and well targeted scope.
> 
> One may worry about some one to abuse the PROT_EXEC heuristic.  But as
> Andrew Morton stated, there are other tricks to getting that sort of boost.
> 
> Another concern is the PROT_EXEC mapped pages growing large in rare cases,
> and therefore hurting reclaim efficiency. But a sane application targeted for
> large audience will never use PROT_EXEC for data mappings. If some home made
> application tries to abuse that bit, it shall be aware of the consequences,
> which won't be disastrous even in the worst case.
> 
> CC: Elladan <elladan@eskimo.com>
> CC: Nick Piggin <npiggin@suse.de>
> CC: Johannes Weiner <hannes@cmpxchg.org>
> CC: Christoph Lameter <cl@linux-foundation.org>
> CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Acked-by: Peter Zijlstra <peterz@infradead.org>
> Acked-by: Rik van Riel <riel@redhat.com>
> Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
> ---
>  mm/vmscan.c |   41 +++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 39 insertions(+), 2 deletions(-)
> 
> --- linux.orig/mm/vmscan.c
> +++ linux/mm/vmscan.c
> @@ -1233,6 +1233,7 @@ static void shrink_active_list(unsigned 
>  	unsigned long pgscanned;
>  	unsigned long vm_flags;
>  	LIST_HEAD(l_hold);	/* The pages which were snipped off */
> +	LIST_HEAD(l_active);
>  	LIST_HEAD(l_inactive);
>  	struct page *page;
>  	struct pagevec pvec;
> @@ -1272,8 +1273,21 @@ static void shrink_active_list(unsigned 
>  
>  		/* page_referenced clears PageReferenced */
>  		if (page_mapping_inuse(page) &&
> -		    page_referenced(page, 0, sc->mem_cgroup, &vm_flags))
> +		    page_referenced(page, 0, sc->mem_cgroup, &vm_flags)) {
>  			pgmoved++;
> +			/*
> +			 * Identify referenced, file-backed active pages and
> +			 * give them one more trip around the active list. So
> +			 * that executable code get better chances to stay in
> +			 * memory under moderate memory pressure.  Anon pages
> +			 * are ignored, since JVM can create lots of anon
> +			 * VM_EXEC pages.
> +			 */
> +			if ((vm_flags & VM_EXEC) && !PageAnon(page)) {
> +				list_add(&page->lru, &l_active);
> +				continue;
> +			}
> +		}
>  
>  		list_add(&page->lru, &l_inactive);
>  	}
> @@ -1282,7 +1296,6 @@ static void shrink_active_list(unsigned 
>  	 * Move the pages to the [file or anon] inactive list.
>  	 */
>  	pagevec_init(&pvec, 1);
> -	lru = LRU_BASE + file * LRU_FILE;
>  
>  	spin_lock_irq(&zone->lru_lock);
>  	/*
> @@ -1294,6 +1307,7 @@ static void shrink_active_list(unsigned 
>  	reclaim_stat->recent_rotated[!!file] += pgmoved;
>  
>  	pgmoved = 0;  /* count pages moved to inactive list */
> +	lru = LRU_BASE + file * LRU_FILE;
>  	while (!list_empty(&l_inactive)) {
>  		page = lru_to_page(&l_inactive);
>  		prefetchw_prev_lru_page(page, &l_inactive, flags);
> @@ -1316,6 +1330,29 @@ static void shrink_active_list(unsigned 
>  	__mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
>  	__count_zone_vm_events(PGREFILL, zone, pgscanned);
>  	__count_vm_events(PGDEACTIVATE, pgmoved);
> +
> +	pgmoved = 0;  /* count pages moved back to active list */
> +	lru = LRU_ACTIVE + file * LRU_FILE;
> +	while (!list_empty(&l_active)) {
> +		page = lru_to_page(&l_active);
> +		prefetchw_prev_lru_page(page, &l_active, flags);
> +		VM_BUG_ON(PageLRU(page));
> +		SetPageLRU(page);
> +		VM_BUG_ON(!PageActive(page));
> +
> +		list_move(&page->lru, &zone->lru[lru].list);
> +		mem_cgroup_add_lru_list(page, lru);
> +		pgmoved++;
> +		if (!pagevec_add(&pvec, page)) {
> +			spin_unlock_irq(&zone->lru_lock);
> +			if (buffer_heads_over_limit)
> +				pagevec_strip(&pvec);
> +			__pagevec_release(&pvec);
> +			spin_lock_irq(&zone->lru_lock);
> +		}
> +	}
> +	__mod_zone_page_state(zone, NR_LRU_BASE + lru, pgmoved);
> +
>  	spin_unlock_irq(&zone->lru_lock);
>  	if (buffer_heads_over_limit)
>  		pagevec_strip(&pvec);


-- 
Kinds Regards
Minchan Kim

--
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:[~2009-05-12  8:17 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                                         ` [PATCH -mm] vmscan: protect a fraction of file backed mapped pages from reclaim Christoph Lameter
2009-05-12 17:06                                           ` 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                                       ` Minchan Kim [this message]
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=20090512171729.3fe475d1.minchan.kim@barrios-desktop \
    --to=minchan.kim@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@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=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