提交 84355bcc 编写于 作者: L Lu Jialin 提交者: Zheng Zengkai

memcg: Add static key for memcg kswapd

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I4IMAK?from=project-issue
CVE: NA

--------

This patch adds a default-false static key to disable memcg kswapd
feature. User can enable by set memcg_kswapd in cmdline.
Signed-off-by: NLu Jialin <lujialin4@huawei.com>
Reviewed-by: Nweiyang wang <wangweiyang2@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 70d020ae
......@@ -1863,6 +1863,9 @@ static inline void mem_cgroup_flush_foreign(struct bdi_writeback *wb)
#endif /* CONFIG_CGROUP_WRITEBACK */
extern struct static_key_false memcg_kswapd_key;
#define mem_cgroup_kswapd_enabled static_branch_unlikely(&memcg_kswapd_key)
struct sock;
bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages);
void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages);
......
......@@ -96,6 +96,10 @@ bool cgroup_memory_noswap __read_mostly;
static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq);
#endif
static bool cgroup_memory_kswapd = false;
DEFINE_STATIC_KEY_FALSE(memcg_kswapd_key);
EXPORT_SYMBOL(memcg_kswapd_key);
/* Whether legacy memory+swap accounting is active */
static bool do_memsw_account(void)
{
......@@ -2364,10 +2368,15 @@ static void high_work_func(struct work_struct *work)
{
struct mem_cgroup *memcg;
if (mem_cgroup_kswapd_enabled) {
current->flags |= PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD;
memcg = container_of(work, struct mem_cgroup, high_work);
reclaim_high(memcg, MEMCG_CHARGE_BATCH, GFP_KERNEL);
current->flags &= ~(PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD);
} else {
memcg = container_of(work, struct mem_cgroup, high_work);
reclaim_high(memcg, MEMCG_CHARGE_BATCH, GFP_KERNEL);
}
}
/*
......@@ -2537,11 +2546,17 @@ void mem_cgroup_handle_over_high(void)
* memory.high is currently batched, whereas memory.max and the page
* allocator run every time an allocation is made.
*/
if (mem_cgroup_kswapd_enabled) {
current->flags |= PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD;
nr_reclaimed = reclaim_high(memcg,
in_retry ? SWAP_CLUSTER_MAX : nr_pages,
GFP_KERNEL);
current->flags &= ~(PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD);
} else {
nr_reclaimed = reclaim_high(memcg,
in_retry ? SWAP_CLUSTER_MAX : nr_pages,
GFP_KERNEL);
}
/*
* memory.high is breached and reclaim is unable to keep up. Throttle
......@@ -5477,6 +5492,9 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
struct mem_cgroup *memcg, *old_memcg;
long error = -ENOMEM;
if (cgroup_memory_kswapd)
static_branch_enable(&memcg_kswapd_key);
old_memcg = set_active_memcg(parent);
memcg = mem_cgroup_alloc();
set_active_memcg(old_memcg);
......@@ -7280,6 +7298,13 @@ static int __init cgroup_memory(char *s)
}
__setup("cgroup.memory=", cgroup_memory);
static int __init memcg_kswapd(char *s)
{
cgroup_memory_kswapd = true;
return 0;
}
__setup("memcg_kswapd", memcg_kswapd);
/*
* subsys_initcall() for memory controller.
*
......
......@@ -2843,8 +2843,9 @@ static bool is_memcg_kswapd_stopped(struct scan_control *sc)
bool is_stop = false;
unsigned long stop_flag = 0;
if (!cgroup_reclaim(sc))
if (!cgroup_reclaim(sc) || !mem_cgroup_kswapd_enabled)
return false;
if (memcg->memory.max == PAGE_COUNTER_MAX)
stop_flag = memcg->memory.high / 6;
else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册