linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mmotm] vmscan: fix may_swap handling for memcg
@ 2009-06-08  3:02 Daisuke Nishimura
  2009-06-08  3:20 ` KOSAKI Motohiro
  0 siblings, 1 reply; 14+ messages in thread
From: Daisuke Nishimura @ 2009-06-08  3:02 UTC (permalink / raw)
  To: LKML, linux-mm
  Cc: Andrew Morton, Johannes Weiner, Balbir Singh, KAMEZAWA Hiroyuki,
	KOSAKI Motohiro, Daisuke Nishimura

From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>

Commit 2e2e425989080cc534fc0fca154cae515f971cf5 ("vmscan,memcg: reintroduce
sc->may_swap) add may_swap flag and handle it at get_scan_ratio().

But the result of get_scan_ratio() is ignored when priority == 0, and this
means, when memcg hits the mem+swap limit, anon pages can be swapped
just in vain. Especially when memcg causes oom by mem+swap limit,
we can see many and many pages are swapped out.

Instead of not scanning anon lru completely when priority == 0, this patch adds
a hook to handle may_swap flag in shrink_page_list() to avoid using useless swaps,
and calls try_to_free_swap() if needed because it can reduce
both mem.usage and memsw.usage if the page(SwapCache) is unused anymore.

Such unused-but-managed-under-memcg SwapCache can be made in some paths,
for example trylock_page() failure in free_swap_cache().

Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
---
 mm/vmscan.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 2ddcfc8..d9a3f54 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -640,6 +640,25 @@ static unsigned long shrink_page_list(struct list_head *page_list,
 					referenced && page_mapping_inuse(page))
 			goto activate_locked;
 
+		if (!sc->may_swap && PageSwapBacked(page)) {
+			/* SwapCache has already uses swap entry */
+			if (!PageSwapCache(page))
+				goto keep_locked;
+			/*
+			 * From the view point of memcg, may_swap is false when
+			 * memsw.usage hits the limit.
+			 * But swaping out SwapCache to disk doesn't reduce the
+			 * memsw.usage, so it is a waste of time.
+			 * Call try_to_free_swap() if the page isn't used,
+			 * because it can reduce both mem.usage and memsw.usage.
+			 */
+			if (!scanning_global_lru(sc)) {
+				if (!page_mapped(page))
+					try_to_free_swap(page);
+				goto keep_locked;
+			}
+		}
+
 		/*
 		 * Anonymous process memory has backing store?
 		 * Try to allocate it some swap space here.

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-06-09  8:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-08  3:02 [PATCH mmotm] vmscan: fix may_swap handling for memcg Daisuke Nishimura
2009-06-08  3:20 ` KOSAKI Motohiro
2009-06-08  6:39   ` Daisuke Nishimura
2009-06-08  6:53     ` KOSAKI Motohiro
2009-06-08  7:54       ` Daisuke Nishimura
2009-06-09  7:13         ` [PATCH mmotm] vmscan: handle may_swap more strictly (Re: [PATCH mmotm] vmscan: fix may_swap handling for memcg) Daisuke Nishimura
2009-06-09  7:20           ` KOSAKI Motohiro
2009-06-09  7:48             ` Minchan Kim
2009-06-09  7:58               ` KOSAKI Motohiro
2009-06-09  8:19                 ` Minchan Kim
2009-06-09  8:24                   ` KOSAKI Motohiro
2009-06-09  8:35                     ` Minchan Kim
2009-06-09  8:37                       ` KOSAKI Motohiro
2009-06-09  7:28           ` KAMEZAWA Hiroyuki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox