Skip to content

Commit 0c59b89

Browse files
hnaztorvalds
authored andcommitted
mm: memcg: push down PageSwapCache check into uncharge entry functions
Not all uncharge paths need to check if the page is swapcache, some of them can know for sure. Push down the check into all callsites of uncharge_common() so that the patch that removes some of them is more obvious. Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> 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> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> 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>
1 parent 5d84c77 commit 0c59b89

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

mm/memcontrol.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,8 +2987,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype,
29872987
if (mem_cgroup_disabled())
29882988
return NULL;
29892989

2990-
if (PageSwapCache(page))
2991-
return NULL;
2990+
VM_BUG_ON(PageSwapCache(page));
29922991

29932992
if (PageTransHuge(page)) {
29942993
nr_pages <<= compound_order(page);
@@ -3085,13 +3084,17 @@ void mem_cgroup_uncharge_page(struct page *page)
30853084
if (page_mapped(page))
30863085
return;
30873086
VM_BUG_ON(page->mapping && !PageAnon(page));
3087+
if (PageSwapCache(page))
3088+
return;
30883089
__mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_ANON, false);
30893090
}
30903091

30913092
void mem_cgroup_uncharge_cache_page(struct page *page)
30923093
{
30933094
VM_BUG_ON(page_mapped(page));
30943095
VM_BUG_ON(page->mapping);
3096+
if (PageSwapCache(page))
3097+
return;
30953098
__mem_cgroup_uncharge_common(page, MEM_CGROUP_CHARGE_TYPE_CACHE, false);
30963099
}
30973100

@@ -3156,6 +3159,8 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
31563159
if (!swapout) /* this was a swap cache but the swap is unused ! */
31573160
ctype = MEM_CGROUP_CHARGE_TYPE_DROP;
31583161

3162+
if (PageSwapCache(page))
3163+
return;
31593164
memcg = __mem_cgroup_uncharge_common(page, ctype, false);
31603165

31613166
/*
@@ -3345,10 +3350,11 @@ void mem_cgroup_end_migration(struct mem_cgroup *memcg,
33453350
unused = oldpage;
33463351
}
33473352
anon = PageAnon(used);
3348-
__mem_cgroup_uncharge_common(unused,
3349-
anon ? MEM_CGROUP_CHARGE_TYPE_ANON
3350-
: MEM_CGROUP_CHARGE_TYPE_CACHE,
3351-
true);
3353+
if (!PageSwapCache(unused))
3354+
__mem_cgroup_uncharge_common(unused,
3355+
anon ? MEM_CGROUP_CHARGE_TYPE_ANON
3356+
: MEM_CGROUP_CHARGE_TYPE_CACHE,
3357+
true);
33523358
css_put(&memcg->css);
33533359
/*
33543360
* We disallowed uncharge of pages under migration because mapcount

0 commit comments

Comments
 (0)