[Devel] [PATCH rh7 5/6] oom: pass points and overdraft to oom_kill_process
Vladimir Davydov
vdavydov at virtuozzo.com
Thu Jan 28 07:00:14 PST 2016
From: Vladimir Davydov <vdavydov at parallels.com>
Patchset description: oom enhancements - part 2
- Patches 1-2 prepare memcg for upcoming changes in oom design.
- Patch 3 reworks oom locking design so that the executioner waits for
victim to exit. This is necessary to increase oom kill rate, which is
essential for berserker mode.
- Patch 4 drops unused OOM_SCAN_ABORT
- Patch 5 introduces oom timeout.
https://jira.sw.ru/browse/PSBM-38581
- Patch 6 makes oom fairer when it comes to selecting a victim among
different containers.
https://jira.sw.ru/browse/PSBM-37915
- Patch 7 prepares oom for introducing berserker mode
- Patch 8 resurrects oom berserker mode, which is supposed to cope with
actively forking processes.
https://jira.sw.ru/browse/PSBM-17930
https://jira.sw.ru/browse/PSBM-26973
Changes in v3:
- rework oom_trylock (patch 3)
- select exiting process instead of aborting oom scan so as not to keep
busy-waiting for an exiting process to exit (patches 3, 4)
- cleanup oom timeout handling + fix stuck process trace dumped
multiple times on timeout (patch 5)
- set max_overdraft to ULONG_MAX on selected processes (patch 6)
- rework oom berserker process selection logic (patches 7, 8)
Changes in v2:
- s/time_after/time_after_eq to avoid BUG_ON in oom_trylock (patch 4)
- propagate victim to the context that initiated oom in oom_unlock
(patch 6)
- always set oom_end on releasing oom context (patch 6)
Vladimir Davydov (8):
memcg: add mem_cgroup_get/put helpers
memcg: add lock for protecting memcg->oom_notify list
oom: rework locking design
oom: introduce oom timeout
oom: drop OOM_SCAN_ABORT
oom: rework logic behind memory.oom_guarantee
oom: pass points and overdraft to oom_kill_process
oom: resurrect berserker mode
Reviewed-by: Kirill Tkhai <ktkhai at odin.com>
=========================================
This patch description:
This is required by oom berserker mode, which will be introduced later
in this series.
Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
include/linux/oom.h | 3 ++-
mm/memcontrol.c | 6 +++---
mm/oom_kill.c | 26 ++++++++++++++++----------
3 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/include/linux/oom.h b/include/linux/oom.h
index 9117d1df385e..6ea83b260aab 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -85,7 +85,8 @@ static inline bool oom_worse(unsigned long points, unsigned long overdraft,
}
extern void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
- unsigned int points, unsigned long totalpages,
+ unsigned long points, unsigned long overdraft,
+ unsigned long totalpages,
struct mem_cgroup *memcg, nodemask_t *nodemask,
const char *message);
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5be42a770b9d..fa78588243da 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1999,7 +1999,7 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
unsigned long chosen_points = 0;
unsigned long totalpages;
unsigned long overdraft;
- unsigned int points = 0;
+ unsigned long points = 0;
struct task_struct *chosen = NULL;
/*
@@ -2051,8 +2051,8 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
if (!chosen)
return;
- points = chosen_points * 1000 / totalpages;
- oom_kill_process(chosen, gfp_mask, order, points, totalpages, memcg,
+ oom_kill_process(chosen, gfp_mask, order, chosen_points, max_overdraft,
+ totalpages, memcg,
NULL, "Memory cgroup out of memory");
}
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index bea7a2a555b2..a56c9a942beb 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -353,7 +353,8 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
*
* (not docbooked, we don't want this one cluttering up the manual)
*/
-static struct task_struct *select_bad_process(unsigned int *ppoints,
+static struct task_struct *select_bad_process(unsigned long *ppoints,
+ unsigned long *poverdraft,
unsigned long totalpages, const nodemask_t *nodemask,
bool force_kill)
{
@@ -389,7 +390,8 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
get_task_struct(chosen);
rcu_read_unlock();
- *ppoints = chosen_points * 1000 / totalpages;
+ *ppoints = chosen_points;
+ *poverdraft = max_overdraft;
return chosen;
}
@@ -694,7 +696,8 @@ void oom_unlock(struct mem_cgroup *memcg)
* returning.
*/
void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
- unsigned int points, unsigned long totalpages,
+ unsigned long points, unsigned long overdraft,
+ unsigned long totalpages,
struct mem_cgroup *memcg, nodemask_t *nodemask,
const char *message)
{
@@ -723,8 +726,8 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
dump_header(p, gfp_mask, order, memcg, nodemask);
task_lock(p);
- pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
- message, task_pid_nr(p), p->comm, points);
+ pr_err("%s: Kill process %d (%s) score %lu or sacrifice child\n",
+ message, task_pid_nr(p), p->comm, points * 1000 / totalpages);
task_unlock(p);
/*
@@ -864,7 +867,8 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
struct task_struct *p;
unsigned long totalpages;
unsigned long freed = 0;
- unsigned int uninitialized_var(points);
+ unsigned long uninitialized_var(points);
+ unsigned long uninitialized_var(overdraft);
enum oom_constraint constraint = CONSTRAINT_NONE;
blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
@@ -899,19 +903,21 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
!oom_unkillable_task(current, NULL, nodemask) &&
current->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) {
get_task_struct(current);
- oom_kill_process(current, gfp_mask, order, 0, totalpages, NULL,
- nodemask,
+ oom_kill_process(current, gfp_mask, order, 0, 0, totalpages,
+ NULL, nodemask,
"Out of memory (oom_kill_allocating_task)");
return;
}
- p = select_bad_process(&points, totalpages, mpol_mask, force_kill);
+ p = select_bad_process(&points, &overdraft, totalpages, mpol_mask,
+ force_kill);
/* Found nothing?!?! Either we hang forever, or we panic. */
if (!p) {
dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
panic("Out of memory and no killable processes...\n");
} else
- oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
+ oom_kill_process(p, gfp_mask, order, points, overdraft,
+ totalpages, NULL,
nodemask, "Out of memory");
}
--
2.1.4
More information about the Devel
mailing list