aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2012-07-31 19:45:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-31 21:42:49 -0400
commit90deb78839faedd194b65d419dbd9cba981e1922 (patch)
tree2262e84058ece104e056bbb3c90abe3e3684a709
parent0435a2fdcb50f8e53a67e98c27708e5d9396b71a (diff)
mm: memcg: only check swap cache pages for repeated charging
Only anon and shmem pages in the swap cache are attempted to be charged multiple times, from every swap pte fault or from shmem_unuse(). No other pages require checking PageCgroupUsed(). Charging pages in the swap cache is also serialized by the page lock, and since both the try_charge and commit_charge are called under the same page lock section, the PageCgroupUsed() check might as well happen before the counter charging, let alone reclaim. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Michal Hocko <mhocko@suse.cz> Cc: David Rientjes <rientjes@google.com> Cc: Hugh Dickins <hughd@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Wanpeng Li <liwp.linux@gmail.com> Cc: Mel Gorman <mel@csn.ul.ie> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/memcontrol.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4cc962d566ce..1a2020d72ca0 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2538,11 +2538,7 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *memcg,
2538 bool anon; 2538 bool anon;
2539 2539
2540 lock_page_cgroup(pc); 2540 lock_page_cgroup(pc);
2541 if (unlikely(PageCgroupUsed(pc))) { 2541 VM_BUG_ON(PageCgroupUsed(pc));
2542 unlock_page_cgroup(pc);
2543 __mem_cgroup_cancel_charge(memcg, nr_pages);
2544 return;
2545 }
2546 /* 2542 /*
2547 * we don't need page_cgroup_lock about tail pages, becase they are not 2543 * we don't need page_cgroup_lock about tail pages, becase they are not
2548 * accessed by any other context at this point. 2544 * accessed by any other context at this point.
@@ -2807,8 +2803,19 @@ static int __mem_cgroup_try_charge_swapin(struct mm_struct *mm,
2807 struct mem_cgroup **memcgp) 2803 struct mem_cgroup **memcgp)
2808{ 2804{
2809 struct mem_cgroup *memcg; 2805 struct mem_cgroup *memcg;
2806 struct page_cgroup *pc;
2810 int ret; 2807 int ret;
2811 2808
2809 pc = lookup_page_cgroup(page);
2810 /*
2811 * Every swap fault against a single page tries to charge the
2812 * page, bail as early as possible. shmem_unuse() encounters
2813 * already charged pages, too. The USED bit is protected by
2814 * the page lock, which serializes swap cache removal, which
2815 * in turn serializes uncharging.
2816 */
2817 if (PageCgroupUsed(pc))
2818 return 0;
2812 if (!do_swap_account) 2819 if (!do_swap_account)
2813 goto charge_cur_mm; 2820 goto charge_cur_mm;
2814 /* 2821 /*