Skip to content

Commit 0435a2f

Browse files
hnaztorvalds
authored andcommitted
mm: memcg: split swapin charge function into private and public part
When shmem is charged upon swapin, it does not need to check twice whether the memory controller is enabled. Also, shmem pages do not have to be checked for everything that regular anon pages have to be checked for, so let shmem use the internal version directly and allow future patches to move around checks that are only required when swapping in anon pages. 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>
1 parent 24467ca commit 0435a2f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

mm/memcontrol.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,18 +2801,14 @@ int mem_cgroup_newpage_charge(struct page *page,
28012801
* struct page_cgroup is acquired. This refcnt will be consumed by
28022802
* "commit()" or removed by "cancel()"
28032803
*/
2804-
int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
2805-
struct page *page,
2806-
gfp_t mask, struct mem_cgroup **memcgp)
2804+
static int __mem_cgroup_try_charge_swapin(struct mm_struct *mm,
2805+
struct page *page,
2806+
gfp_t mask,
2807+
struct mem_cgroup **memcgp)
28072808
{
28082809
struct mem_cgroup *memcg;
28092810
int ret;
28102811

2811-
*memcgp = NULL;
2812-
2813-
if (mem_cgroup_disabled())
2814-
return 0;
2815-
28162812
if (!do_swap_account)
28172813
goto charge_cur_mm;
28182814
/*
@@ -2839,6 +2835,15 @@ int mem_cgroup_try_charge_swapin(struct mm_struct *mm,
28392835
return ret;
28402836
}
28412837

2838+
int mem_cgroup_try_charge_swapin(struct mm_struct *mm, struct page *page,
2839+
gfp_t gfp_mask, struct mem_cgroup **memcgp)
2840+
{
2841+
*memcgp = NULL;
2842+
if (mem_cgroup_disabled())
2843+
return 0;
2844+
return __mem_cgroup_try_charge_swapin(mm, page, gfp_mask, memcgp);
2845+
}
2846+
28422847
void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg)
28432848
{
28442849
if (mem_cgroup_disabled())
@@ -2900,7 +2905,8 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
29002905
if (!PageSwapCache(page))
29012906
ret = mem_cgroup_charge_common(page, mm, gfp_mask, type);
29022907
else { /* page is swapcache/shmem */
2903-
ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &memcg);
2908+
ret = __mem_cgroup_try_charge_swapin(mm, page,
2909+
gfp_mask, &memcg);
29042910
if (!ret)
29052911
__mem_cgroup_commit_charge_swapin(page, memcg, type);
29062912
}

0 commit comments

Comments
 (0)