[Devel] [PATCH rh7 v3 7/8] oom: pass points and overdraft to oom_kill_process

Vladimir Davydov vdavydov at parallels.com
Sun Sep 13 06:42:09 PDT 2015


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 9063454d8e0b..15a07371a5e1 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1935,7 +1935,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;
 
 	/*
@@ -1987,8 +1987,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 a437f68e1a09..d8a89c0e0aa5 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);
 
 	/*
@@ -861,7 +864,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);
@@ -896,19 +900,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