FROMLIST: mm, memcg: add mem_cgroup_disabled checks in vmpressure and swap-related functions

Add mem_cgroup_disabled check in vmpressure, mem_cgroup_uncharge_swap and
cgroup_throttle_swaprate functions. This minimizes the memcg overhead in
the pagefault and exit_mmap paths when memcgs are disabled using
cgroup_disable=memory command-line option.
This change results in ~2.1% overhead reduction when running PFT test [1]
comparing {CONFIG_MEMCG=n, CONFIG_MEMCG_SWAP=n} against {CONFIG_MEMCG=y,
CONFIG_MEMCG_SWAP=y, cgroup_disable=memory} configuration on an 8-core
ARM64 Android device.

[1] https://lkml.org/lkml/2006/8/29/294 also used in mmtests suite

Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>

Link: https://lore.kernel.org/patchwork/patch/1458906/
Bug: 191223209
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ic1fc75eb1e4d7a9848cf641b9f232ad3262c490b
This commit is contained in:
Suren Baghdasaryan 2021-07-02 16:58:43 -07:00
parent 669df367a9
commit f73d029485
3 changed files with 12 additions and 1 deletions

View File

@ -7322,6 +7322,9 @@ void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages)
struct mem_cgroup *memcg;
unsigned short id;
if (mem_cgroup_disabled())
return;
id = swap_cgroup_record(entry, 0, nr_pages);
rcu_read_lock();
memcg = mem_cgroup_from_id(id);

View File

@ -3818,6 +3818,9 @@ void cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask)
struct swap_info_struct *si, *next;
int nid = page_to_nid(page);
if (mem_cgroup_disabled())
return;
if (!(gfp_mask & __GFP_IO))
return;

View File

@ -242,9 +242,14 @@ static void vmpressure_work_fn(struct work_struct *work)
void vmpressure(gfp_t gfp, struct mem_cgroup *memcg, bool tree,
unsigned long scanned, unsigned long reclaimed)
{
struct vmpressure *vmpr = memcg_to_vmpressure(memcg);
struct vmpressure *vmpr;
bool bypass = false;
if (mem_cgroup_disabled())
return;
vmpr = memcg_to_vmpressure(memcg);
trace_android_vh_vmpressure(memcg, &bypass);
if (unlikely(bypass))
return;