Skip to content

Commit dc67d50

Browse files
hkamezawatorvalds
authored andcommitted
memcg: simplify page cache charging
This patch is a clean up. No functional/logical changes. Because of commit ef6a3c6 ("mm: add replace_page_cache_page() function") , FUSE uses replace_page_cache() instead of add_to_page_cache(). Then, mem_cgroup_cache_charge() is not called against FUSE's pages from splice. So now, mem_cgroup_cache_charge() gets pages that are not on the LRU with the exception of PageSwapCache pages. For checking, WARN_ON_ONCE(PageLRU(page)) is added. Signed-off-by: KAMEZAWA Hiroyuki <[email protected]> Cc: Miklos Szeredi <[email protected]> Acked-by: Michal Hocko <[email protected]> Acked-by: Johannes Weiner <[email protected]> Cc: Ying Han <[email protected]> Cc: Hugh Dickins <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent de077d2 commit dc67d50

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

mm/memcontrol.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,7 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
27902790
gfp_t gfp_mask)
27912791
{
27922792
struct mem_cgroup *memcg = NULL;
2793+
enum charge_type type = MEM_CGROUP_CHARGE_TYPE_CACHE;
27932794
int ret;
27942795

27952796
if (mem_cgroup_disabled())
@@ -2799,31 +2800,17 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
27992800

28002801
if (unlikely(!mm))
28012802
mm = &init_mm;
2803+
if (!page_is_file_cache(page))
2804+
type = MEM_CGROUP_CHARGE_TYPE_SHMEM;
28022805

2803-
if (page_is_file_cache(page)) {
2804-
ret = __mem_cgroup_try_charge(mm, gfp_mask, 1, &memcg, true);
2805-
if (ret || !memcg)
2806-
return ret;
2807-
2808-
/*
2809-
* FUSE reuses pages without going through the final
2810-
* put that would remove them from the LRU list, make
2811-
* sure that they get relinked properly.
2812-
*/
2813-
__mem_cgroup_commit_charge_lrucare(page, memcg,
2814-
MEM_CGROUP_CHARGE_TYPE_CACHE);
2815-
return ret;
2816-
}
2817-
/* shmem */
2818-
if (PageSwapCache(page)) {
2806+
if (!PageSwapCache(page)) {
2807+
ret = mem_cgroup_charge_common(page, mm, gfp_mask, type);
2808+
WARN_ON_ONCE(PageLRU(page));
2809+
} else { /* page is swapcache/shmem */
28192810
ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &memcg);
28202811
if (!ret)
2821-
__mem_cgroup_commit_charge_swapin(page, memcg,
2822-
MEM_CGROUP_CHARGE_TYPE_SHMEM);
2823-
} else
2824-
ret = mem_cgroup_charge_common(page, mm, gfp_mask,
2825-
MEM_CGROUP_CHARGE_TYPE_SHMEM);
2826-
2812+
__mem_cgroup_commit_charge_swapin(page, memcg, type);
2813+
}
28272814
return ret;
28282815
}
28292816

0 commit comments

Comments
 (0)