[PATCH] memcg: handle shmem's swap cache (Was 2.6.26-rc8-mm1

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andrew Morton <akpm@...>
Cc: <linux-kernel@...>, <linux-mm@...>, hugh@veritas.com <hugh@...>, balbir@linux.vnet.ibm.com <balbir@...>, nishimura@mxp.nes.nec.co.jp <nishimura@...>, yamamoto@valinux.co.jp <yamamoto@...>
Date: Friday, July 4, 2008 - 5:09 am

My swapcache accounting under memcg patch failed to catch tmpfs(shmem)'s one.
Can I test this under -mm tree ?
(If -mm is busy, I'm not in hurry.)
This patch works well in my box.
=
SwapCache handling fix.

shmem's swapcache behavior is a little different from anonymous's one and
memcg failed to handle it. This patch tries to fix it.

After this:

Any page marked as SwapCache is not uncharged. (delelte_from_swap_cache()
delete the SwapCache flag.)

To check a shmem-page-cache is alive or not we use
 page->mapping && !PageAnon(page) instead of
 pc->flags & PAGE_CGROUP_FLAG_CACHE.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

Index: test-2.6.26-rc8-mm1/mm/memcontrol.c
===================================================================
--- test-2.6.26-rc8-mm1.orig/mm/memcontrol.c
+++ test-2.6.26-rc8-mm1/mm/memcontrol.c
@@ -687,11 +687,45 @@ __mem_cgroup_uncharge_common(struct page
 
 	VM_BUG_ON(pc->page != page);
 
-	if ((ctype == MEM_CGROUP_CHARGE_TYPE_MAPPED)
-	    && ((pc->flags & PAGE_CGROUP_FLAG_CACHE)
-		|| page_mapped(page)
-		|| PageSwapCache(page)))
+	/*
+	 * File Cache
+	 * If called with MEM_CGROUP_CHARGE_TYPE_MAPPED, check page->mapping.
+	 * add_to_page_cache() .... charged before inserting radix-tree.
+	 * remove_from_page_cache() .... uncharged at removing from radix-tree.
+	 * page->mapping && !PageAnon(page) catches file cache.
+	 *
+	 * Anon/Shmem.....We check PageSwapCache(page).
+	 * Anon .... charged before mapped.
+	 * Shmem .... charged at add_to_page_cache() as usual File Cache.
+	 *
+	 * This page will be finally uncharged when removed from swap-cache
+	 *
+	 * we treat 2 cases here.
+	 * A. anonymous page  B. shmem.
+	 * We never uncharge if page is marked as SwapCache.
+	 * add_to_swap_cache() have nothing to do with charge/uncharge.
+	 * SwapCache flag is deleted before delete_from_swap_cache() calls this
+	 *
+	 * shmem's behavior is following. (see shmem.c/swap_state.c also)
+	 * at swap-out:
+	 * 	0. add_to_page_cache()//charged at page creation.
+	 * 	1. add_to_swap_cache() (marked as SwapCache)
+	 *	2. remove_from_page_cache().  (calls this.)
+	 *	(finally) delete_from_swap_cache(). (calls this.)
+	 * at swap-in:
+	 * 	3. add_to_swap_cache() (no charge here.)
+	 * 	4. add_to_page_cache() (charged here.)
+	 * 	5. delete_from_swap_cache() (calls this.)
+	 * PageSwapCache(page) catches "2".
+	 * page->mapping && !PageAnon() catches "5" and avoid uncharging.
+	 */
+	if (PageSwapCache(page))
 		goto unlock;
+	/* called from unmap or delete_from_swap_cache() */
+	if ((ctype == MEM_CGROUP_CHARGE_TYPE_MAPPED)
+		&& (page_mapped(page)
+		    || (page->mapping && !PageAnon(page))))/* alive cache ? */
+			goto unlock;
 
 	mz = page_cgroup_zoneinfo(pc);
 	spin_lock_irqsave(&mz->lru_lock, flags);

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
2.6.26-rc8-mm1, Andrew Morton, (Thu Jul 3, 5:02 am)
Re: 2.6.26-rc8-mm1 - Missing AC97 power save Kconfig?, Randy Dunlap, (Wed Jul 9, 6:05 pm)
Re: 2.6.26-rc8-mm1: unable to mount nfs shares, Mariusz Kozlowski, (Fri Jul 4, 6:49 pm)
Re: 2.6.26-rc8-mm1: unable to mount nfs shares, Andrew Morton, (Fri Jul 4, 7:07 pm)
[PATCH] memcg: handle shmem's swap cache (Was 2.6.26-rc8-mm1, KAMEZAWA Hiroyuki, (Fri Jul 4, 5:09 am)
memcg: lru scan fix (Was: 2.6.26-rc8-mm1, KAMEZAWA Hiroyuki, (Fri Jul 4, 5:02 am)
Re: memcg: lru scan fix (Was: 2.6.26-rc8-mm1, Rik van Riel, (Fri Jul 4, 3:16 pm)
Re: memcg: lru scan fix (Was: 2.6.26-rc8-mm1, Andrew Morton, (Fri Jul 4, 3:24 pm)
Re: memcg: lru scan fix (Was: 2.6.26-rc8-mm1, KAMEZAWA Hiroyuki, (Fri Jul 4, 11:59 pm)
Question: split-lur // Re: 2.6.26-rc8-mm1, KAMEZAWA Hiroyuki, (Thu Jul 3, 10:48 pm)
Re: [BUILD-FAILURE] 2.6.26-rc8-mm1 - x86 - __ptep_modify_pro..., Jeremy Fitzhardinge, (Thu Jul 3, 2:00 pm)
[bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", KOSAKI Motohiro, (Thu Jul 3, 7:59 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", David Woodhouse, (Fri Jul 4, 10:13 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Arjan van de Ven, (Fri Jul 4, 4:42 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Arjan van de Ven, (Fri Jul 4, 4:59 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", David Woodhouse, (Fri Jul 4, 10:31 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", maximilian attems, (Fri Jul 4, 10:24 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", maximilian attems, (Sat Jul 5, 6:26 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Hannes Reinecke, (Fri Jul 4, 10:39 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", David Woodhouse, (Fri Jul 4, 10:42 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Olivier Galibert, (Fri Jul 4, 7:13 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Olivier Galibert, (Sat Jul 5, 6:53 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Olivier Galibert, (Sat Jul 5, 8:02 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Christoph Hellwig, (Sat Jul 5, 1:13 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Christoph Hellwig, (Sun Jul 6, 6:02 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Olivier Galibert, (Sat Jul 5, 10:44 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", David Woodhouse, (Sat Jul 5, 11:10 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Henrique de Moraes Holschuh..., (Fri Jul 4, 7:58 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Henrique de Moraes Holschuh..., (Fri Jul 4, 11:52 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Henrique de Moraes Holschuh..., (Sat Jul 5, 9:08 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", David Woodhouse, (Fri Jul 4, 10:37 am)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Mikael Pettersson, (Thu Jul 3, 10:31 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Rafael J. Wysocki, (Thu Jul 3, 5:42 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Rafael J. Wysocki, (Thu Jul 3, 5:52 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Rafael J. Wysocki, (Thu Jul 3, 6:27 pm)
Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin", Rafael J. Wysocki, (Thu Jul 3, 4:52 pm)