From: Liu Shixin liushixin2@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8QK6Q CVE: NA
--------------------------------
Introduce memcg swap qos including subsequent sub-features. Add CONFIG_MEMCG_SWAP_QOS and static key memcg_swap_qos_key.
Signed-off-by: Liu Shixin liushixin2@huawei.com Signed-off-by: Jinjiang Tu tujinjiang@huawei.com --- include/linux/memcontrol.h | 4 ++++ init/Kconfig | 9 +++++++ mm/memcontrol.c | 48 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 31aff8b9286a..578f43b68392 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -367,6 +367,10 @@ static inline void memcg_print_bad_task(struct oom_control *oc) } #endif
+#ifdef CONFIG_MEMCG_SWAP_QOS +DECLARE_STATIC_KEY_FALSE(memcg_swap_qos_key); +#endif + /* * size of first charge trial. * TODO: maybe necessary to use big numbers in big irons or dynamic based of the diff --git a/init/Kconfig b/init/Kconfig index 869eea4108d0..3d7a992a6b57 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -973,6 +973,15 @@ config MEMCG_OOM_PRIORITY
If unsure, say "n".
+config MEMCG_SWAP_QOS + bool "Enable Memory Cgroup Swap Control" + depends on MEMCG && SWAP + depends on X86 || ARM64 + default n + help + memcg swap control include memory force swapin, swapfile control + and swap limit. + config MEMCG_KMEM bool depends on MEMCG diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a707014b644d..98fea5dacd40 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4236,6 +4236,43 @@ static int sysctl_memcg_oom_prio_handler(struct ctl_table *table, int write, #endif #endif
+#ifdef CONFIG_MEMCG_SWAP_QOS +DEFINE_STATIC_KEY_FALSE(memcg_swap_qos_key); + +#ifdef CONFIG_SYSCTL +static int sysctl_memcg_swap_qos_stat; + +static void memcg_swap_qos_reset(void) +{ +} + +static int sysctl_memcg_swap_qos_handler(struct ctl_table *table, int write, + void __user *buffer, size_t *length, loff_t *ppos) +{ + int ret; + int qos_stat_old = sysctl_memcg_swap_qos_stat; + + ret = proc_dointvec_minmax(table, write, buffer, length, ppos); + if (ret) + return ret; + + if (write) { + if (qos_stat_old == sysctl_memcg_swap_qos_stat) + return 0; + + if (sysctl_memcg_swap_qos_stat) { + memcg_swap_qos_reset(); + static_branch_enable(&memcg_swap_qos_key); + } else { + static_branch_disable(&memcg_swap_qos_key); + } + } + + return 0; +} +#endif +#endif + #ifdef CONFIG_NUMA
#define LRU_ALL_FILE (BIT(LRU_INACTIVE_FILE) | BIT(LRU_ACTIVE_FILE)) @@ -8022,6 +8059,17 @@ static struct ctl_table mem_cgroup_sysctls[] = { .extra2 = SYSCTL_ONE, }, #endif +#ifdef CONFIG_MEMCG_SWAP_QOS + { + .procname = "memcg_swap_qos_enable", + .data = &sysctl_memcg_swap_qos_stat, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = sysctl_memcg_swap_qos_handler, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif };
static __init int mem_cgroup_sysctls_init(void)