introduce new attribute "priority" to control group
Subsystems (4)
v2 cover introduce new attribute "priority" to control group
From: Yulei Zhang <[email protected]>
Last time we introduce the idea of adding prioritized tasks management to control group. Sometimes we may assign the same amount of resources to multiple cgroups due to the environment restriction, but we still hope there are preference order to handle the tasks in those cgroups, the 'prio' attribute may help to do the ranking jobs.
The default value of "priority" is set to 0 which means the highest priority, and the totally levels of priority is defined by CGROUP_PRIORITY_MAX. Each subsystem could register callback to receive the priority change notification for their own purposes.
In this v2 patch we apply a simple rule to the oom hanlder base on the order of priority to demonstrate the intention about adding this attribute. When enable the prioritized oom, it will perfer to pick up the victim from the memory cgroup with lower priority, and try the best to keep the tasks alive in high ranked memcg.
V2->V1:
1. Introduce prioritized oom in memcg.
Lei Chen (1):
cgroup: add support for cgroup priority
Yulei Zhang (1):
memcg: introduce prioritized oom in memcg
include/linux/cgroup-defs.h | 2 + include/linux/cgroup.h | 2 + include/linux/memcontrol.h | 38 ++++++++++++++ include/linux/oom.h | 1 + kernel/cgroup/cgroup.c | 90 +++++++++++++++++++++++++++++++++ mm/memcontrol.c | 99 ++++++++++++++++++++++++++++++++++++- mm/oom_kill.c | 6 +-- 7 files changed, 233 insertions(+), 5 deletions(-)
Signature · 1 line
2.28.0
RFC v2 1/2 cgroup: add support for cgroup priority
In reply to a message not in the archiveFrom: Lei Chen <[email protected]>
Introduce new attribute "priority" to control group, which could be used as scale by subssytem to manipulate the behaviors of processes.
The default value of "priority" is set to 0 which means the highest priority, and the totally levels of priority is defined by CGROUP_PRIORITY_MAX.
--- include/linux/cgroup-defs.h | 2 + include/linux/cgroup.h | 2 + kernel/cgroup/cgroup.c | 90 +++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+)
include/linux/cgroup-defs.h +2 -0
@@ -417,6 +417,7 @@ struct cgroup {u16 subtree_ss_mask;u16 old_subtree_control;u16 old_subtree_ss_mask; +u16 priority;/* Private pointers for each registered subsystem */ struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT ];
@@ -640,6 +641,7 @@ struct cgroup_subsys {void (*exit)(struct task_struct *task);void (*release)(struct task_struct *task);void (*bind)(struct cgroup_subsys_state *root_css); +int (*css_priority_change)(struct cgroup_subsys_state *css,u16 old,u16 new); bool early_init:1;
include/linux/cgroup.h +2 -0
@@ -47,6 +47,7 @@ struct kernel_clone_args;/* internal flags */ #define CSS_TASK_ITER_SKIPPED (1U << 16) +#define CGROUP_PRIORITY_MAX 8/* a css_task_iter should be treated as an opaque object */ struct css_task_iter {
@@ -957,5 +958,6 @@ static inline void cgroup_bpf_get(struct cgroup *cgrp) {}static inline void cgroup_bpf_put (struct cgroup *cgrp) {}#endif /* CONFIG_CGROUP_BPF */ +ssize_t cgroup_priority (struct cgroup_subsys_state *css);#endif /* _LINUX_CGROUP_H */
kernel/cgroup/cgroup.c +90 -0
114 lines not on this page · raw message
Signature · 1 line
2.28.0
RFC v2 2/2 memcg: introduce prioritized oom in memcg
In reply to a message not in the archiveFrom: Yulei Zhang <[email protected]>
In current implementation when memcg oom happens it will select victim from the memcg hierarchy, with the assistant of priority attribute in the first patch, it will be able to select the victim in memcg with the order from low to high priority, and try the best to keep the high priority tasks survived from oom.
A new trigger memory.use_priority_oom is introduced to contorl the enabling of the policy. And for global oom it will check the memory.use_priority_oom setting in root memcg, by default this is disabled.
--- include/linux/memcontrol.h | 38 +++++++++++++++ include/linux/oom.h | 1 + mm/memcontrol.c | 99 +++++++++++++++++++++++++++++++++++++- mm/oom_kill.c | 6 +-- 4 files changed, 139 insertions(+), 5 deletions(-)
include/linux/memcontrol.h +38 -0
@@ -27,6 +27,7 @@ struct obj_cgroup;struct page ;struct mm_struct ;struct kmem_cache ; +struct oom_control ;/* Cgroup-specific page state, on top of universal node page state */ enum memcg_stat_item {
@@ -253,6 +254,9 @@ struct mem_cgroup {bool oom_lock;int under_oom; +/* memcg priority */ +bool use_priority_oom; +int swappiness;/* OOM-Killer disable */ int oom_kill_disable;
@@ -812,6 +816,24 @@ static inline bool mem_cgroup_online(struct mem_cgroup *memcg)return !!(memcg->css.flags &CSS_ONLINE ); } +/* +* memcg priority +*/ +void mem_cgroup_select_bad_process (struct oom_control *oc); + +void mem_cgroup_oom_select_bad_process (struct oom_control *oc); + +static inline bool root_memcg_use_priority_oom (void ) +{ +if (mem_cgroup_disabled ()) +return false; + +if (root_mem_cgroup->use_priority_oom) +return true; + +return false; +} +/* * For memory reclaim. */
@@ -1262,6 +1284,22 @@ static inline bool mem_cgroup_online(struct mem_cgroup *memcg)return true; } +/* +* memcg priority +*/ +static inline void mem_cgroup_select_bad_process (struct oom_control *oc) +{ +} + +static inline void mem_cgroup_oom_select_bad_process (struct oom_control *oc) +{ +} + +static inline bool root_memcg_use_priority_oom (void ) +{ +return false; +} +static inline unsigned long mem_cgroup_get_zone_lru_size (struct lruvec *lruvec,enum lru_list lru,int zone_idx)
include/linux/oom.h +1 -0
@@ -121,6 +121,7 @@ extern int unregister_oom_notifier(struct notifier_block *nb);extern bool oom_killer_disable (signed long timeout);extern void oom_killer_enable (void ); +extern int oom_evaluate_task (struct task_struct *task,void *arg);extern struct task_struct *find_lock_task_mm (struct task_struct *p);/* sysctls */
mm/memcontrol.c +97 -2
129 lines not on this page · raw message
mm/oom_kill.c +3 -3
@@ -307,7 +307,7 @@ static enum oom_constraint constrained_alloc(struct oom_control *oc)return CONSTRAINT_NONE ; } -static int oom_evaluate_task (struct task_struct *task,void *arg) +int oom_evaluate_task (struct task_struct *task,void *arg) {struct oom_control *oc = arg;long points;
@@ -367,8 +367,8 @@ static void select_bad_process(struct oom_control *oc) { oc->chosen_points =LONG_MIN ; -if (is_memcg_oom (oc)) -mem_cgroup_scan_tasks (oc->memcg, oom_evaluate_task, oc); +if (is_memcg_oom (oc) ||root_memcg_use_priority_oom ()) +mem_cgroup_oom_select_bad_process (oc);else {struct task_struct *p;
Signature · 1 line
2.28.0
Quoted 13 lines · On Tue, Apr 13, 2021 at 12:40:09AM +0800…
From: Yulei Zhang <[email protected]>
Last time we introduce the idea of adding prioritized tasks management to control group. Sometimes we may assign the same amount of resources to multiple cgroups due to the environment restriction, but we still hope there are preference order to handle the tasks in those cgroups, the 'prio' attribute may help to do the ranking jobs.
The default value of "priority" is set to 0 which means the highest priority, and the totally levels of priority is defined by
CGROUP_PRIORITY_MAX. Each subsystem could register callback to receive the priority change notification for their own purposes.
Quoted 5 lines
In this v2 patch we apply a simple rule to the oom hanlder base on the order of priority to demonstrate the intention about adding this attribute. When enable the prioritized oom, it will perfer to pick up the victim from the memory cgroup with lower priority, and try the best to keep the tasks alive in high ranked memcg.
I don't think the discussion in the previous thread led anywhere. Please consider this series nacked for now.
Thanks.
Signature · 1 line
tejun