提交 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) ...@@ -1863,6 +1863,9 @@ static inline void mem_cgroup_flush_foreign(struct bdi_writeback *wb)
#endif /* CONFIG_CGROUP_WRITEBACK */ #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; struct sock;
bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages); 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); void mem_cgroup_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages);
......
...@@ -96,6 +96,10 @@ bool cgroup_memory_noswap __read_mostly; ...@@ -96,6 +96,10 @@ bool cgroup_memory_noswap __read_mostly;
static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq); static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq);
#endif #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 */ /* Whether legacy memory+swap accounting is active */
static bool do_memsw_account(void) static bool do_memsw_account(void)
{ {
...@@ -2364,10 +2368,15 @@ static void high_work_func(struct work_struct *work) ...@@ -2364,10 +2368,15 @@ static void high_work_func(struct work_struct *work)
{ {
struct mem_cgroup *memcg; struct mem_cgroup *memcg;
current->flags |= PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD; if (mem_cgroup_kswapd_enabled) {
memcg = container_of(work, struct mem_cgroup, high_work); current->flags |= PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD;
reclaim_high(memcg, MEMCG_CHARGE_BATCH, GFP_KERNEL); memcg = container_of(work, struct mem_cgroup, high_work);
current->flags &= ~(PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD); 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) ...@@ -2537,11 +2546,17 @@ void mem_cgroup_handle_over_high(void)
* memory.high is currently batched, whereas memory.max and the page * memory.high is currently batched, whereas memory.max and the page
* allocator run every time an allocation is made. * allocator run every time an allocation is made.
*/ */
current->flags |= PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD; if (mem_cgroup_kswapd_enabled) {
nr_reclaimed = reclaim_high(memcg, current->flags |= PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD;
in_retry ? SWAP_CLUSTER_MAX : nr_pages, nr_reclaimed = reclaim_high(memcg,
GFP_KERNEL); in_retry ? SWAP_CLUSTER_MAX : nr_pages,
current->flags &= ~(PF_SWAPWRITE | PF_MEMALLOC | PF_KSWAPD); 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 * 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) ...@@ -5477,6 +5492,9 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
struct mem_cgroup *memcg, *old_memcg; struct mem_cgroup *memcg, *old_memcg;
long error = -ENOMEM; long error = -ENOMEM;
if (cgroup_memory_kswapd)
static_branch_enable(&memcg_kswapd_key);
old_memcg = set_active_memcg(parent); old_memcg = set_active_memcg(parent);
memcg = mem_cgroup_alloc(); memcg = mem_cgroup_alloc();
set_active_memcg(old_memcg); set_active_memcg(old_memcg);
...@@ -7280,6 +7298,13 @@ static int __init cgroup_memory(char *s) ...@@ -7280,6 +7298,13 @@ static int __init cgroup_memory(char *s)
} }
__setup("cgroup.memory=", cgroup_memory); __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. * subsys_initcall() for memory controller.
* *
......
...@@ -2843,8 +2843,9 @@ static bool is_memcg_kswapd_stopped(struct scan_control *sc) ...@@ -2843,8 +2843,9 @@ static bool is_memcg_kswapd_stopped(struct scan_control *sc)
bool is_stop = false; bool is_stop = false;
unsigned long stop_flag = 0; unsigned long stop_flag = 0;
if (!cgroup_reclaim(sc)) if (!cgroup_reclaim(sc) || !mem_cgroup_kswapd_enabled)
return false; return false;
if (memcg->memory.max == PAGE_COUNTER_MAX) if (memcg->memory.max == PAGE_COUNTER_MAX)
stop_flag = memcg->memory.high / 6; stop_flag = memcg->memory.high / 6;
else else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册