memcg: simplify page cache charging
This patch is a clean up. No functional/logical changes.
Because of commit ef6a3c6311
("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 <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Miklos Szeredi <mszeredi@suse.cz>
Acked-by: Michal Hocko <mhocko@suse.cz>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: Ying Han <yinghan@google.com>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
de077d222d
commit
dc67d50465
1 changed files with 9 additions and 22 deletions
|
@ -2790,6 +2790,7 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
|
||||||
gfp_t gfp_mask)
|
gfp_t gfp_mask)
|
||||||
{
|
{
|
||||||
struct mem_cgroup *memcg = NULL;
|
struct mem_cgroup *memcg = NULL;
|
||||||
|
enum charge_type type = MEM_CGROUP_CHARGE_TYPE_CACHE;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (mem_cgroup_disabled())
|
if (mem_cgroup_disabled())
|
||||||
|
@ -2799,31 +2800,17 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
|
||||||
|
|
||||||
if (unlikely(!mm))
|
if (unlikely(!mm))
|
||||||
mm = &init_mm;
|
mm = &init_mm;
|
||||||
|
if (!page_is_file_cache(page))
|
||||||
|
type = MEM_CGROUP_CHARGE_TYPE_SHMEM;
|
||||||
|
|
||||||
if (page_is_file_cache(page)) {
|
if (!PageSwapCache(page)) {
|
||||||
ret = __mem_cgroup_try_charge(mm, gfp_mask, 1, &memcg, true);
|
ret = mem_cgroup_charge_common(page, mm, gfp_mask, type);
|
||||||
if (ret || !memcg)
|
WARN_ON_ONCE(PageLRU(page));
|
||||||
return ret;
|
} else { /* page is swapcache/shmem */
|
||||||
|
|
||||||
/*
|
|
||||||
* FUSE reuses pages without going through the final
|
|
||||||
* put that would remove them from the LRU list, make
|
|
||||||
* sure that they get relinked properly.
|
|
||||||
*/
|
|
||||||
__mem_cgroup_commit_charge_lrucare(page, memcg,
|
|
||||||
MEM_CGROUP_CHARGE_TYPE_CACHE);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/* shmem */
|
|
||||||
if (PageSwapCache(page)) {
|
|
||||||
ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &memcg);
|
ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &memcg);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
__mem_cgroup_commit_charge_swapin(page, memcg,
|
__mem_cgroup_commit_charge_swapin(page, memcg, type);
|
||||||
MEM_CGROUP_CHARGE_TYPE_SHMEM);
|
}
|
||||||
} else
|
|
||||||
ret = mem_cgroup_charge_common(page, mm, gfp_mask,
|
|
||||||
MEM_CGROUP_CHARGE_TYPE_SHMEM);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue