Skip to contentSkip to conversation

various OOM bugfixes v3

PATCH In review KOSAKI Motohiro 5 participants 36 messages Jun 30, 2010 – Jul 7, 2010

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

cover various OOM bugfixes v3

Hi

Here is updated series for various OOM fixes.
Almost fixes are trivial.

One big improvement is Luis's dying task priority boost patch. This is necessary for RT folks.

oom: don't try to kill oom_unkillable child
oom: oom_kill_process() doesn't select kthread child
oom: make oom_unkillable_task() helper function
oom: oom_kill_process() need to check p is unkillable
oom: /proc/<pid>/oom_score treat kernel thread honestly
oom: kill duplicate OOM_DISABLE check
oom: move OOM_DISABLE check from oom_kill_task to out_of_memory()
oom: cleanup has_intersects_mems_allowed()
oom: remove child->mm check from oom_kill_process()
oom: give the dying task a higher priority
oom: multi threaded process coredump don't make deadlock

 fs/proc/base.c |    5 ++-
 mm/oom_kill.c  |  100 +++++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 73 insertions(+), 32 deletions(-)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

PATCH 1/11 oom: don't try to kill oom_unkillable child

Now, badness() doesn't care neigher CPUSET nor mempolicy. Then if the victim child process have disjoint nodemask, OOM Killer might kill innocent process.

This patch fixes it.

---
 mm/oom_kill.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
mm/oom_kill.c +6 -4
index 26ae697..0aeacb2 100644
@@ -429,7 +429,7 @@ static int oom_kill_task(struct task_struct *p)
 
 static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 			    unsigned long points, struct mem_cgroup *mem,
-			    const char *message)
+			    nodemask_t *nodemask, const char *message)
 {
 	struct task_struct *victim = p;
 	struct task_struct *child;
@@ -469,6 +469,8 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 				continue;
 			if (mem && !task_in_mem_cgroup(child, mem))
 				continue;
+			if (!has_intersects_mems_allowed(child, nodemask))
+				continue;
 
 			/* badness() returns 0 if the thread is unkillable */
 			child_points = badness(child, uptime.tv_sec);
@@ -519,7 +521,7 @@ retry:
 	if (!p || PTR_ERR(p) == -1UL)
 		goto out;
 
-	if (oom_kill_process(p, gfp_mask, 0, points, mem,
+	if (oom_kill_process(p, gfp_mask, 0, points, mem, NULL,
 				"Memory cgroup out of memory"))
 		goto retry;
 out:
@@ -678,7 +680,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 		 * non-zero, current could not be killed so we must fallback to
 		 * the tasklist scan.
 		 */
-		if (!oom_kill_process(current, gfp_mask, order, 0, NULL,
+		if (!oom_kill_process(current, gfp_mask, order, 0, NULL, nodemask,
 				"Out of memory (oom_kill_allocating_task)"))
 			return;
 	}
@@ -697,7 +699,7 @@ retry:
 		panic("Out of memory and no killable processes...\n");
 	}
 
-	if (oom_kill_process(p, gfp_mask, order, points, NULL,
+	if (oom_kill_process(p, gfp_mask, order, points, NULL, nodemask,
 			     "Out of memory"))
 		goto retry;
 	read_unlock(&tasklist_lock);
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH 2/11 oom: oom_kill_process() doesn't select kthread child

In reply to KOSAKI Motohiro

Now, select_bad_process() have PF_KTHREAD check, but oom_kill_process doesn't. It mean oom_kill_process() may choose wrong task, especially, when the child are using use_mm().

---
 mm/oom_kill.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
mm/oom_kill.c +2 -0
index 0aeacb2..dc8589e 100644
@@ -467,6 +467,8 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 
 			if (child->mm == p->mm)
 				continue;
+			if (child->flags & PF_KTHREAD)
+				continue;
 			if (mem && !task_in_mem_cgroup(child, mem))
 				continue;
 			if (!has_intersects_mems_allowed(child, nodemask))
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Re: [PATCH 02/11] oom: oom_kill_process() doesn't select kthread child

Quoted 3 lines · KOSAKI Motohiro

Now, select_bad_process() have PF_KTHREAD check, but oom_kill_process doesn't. It mean oom_kill_process() may choose wrong task, especially, when the child are using use_mm().

Is it possible child is kthread even though parent isn't kthread?

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw

Re: [PATCH 02/11] oom: oom_kill_process() doesn't select kthread child

Quoted 6 lines · KOSAKI Motohiro
Quoted 3 lines

Now, select_bad_process() have PF_KTHREAD check, but oom_kill_process doesn't. It mean oom_kill_process() may choose wrong task, especially, when the child are using use_mm().

Is it possible child is kthread even though parent isn't kthread?

Usually unhappen. but crappy driver can do any strange thing freely. As I said, oom code should have conservative assumption as far as possible.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by
#5 lore raw

Re: [PATCH 02/11] oom: oom_kill_process() doesn't select kthread child

Quoted 9 lines · KOSAKI Motohiro
Quoted 6 lines · KOSAKI Motohiro
Quoted 3 lines

Now, select_bad_process() have PF_KTHREAD check, but oom_kill_process doesn't. It mean oom_kill_process() may choose wrong task, especially, when the child are using use_mm().

Is it possible child is kthread even though parent isn't kthread?

Usually unhappen. but crappy driver can do any strange thing freely. As I said, oom code should have conservative assumption as far as possible.

Okay. You change the check with oom_unkillable_task at last. The oom_unkillable_task is generic function so that the kthread check in oom_kill_process is tivial, I think.

Quoted 3 lines
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw

PATCH 3/11 oom: make oom_unkillable_task() helper function

In reply to KOSAKI Motohiro

Now, we have the same task check in two places. Unify it.

---
 mm/oom_kill.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)
mm/oom_kill.c +22 -11
index dc8589e..a4a5439 100644
@@ -101,6 +101,26 @@ static struct task_struct *find_lock_task_mm(struct task_struct *p)
 	return NULL;
 }
 
+/* return true if the task is not adequate as candidate victim task. */
+static bool oom_unkillable_task(struct task_struct *p, struct mem_cgroup *mem,
+			   const nodemask_t *nodemask)
+{
+	if (is_global_init(p))
+		return true;
+	if (p->flags & PF_KTHREAD)
+		return true;
+
+	/* When mem_cgroup_out_of_memory() and p is not member of the group */
+	if (mem && !task_in_mem_cgroup(p, mem))
+		return true;
+
+	/* p may not have freeable memory in nodemask */
+	if (!has_intersects_mems_allowed(p, nodemask))
+		return true;
+
+	return false;
+}
+
 /**
  * badness - calculate a numeric value for how bad this task has been
  * @p: task struct of which task we should calculate
@@ -295,12 +315,7 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
 	for_each_process(p) {
 		unsigned long points;
 
-		/* skip the init task and kthreads */
-		if (is_global_init(p) || (p->flags & PF_KTHREAD))
-			continue;
-		if (mem && !task_in_mem_cgroup(p, mem))
-			continue;
-		if (!has_intersects_mems_allowed(p, nodemask))
+		if (oom_unkillable_task(p, mem, nodemask))
 			continue;
 
 		/*
@@ -467,11 +482,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 
 			if (child->mm == p->mm)
 				continue;
-			if (child->flags & PF_KTHREAD)
-				continue;
-			if (mem && !task_in_mem_cgroup(child, mem))
-				continue;
-			if (!has_intersects_mems_allowed(child, nodemask))
+			if (oom_unkillable_task(p, mem, nodemask))
 				continue;
 
 			/* badness() returns 0 if the thread is unkillable */
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#7 lore raw

Re: [PATCH 03/11] oom: make oom_unkillable_task() helper function

Quoted 26 lines · KOSAKI Motohiro

Now, we have the same task check in two places. Unify it.

---
 mm/oom_kill.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)
mm/oom_kill.c +10 -0
index dc8589e..a4a5439 100644
@@ -101,6 +101,26 @@ static struct task_struct *find_lock_task_mm(struct task_struct *p)
 	return NULL;
 }
 
+/* return true if the task is not adequate as candidate victim task. */
+static bool oom_unkillable_task(struct task_struct *p, struct mem_cgroup *mem,
+			   const nodemask_t *nodemask)
+{
+	if (is_global_init(p))
+		return true;
+	if (p->flags & PF_KTHREAD)
+		return true;
+
+	/* When mem_cgroup_out_of_memory() and p is not member of the group */

mm/oom_kill.c static struct task_struct *find_lock_task_mm(struct task_struct *p) · line 123

Quoted 10 lines
mm/oom_kill.c +10 -0
+	if (mem && !task_in_mem_cgroup(p, mem))
+		return true;
+
+	/* p may not have freeable memory in nodemask */
+	if (!has_intersects_mems_allowed(p, nodemask))
+		return true;
+
+	return false;
+}
+

I returend this patch as review 7/11.
Why didn't you check p->signal->oom_adj == OOM_DISABLE in here? I don't figure out code after your patches are applied totally. But I think it would be check it in this function as function's name says.

Signature · 2 lines
Kind regards,
Minchan Kim
#8 lore raw

Re: [PATCH 03/11] oom: make oom_unkillable_task() helper function

Quoted 34 lines · KOSAKI Motohiro
Quoted 33 lines

Now, we have the same task check in two places. Unify it.

---
 mm/oom_kill.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)
mm/oom_kill.c +17 -0
index dc8589e..a4a5439 100644
@@ -101,6 +101,26 @@ static struct task_struct *find_lock_task_mm(struct task_struct *p)
 	return NULL;
 }
 
+/* return true if the task is not adequate as candidate victim task. */
+static bool oom_unkillable_task(struct task_struct *p, struct mem_cgroup *mem,
+			   const nodemask_t *nodemask)
+{
+	if (is_global_init(p))
+		return true;
+	if (p->flags & PF_KTHREAD)
+		return true;
+
+	/* When mem_cgroup_out_of_memory() and p is not member of the group */
+	if (mem && !task_in_mem_cgroup(p, mem))
+		return true;
+
+	/* p may not have freeable memory in nodemask */
+	if (!has_intersects_mems_allowed(p, nodemask))
+		return true;
+
Quoted 8 lines

mm/oom_kill.c static struct task_struct *find_lock_task_mm(struct task_struct *p) · line 123

Quoted 3 lines
mm/oom_kill.c +3 -0
+	return false;
+}
+

I returend this patch as review 7/11.
Why didn't you check p->signal->oom_adj == OOM_DISABLE in here? I don't figure out code after your patches are applied totally. But I think it would be check it in this function as function's name says.

For preserve select_bad_process() semantics. It have

        for_each_process(p) {
                if (oom_unkillable_task(p, mem, nodemask))
			continue;

                if (thread_group_empty(p) && (p->flags & PF_EXITING) && p->mm) {
                        if (p != current)
                                return ERR_PTR(-1UL);

                        chosen = p;
                        *ppoints = ULONG_MAX;
                }

	        if (oom_adj == OOM_DISABLE)
			continue;

That said, Current OOM-Killer intend to kill PF_EXITING process even if it have OOM_DISABLE. (practically, it's not kill. it only affect to give allocation bonus to PF_EXITING process)

My trivial fixes series don't intend to make large semantics change.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

PATCH 4/11 oom: oom_kill_process() need to check p is unkillable

In reply to KOSAKI Motohiro

When oom_kill_allocating_task is enabled, an argument task of oom_kill_process is not selected by select_bad_process(), It's just out_of_memory() caller task. It mean the task can be unkillable. check it first.

---
 mm/oom_kill.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
mm/oom_kill.c +2 -1
index a4a5439..ee00817 100644
@@ -687,7 +687,8 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 	check_panic_on_oom(constraint, gfp_mask, order);
 
 	read_lock(&tasklist_lock);
-	if (sysctl_oom_kill_allocating_task) {
+	if (sysctl_oom_kill_allocating_task &&
+	    !oom_unkillable_task(current, NULL, nodemask)) {
 		/*
 		 * oom_kill_process() needs tasklist_lock held.  If it returns
 		 * non-zero, current could not be killed so we must fallback to
Signature · 1 line
1.6.5.2
Reviewed-by on v1 4/11
#10 lore raw

Re: [PATCH 04/11] oom: oom_kill_process() need to check p is unkillable

Quoted 6 lines · KOSAKI Motohiro

When oom_kill_allocating_task is enabled, an argument task of oom_kill_process is not selected by select_bad_process(), It's just out_of_memory() caller task. It mean the task can be unkillable. check it first.

Signature · 2 lines
Kind regards,
Minchan Kim
#11 lore raw

PATCH 5/11 oom: /proc/<pid>/oom_score treat kernel thread honestly

In reply to KOSAKI Motohiro

If kernel thread are using use_mm(), badness() return positive value. This is not big issue because caller care it correctly. but there is one exception, /proc/<pid>/oom_score call badness() directly and don't care the task is regular process.

another example, /proc/1/oom_score return !0 value. but it's unkillable. This incorrectness makes confusing to admin a bit.

This patch fixes it.

---
 fs/proc/base.c |    5 +++--
 mm/oom_kill.c  |   13 +++++++------
 2 files changed, 10 insertions(+), 8 deletions(-)
fs/proc/base.c +3 -2
index 28099a1..56b8d3e 100644
@@ -428,7 +428,8 @@ static const struct file_operations proc_lstats_operations = {
 #endif
 
 /* The badness from the OOM killer */
-unsigned long badness(struct task_struct *p, unsigned long uptime);
+unsigned long badness(struct task_struct *p, struct mem_cgroup *mem,
+		      nodemask_t *nodemask, unsigned long uptime);
 static int proc_oom_score(struct task_struct *task, char *buffer)
 {
 	unsigned long points = 0;
@@ -437,7 +438,7 @@ static int proc_oom_score(struct task_struct *task, char *buffer)
 	do_posix_clock_monotonic_gettime(&uptime);
 	read_lock(&tasklist_lock);
 	if (pid_alive(task))
-		points = badness(task, uptime.tv_sec);
+		points = badness(task, NULL, NULL, uptime.tv_sec);
 	read_unlock(&tasklist_lock);
 	return sprintf(buffer, "%lu\n", points);
 }
mm/oom_kill.c +7 -6
index ee00817..fcbd21b 100644
@@ -139,8 +139,8 @@ static bool oom_unkillable_task(struct task_struct *p, struct mem_cgroup *mem,
  *    algorithm has been meticulously tuned to meet the principle
  *    of least surprise ... (be careful when you change it)
  */
-
-unsigned long badness(struct task_struct *p, unsigned long uptime)
+unsigned long badness(struct task_struct *p, struct mem_cgroup *mem,
+		      const nodemask_t *nodemask, unsigned long uptime)
 {
 	unsigned long points, cpu_time, run_time;
 	struct task_struct *child;
@@ -150,6 +150,8 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
 	unsigned long utime;
 	unsigned long stime;
 
+	if (oom_unkillable_task(p, mem, nodemask))
+		return 0;
 	if (oom_adj == OOM_DISABLE)
 		return 0;
 
@@ -351,7 +353,7 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
 		if (p->signal->oom_adj == OOM_DISABLE)
 			continue;
 
-		points = badness(p, uptime.tv_sec);
+		points = badness(p, mem, nodemask, uptime.tv_sec);
 		if (points > *ppoints || !chosen) {
 			chosen = p;
 			*ppoints = points;
@@ -482,11 +484,10 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 
 			if (child->mm == p->mm)
 				continue;
-			if (oom_unkillable_task(p, mem, nodemask))
-				continue;
 
 			/* badness() returns 0 if the thread is unkillable */
-			child_points = badness(child, uptime.tv_sec);
+			child_points = badness(child, mem, nodemask,
+					       uptime.tv_sec);
 			if (child_points > victim_points) {
 				victim = child;
 				victim_points = child_points;
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw

Re: [PATCH 05/11] oom: /proc/<pid>/oom_score treat kernel thread honestly

Quoted 7 lines · KOSAKI Motohiro

If kernel thread are using use_mm(), badness() return positive value. This is not big issue because caller care it correctly. but there is one exception, /proc/<pid>/oom_score call badness() directly and don't care the task is regular process.

another example, /proc/1/oom_score return !0 value. but it's unkillable. This incorrectness makes confusing to admin a bit.

Hmm. If it is a really problem, Could we solve it in proc_oom_score itself?

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#13 lore raw

Re: [PATCH 05/11] oom: /proc/<pid>/oom_score treat kernel thread honestly

Quoted 10 lines · KOSAKI Motohiro
Quoted 7 lines

If kernel thread are using use_mm(), badness() return positive value. This is not big issue because caller care it correctly. but there is one exception, /proc/<pid>/oom_score call badness() directly and don't care the task is regular process.

another example, /proc/1/oom_score return !0 value. but it's unkillable. This incorrectness makes confusing to admin a bit.

Hmm. If it is a really problem, Could we solve it in proc_oom_score itself?

probably, no good idea. For maintainance view, all oom related code should be gathered in oom_kill.c.
If you dislike to add messy into badness(), I hope to make badness_for_oom_score() or something like instead.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw

Re: [PATCH 05/11] oom: /proc/<pid>/oom_score treat kernel thread honestly

Quoted 6 lines · KOSAKI Motohiro
Quoted 6 lines · KOSAKI Motohiro
Quoted 5 lines

If kernel thread are using use_mm(), badness() return positive value. This is not big issue because caller care it correctly. but there is one exception, /proc/<pid>/oom_score call badness() directly and don't care the task is regular process.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

another example, /proc/1/oom_score return !0 value. but it's unkillable. This incorrectness makes confusing to admin a bit.

Hmm. If it is a really problem, Could we solve it in proc_oom_score itself?

probably, no good idea. For maintainance view, all oom related code should be gathered in oom_kill.c.
If you dislike to add messy into badness(), I hope to make badness_for_oom_score()

I am looking forward to seeing your next series.
Thanks, Kosaki.

P.S)
I think if the number of patch series is the bigger than #10, It would be better to include or point url of all-at-once patch in patch series.

In case of your patch, post patches changes pre patches
It could make hard review unless the reviewer merge patches into tree to see the final figure.

Signature · 2 lines
Kind regards,
Minchan Kim
#15 lore raw

PATCH 6/11 oom: kill duplicate OOM_DISABLE check

In reply to KOSAKI Motohiro

select_bad_process() and badness() have the same OOM_DISABLE check. This patch kill one.

---
 mm/oom_kill.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
mm/oom_kill.c +0 -3
index fcbd21b..f5d903f 100644
@@ -350,9 +350,6 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
 			*ppoints = ULONG_MAX;
 		}
 
-		if (p->signal->oom_adj == OOM_DISABLE)
-			continue;
-
 		points = badness(p, mem, nodemask, uptime.tv_sec);
 		if (points > *ppoints || !chosen) {
 			chosen = p;
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 6/11
#16 lore raw

Re: [PATCH 06/11] oom: kill duplicate OOM_DISABLE check

Quoted 5 lines · KOSAKI Motohiro

select_bad_process() and badness() have the same OOM_DISABLE check. This patch kill one.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#17 lore raw

PATCH 7/11 oom: move OOM_DISABLE check from oom_kill_task to out_of_memory()

In reply to KOSAKI Motohiro

Now, if oom_kill_allocating_task is enabled and current have OOM_DISABLED, following printk in oom_kill_process is called twice.

pr_err("%s: Kill process %d (%s) score %lu or sacrifice child\n",
message, task_pid_nr(p), p->comm, points);

So, OOM_DISABLE check should be more early.

---
 mm/oom_kill.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
mm/oom_kill.c +3 -2
index f5d903f..75f6dbc 100644
@@ -424,7 +424,7 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
 static int oom_kill_task(struct task_struct *p)
 {
 	p = find_lock_task_mm(p);
-	if (!p || p->signal->oom_adj == OOM_DISABLE) {
+	if (!p) {
 		task_unlock(p);
 		return 1;
 	}
@@ -686,7 +686,8 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 
 	read_lock(&tasklist_lock);
 	if (sysctl_oom_kill_allocating_task &&
-	    !oom_unkillable_task(current, NULL, nodemask)) {
+	    !oom_unkillable_task(current, NULL, nodemask) &&
+	    (current->signal->oom_adj != OOM_DISABLE)) {
 		/*
 		 * oom_kill_process() needs tasklist_lock held.  If it returns
 		 * non-zero, current could not be killed so we must fallback to
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw

Re: [PATCH 07/11] oom: move OOM_DISABLE check from oom_kill_task to out_of_memory()

Quoted 7 lines · KOSAKI Motohiro

Now, if oom_kill_allocating_task is enabled and current have OOM_DISABLED, following printk in oom_kill_process is called twice.

pr_err("%s: Kill process %d (%s) score %lu or sacrifice child\n",
message, task_pid_nr(p), p->comm, points);

So, OOM_DISABLE check should be more early.

If we check it in oom_unkillable_task, we don't need this patch.

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#19 lore raw

Re: [PATCH 07/11] oom: move OOM_DISABLE check from oom_kill_task to out_of_memory()

Quoted 10 lines · KOSAKI Motohiro
Quoted 7 lines

Now, if oom_kill_allocating_task is enabled and current have OOM_DISABLED, following printk in oom_kill_process is called twice.

pr_err("%s: Kill process %d (%s) score %lu or sacrifice child\n",
message, task_pid_nr(p), p->comm, points);

So, OOM_DISABLE check should be more early.

If we check it in oom_unkillable_task, we don't need this patch.

Yup. but please read the commnet of [3/11].

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#20 lore raw

PATCH 8/11 oom: cleanup has_intersects_mems_allowed()

In reply to KOSAKI Motohiro

Now has_intersects_mems_allowed() has own thread iterate logic, but it should use while_each_thread().

It slightly improve the code readability.

---
 mm/oom_kill.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
mm/oom_kill.c +2 -2
index 75f6dbc..136708b 100644
@@ -69,8 +69,8 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,
 			if (cpuset_mems_allowed_intersects(current, tsk))
 				return true;
 		}
-		tsk = next_thread(tsk);
-	} while (tsk != start);
+	} while_each_thread(start, tsk);
+
 	return false;
 }
 #else
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#21 lore raw

PATCH 9/11 oom: remove child->mm check from oom_kill_process()

In reply to KOSAKI Motohiro

Current "child->mm == p->mm" mean prevent to select vfork() task. But we don't have any reason to don't consider vfork().

Remvoed.

---
 mm/oom_kill.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
mm/oom_kill.c +0 -3
index 136708b..b5678bf 100644
@@ -479,9 +479,6 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 		list_for_each_entry(child, &t->children, sibling) {
 			unsigned long child_points;
 
-			if (child->mm == p->mm)
-				continue;
-
 			/* badness() returns 0 if the thread is unkillable */
 			child_points = badness(child, mem, nodemask,
 					       uptime.tv_sec);
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#22 lore raw

Re: [PATCH 09/11] oom: remove child->mm check from oom_kill_process()

Quoted 3 lines · KOSAKI Motohiro

Current "child->mm == p->mm" mean prevent to select vfork() task. But we don't have any reason to don't consider vfork().

I guess "child->mm == p->mm" is for losing the minimal amount of work done as comment say. But frankly speaking, I don't understand it, either. Maybe "One shot, two kill" problem?

Andrea. Could you explain it?

Signature · 2 lines
Kind regards,
Minchan Kim
#23 lore raw

PATCH 10/11 oom: give the dying task a higher priority

In reply to KOSAKI Motohiro

From: Luis Claudio R. Goncalves <[email protected]>

In a system under heavy load it was observed that even after the oom-killer selects a task to die, the task may take a long time to die.

Right after sending a SIGKILL to the task selected by the oom-killer this task has it's priority increased so that it can exit() exit soon, freeing memory. That is accomplished by:

/*
* We give our sacrificial lamb high priority and access to
* all the memory it needs. That way it should be able to
* exit() and clear out its resources quickly... */
p->rt.time_slice = HZ;
set_tsk_thread_flag(p, TIF_MEMDIE);

It sounds plausible giving the dying task an even higher priority to be sure it will be scheduled sooner and free the desired memory. It was suggested on LKML using SCHED_FIFO:1, the lowest RT priority so that this task won't interfere with any running RT task.

If the dying task is already an RT task, leave it untouched. Another good suggestion, implemented here, was to avoid boosting the dying task priority in case of mem_cgroup OOM.

---
 mm/oom_kill.c |   34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)
mm/oom_kill.c +31 -3
index b5678bf..0858b18 100644
@@ -82,6 +82,24 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,
 #endif /* CONFIG_NUMA */
 
 /*
+ * If this is a system OOM (not a memcg OOM) and the task selected to be
+ * killed is not already running at high (RT) priorities, speed up the
+ * recovery by boosting the dying task to the lowest FIFO priority.
+ * That helps with the recovery and avoids interfering with RT tasks.
+ */
+static void boost_dying_task_prio(struct task_struct *p,
+				  struct mem_cgroup *mem)
+{
+	struct sched_param param = { .sched_priority = 1 };
+
+	if (mem)
+		return;
+
+	if (!rt_task(p))
+		sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+}
+
+/*
  * The process p may have detached its own ->mm while exiting or through
  * use_mm(), but one or more of its subthreads may still have a valid
  * pointer.  Return p, or any of its subthreads with a valid ->mm, with
@@ -421,7 +439,7 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
 }
 
 #define K(x) ((x) << (PAGE_SHIFT-10))
-static int oom_kill_task(struct task_struct *p)
+static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 {
 	p = find_lock_task_mm(p);
 	if (!p) {
@@ -434,9 +452,17 @@ static int oom_kill_task(struct task_struct *p)
 		K(get_mm_counter(p->mm, MM_FILEPAGES)));
 	task_unlock(p);
 
-	p->rt.time_slice = HZ;
+
 	set_tsk_thread_flag(p, TIF_MEMDIE);
 	force_sig(SIGKILL, p);
+
+	/*
+	 * We give our sacrificial lamb high priority and access to
+	 * all the memory it needs. That way it should be able to
+	 * exit() and clear out its resources quickly...
+	 */
+	boost_dying_task_prio(p, mem);
+
 	return 0;
 }
 #undef K
@@ -460,6 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 	 */
 	if (p->flags & PF_EXITING) {
 		set_tsk_thread_flag(p, TIF_MEMDIE);
+		boost_dying_task_prio(p, mem);
 		return 0;
 	}
 
@@ -489,7 +516,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 		}
 	} while_each_thread(p, t);
 
-	return oom_kill_task(victim);
+	return oom_kill_task(victim, mem);
 }
 
 /*
@@ -670,6 +697,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 	 */
 	if (fatal_signal_pending(current)) {
 		set_thread_flag(TIF_MEMDIE);
+		boost_dying_task_prio(current, NULL);
 		return;
 	}
 
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#24 lore raw

Re: [PATCH 10/11] oom: give the dying task a higher priority

Sorry, I forgot to cc Luis. resend.

(intentional full quote)

Quoted 120 lines

From: Luis Claudio R. Goncalves <[email protected]>

In a system under heavy load it was observed that even after the oom-killer selects a task to die, the task may take a long time to die.

Right after sending a SIGKILL to the task selected by the oom-killer this task has it's priority increased so that it can exit() exit soon, freeing memory. That is accomplished by:

/*
* We give our sacrificial lamb high priority and access to
* all the memory it needs. That way it should be able to
* exit() and clear out its resources quickly... */

(quoted diff) +0 -0
 	p->rt.time_slice = HZ;
 	set_tsk_thread_flag(p, TIF_MEMDIE);

It sounds plausible giving the dying task an even higher priority to be sure it will be scheduled sooner and free the desired memory. It was suggested on LKML using SCHED_FIFO:1, the lowest RT priority so that this task won't interfere with any running RT task.

If the dying task is already an RT task, leave it untouched. Another good suggestion, implemented here, was to avoid boosting the dying task priority in case of mem_cgroup OOM.

---
 mm/oom_kill.c |   34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)
mm/oom_kill.c +31 -3
index b5678bf..0858b18 100644
@@ -82,6 +82,24 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,
 #endif /* CONFIG_NUMA */
 
 /*
+ * If this is a system OOM (not a memcg OOM) and the task selected to be
+ * killed is not already running at high (RT) priorities, speed up the
+ * recovery by boosting the dying task to the lowest FIFO priority.
+ * That helps with the recovery and avoids interfering with RT tasks.
+ */
+static void boost_dying_task_prio(struct task_struct *p,
+				  struct mem_cgroup *mem)
+{
+	struct sched_param param = { .sched_priority = 1 };
+
+	if (mem)
+		return;
+
+	if (!rt_task(p))
+		sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+}
+
+/*
  * The process p may have detached its own ->mm while exiting or through
  * use_mm(), but one or more of its subthreads may still have a valid
  * pointer.  Return p, or any of its subthreads with a valid ->mm, with
@@ -421,7 +439,7 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
 }
 
 #define K(x) ((x) << (PAGE_SHIFT-10))
-static int oom_kill_task(struct task_struct *p)
+static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 {
 	p = find_lock_task_mm(p);
 	if (!p) {
@@ -434,9 +452,17 @@ static int oom_kill_task(struct task_struct *p)
 		K(get_mm_counter(p->mm, MM_FILEPAGES)));
 	task_unlock(p);
 
-	p->rt.time_slice = HZ;
+
 	set_tsk_thread_flag(p, TIF_MEMDIE);
 	force_sig(SIGKILL, p);
+
+	/*
+	 * We give our sacrificial lamb high priority and access to
+	 * all the memory it needs. That way it should be able to
+	 * exit() and clear out its resources quickly...
+	 */
+	boost_dying_task_prio(p, mem);
+
 	return 0;
 }
 #undef K
@@ -460,6 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 	 */
 	if (p->flags & PF_EXITING) {
 		set_tsk_thread_flag(p, TIF_MEMDIE);
+		boost_dying_task_prio(p, mem);
 		return 0;
 	}
 
@@ -489,7 +516,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 		}
 	} while_each_thread(p, t);
 
-	return oom_kill_task(victim);
+	return oom_kill_task(victim, mem);
 }
 
 /*
@@ -670,6 +697,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 	 */
 	if (fatal_signal_pending(current)) {
 		set_thread_flag(TIF_MEMDIE);
+		boost_dying_task_prio(current, NULL);
 		return;
 	}
 
Signature · 1 line
1.6.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by
#25 lore raw

Re: [PATCH 10/11] oom: give the dying task a higher priority

Quoted 35 lines · KOSAKI Motohiro

Sorry, I forgot to cc Luis. resend.

(intentional full quote)

Quoted 29 lines

From: Luis Claudio R. Goncalves <[email protected]>

In a system under heavy load it was observed that even after the oom-killer selects a task to die, the task may take a long time to die.

Right after sending a SIGKILL to the task selected by the oom-killer this task has it's priority increased so that it can exit() exit soon, freeing memory. That is accomplished by:

/*
* We give our sacrificial lamb high priority and access to
* all the memory it needs. That way it should be able to
* exit() and clear out its resources quickly... */

(quoted diff) +0 -0
 	p->rt.time_slice = HZ;
 	set_tsk_thread_flag(p, TIF_MEMDIE);

It sounds plausible giving the dying task an even higher priority to be sure it will be scheduled sooner and free the desired memory. It was suggested on LKML using SCHED_FIFO:1, the lowest RT priority so that this task won't interfere with any running RT task.

If the dying task is already an RT task, leave it untouched. Another good suggestion, implemented here, was to avoid boosting the dying task priority in case of mem_cgroup OOM.

It seems code itself doesn't have a problem.
So I give reviewed-by.
But this patch might break fairness of normal process at corner case. If system working is more important than fairness of processes, It does make sense. But scheduler guys might have a different opinion.

So at least, we need ACKs of scheduler guys.
Cced Ingo, Peter, Thomas.

Quoted 94 lines
Quoted 91 lines
---
 mm/oom_kill.c |   34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)
mm/oom_kill.c +31 -3
index b5678bf..0858b18 100644
@@ -82,6 +82,24 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk,
 #endif /* CONFIG_NUMA */
 
 /*
+ * If this is a system OOM (not a memcg OOM) and the task selected to be
+ * killed is not already running at high (RT) priorities, speed up the
+ * recovery by boosting the dying task to the lowest FIFO priority.
+ * That helps with the recovery and avoids interfering with RT tasks.
+ */
+static void boost_dying_task_prio(struct task_struct *p,
+				  struct mem_cgroup *mem)
+{
+	struct sched_param param = { .sched_priority = 1 };
+
+	if (mem)
+		return;
+
+	if (!rt_task(p))
+		sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+}
+
+/*
  * The process p may have detached its own ->mm while exiting or through
  * use_mm(), but one or more of its subthreads may still have a valid
  * pointer.  Return p, or any of its subthreads with a valid ->mm, with
@@ -421,7 +439,7 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
 }
 
 #define K(x) ((x) << (PAGE_SHIFT-10))
-static int oom_kill_task(struct task_struct *p)
+static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 {
 	p = find_lock_task_mm(p);
 	if (!p) {
@@ -434,9 +452,17 @@ static int oom_kill_task(struct task_struct *p)
 		K(get_mm_counter(p->mm, MM_FILEPAGES)));
 	task_unlock(p);
 
-	p->rt.time_slice = HZ;
+
 	set_tsk_thread_flag(p, TIF_MEMDIE);
 	force_sig(SIGKILL, p);
+
+	/*
+	 * We give our sacrificial lamb high priority and access to
+	 * all the memory it needs. That way it should be able to
+	 * exit() and clear out its resources quickly...
+	 */
+	boost_dying_task_prio(p, mem);
+
 	return 0;
 }
 #undef K
@@ -460,6 +486,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 	 */
 	if (p->flags & PF_EXITING) {
 		set_tsk_thread_flag(p, TIF_MEMDIE);
+		boost_dying_task_prio(p, mem);
 		return 0;
 	}
 
@@ -489,7 +516,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 		}
 	} while_each_thread(p, t);
 
-	return oom_kill_task(victim);
+	return oom_kill_task(victim, mem);
 }
 
 /*
@@ -670,6 +697,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 	 */
 	if (fatal_signal_pending(current)) {
 		set_thread_flag(TIF_MEMDIE);
+		boost_dying_task_prio(current, NULL);
 		return;
 	}
 
Signature · 1 line
1.6.5.2
Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#26 lore raw

Re: [PATCH 10/11] oom: give the dying task a higher priority

In reply to KOSAKI Motohiro

Review

Quoted 11 lines · On Wed, 30 Jun 2010 18:33:23 +0900 (JST) KOSAKI Motohiro…
(quoted diff) +11 -0
+static void boost_dying_task_prio(struct task_struct *p,
+				  struct mem_cgroup *mem)
+{
+	struct sched_param param = { .sched_priority = 1 };
+
+	if (mem)
+		return;
+
+	if (!rt_task(p))
+		sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+}

We can actually make `param' static here. That saves a teeny bit of code and a little bit of stack. The oom-killer can be called when we're using a lot of stack.

But if we make that change we really should make the param arg to sched_setscheduler_nocheck() be const. I did that (and was able to convert lots of callers to use a static `param') but to complete the job we'd need to chase through all the security goop, fixing up security_task_setscheduler() and callees, and I got bored.

 include/linux/sched.h |    2 +-
 kernel/kthread.c      |    2 +-
 kernel/sched.c        |    4 ++--
 kernel/softirq.c      |    4 +++-
 kernel/stop_machine.c |    2 +-
 kernel/workqueue.c    |    2 +-
 6 files changed, 9 insertions(+), 7 deletions(-)
kernel/kthread.c renamed from kernel/kthread.c~a +1 -1
diff -puN kernel/kthread.c~a kernel/kthread.c
@@ -131,7 +131,7 @@ struct task_struct *kthread_create(int (
 	wait_for_completion(&create.done);
 
 	if (!IS_ERR(create.result)) {
-		struct sched_param param = { .sched_priority = 0 };
+		static struct sched_param param = { .sched_priority = 0 };
 		va_list args;
 
 		va_start(args, namefmt);
kernel/workqueue.c renamed from kernel/workqueue.c~a +1 -1
diff -puN kernel/workqueue.c~a kernel/workqueue.c
@@ -962,7 +962,7 @@ init_cpu_workqueue(struct workqueue_stru
 
 static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
 {
-	struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
+	static struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
 	struct workqueue_struct *wq = cwq->wq;
 	const char *fmt = is_wq_single_threaded(wq) ? "%s" : "%s/%d";
 	struct task_struct *p;
kernel/stop_machine.c renamed from kernel/stop_machine.c~a +1 -1
diff -puN kernel/stop_machine.c~a kernel/stop_machine.c
@@ -291,7 +291,7 @@ repeat:
 static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
 					   unsigned long action, void *hcpu)
 {
-	struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
+	static struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
 	unsigned int cpu = (unsigned long)hcpu;
 	struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
 	struct task_struct *p;
kernel/sched.c renamed from kernel/sched.c~a +2 -2
diff -puN kernel/sched.c~a kernel/sched.c
@@ -4570,7 +4570,7 @@ static bool check_same_owner(struct task
 }
 
 static int __sched_setscheduler(struct task_struct *p, int policy,
-				struct sched_param *param, bool user)
+				const struct sched_param *param, bool user)
 {
 	int retval, oldprio, oldpolicy = -1, on_rq, running;
 	unsigned long flags;
@@ -4734,7 +4734,7 @@ EXPORT_SYMBOL_GPL(sched_setscheduler);
  * but our caller might not have that capability.
  */
 int sched_setscheduler_nocheck(struct task_struct *p, int policy,
-			       struct sched_param *param)
+			       const struct sched_param *param)
 {
 	return __sched_setscheduler(p, policy, param, false);
 }
kernel/softirq.c renamed from kernel/softirq.c~a +3 -1
diff -puN kernel/softirq.c~a kernel/softirq.c
@@ -827,7 +827,9 @@ static int __cpuinit cpu_callback(struct
 			     cpumask_any(cpu_online_mask));
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN: {
-		struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
+		static struct sched_param param = {
+				.sched_priority = MAX_RT_PRIO-1,
+			};
 
 		p = per_cpu(ksoftirqd, hotcpu);
 		per_cpu(ksoftirqd, hotcpu) = NULL;
include/linux/sched.h renamed from include/linux/sched.h~a +1 -1
diff -puN include/linux/sched.h~a include/linux/sched.h
@@ -1924,7 +1924,7 @@ extern int task_curr(const struct task_s
 extern int idle_cpu(int cpu);
 extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
 extern int sched_setscheduler_nocheck(struct task_struct *, int,
-				      struct sched_param *);
+				      const struct sched_param *);
 extern struct task_struct *idle_task(int cpu);
 extern struct task_struct *curr_task(int cpu);
 extern void set_curr_task(int cpu, struct task_struct *p);

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#27 lore raw

Re: [PATCH 10/11] oom: give the dying task a higher priority

(cc to James)

Quoted 19 lines

Review

Quoted 11 lines · On Wed, 30 Jun 2010 18:33:23 +0900 (JST) KOSAKI Motohiro…
(quoted diff) +11 -0
+static void boost_dying_task_prio(struct task_struct *p,
+				  struct mem_cgroup *mem)
+{
+	struct sched_param param = { .sched_priority = 1 };
+
+	if (mem)
+		return;
+
+	if (!rt_task(p))
+		sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+}

We can actually make `param' static here. That saves a teeny bit of code and a little bit of stack. The oom-killer can be called when we're using a lot of stack.

Quoted 5 lines

But if we make that change we really should make the param arg to sched_setscheduler_nocheck() be const. I did that (and was able to convert lots of callers to use a static `param') but to complete the job we'd need to chase through all the security goop, fixing up security_task_setscheduler() and callees, and I got bored.

ok, I've finished this works. I made two patches, for-security-tree and for-core. diffstat is below.

I'll post the patches as reply of this mail.

KOSAKI Motohiro (2):
security: add const to security_task_setscheduler()
sched: make sched_param arugment static variables in some
sched_setscheduler() caller

 include/linux/sched.h         |    5 +++--
 include/linux/security.h      |    9 +++++----
 kernel/irq/manage.c           |    4 +++-
 kernel/kthread.c              |    2 +-
 kernel/sched.c                |    6 +++---
 kernel/softirq.c              |    4 +++-
 kernel/stop_machine.c         |    2 +-
 kernel/trace/trace_selftest.c |    2 +-
 kernel/watchdog.c             |    2 +-
 kernel/workqueue.c            |    2 +-
 security/commoncap.c          |    2 +-
 security/security.c           |    4 ++--
 security/selinux/hooks.c      |    3 ++-
 security/smack/smack_lsm.c    |    2 +-
 14 files changed, 28 insertions(+), 21 deletions(-)

- kosaki

Quoted 93 lines

 include/linux/sched.h |    2 +-
 kernel/kthread.c      |    2 +-
 kernel/sched.c        |    4 ++--
 kernel/softirq.c      |    4 +++-
 kernel/stop_machine.c |    2 +-
 kernel/workqueue.c    |    2 +-
 6 files changed, 9 insertions(+), 7 deletions(-)

diff -puN kernel/kthread.c~a kernel/kthread.c

kernel/kthread.c renamed from kernel/kthread.c~a +1 -1
@@ -131,7 +131,7 @@ struct task_struct *kthread_create(int (
 	wait_for_completion(&create.done);
 
 	if (!IS_ERR(create.result)) {
-		struct sched_param param = { .sched_priority = 0 };
+		static struct sched_param param = { .sched_priority = 0 };
 		va_list args;
 
 		va_start(args, namefmt);

diff -puN kernel/workqueue.c~a kernel/workqueue.c

kernel/workqueue.c renamed from kernel/workqueue.c~a +1 -1
@@ -962,7 +962,7 @@ init_cpu_workqueue(struct workqueue_stru
 
 static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
 {
-	struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
+	static struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
 	struct workqueue_struct *wq = cwq->wq;
 	const char *fmt = is_wq_single_threaded(wq) ? "%s" : "%s/%d";
 	struct task_struct *p;

diff -puN kernel/stop_machine.c~a kernel/stop_machine.c

kernel/stop_machine.c renamed from kernel/stop_machine.c~a +1 -1
@@ -291,7 +291,7 @@ repeat:
 static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
 					   unsigned long action, void *hcpu)
 {
-	struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
+	static struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
 	unsigned int cpu = (unsigned long)hcpu;
 	struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
 	struct task_struct *p;

diff -puN kernel/sched.c~a kernel/sched.c

kernel/sched.c renamed from kernel/sched.c~a +2 -2
@@ -4570,7 +4570,7 @@ static bool check_same_owner(struct task
 }
 
 static int __sched_setscheduler(struct task_struct *p, int policy,
-				struct sched_param *param, bool user)
+				const struct sched_param *param, bool user)
 {
 	int retval, oldprio, oldpolicy = -1, on_rq, running;
 	unsigned long flags;
@@ -4734,7 +4734,7 @@ EXPORT_SYMBOL_GPL(sched_setscheduler);
  * but our caller might not have that capability.
  */
 int sched_setscheduler_nocheck(struct task_struct *p, int policy,
-			       struct sched_param *param)
+			       const struct sched_param *param)
 {
 	return __sched_setscheduler(p, policy, param, false);
 }

diff -puN kernel/softirq.c~a kernel/softirq.c

kernel/softirq.c renamed from kernel/softirq.c~a +3 -1
@@ -827,7 +827,9 @@ static int __cpuinit cpu_callback(struct
 			     cpumask_any(cpu_online_mask));
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN: {
-		struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
+		static struct sched_param param = {
+				.sched_priority = MAX_RT_PRIO-1,
+			};
 
 		p = per_cpu(ksoftirqd, hotcpu);
 		per_cpu(ksoftirqd, hotcpu) = NULL;

diff -puN include/linux/sched.h~a include/linux/sched.h

include/linux/sched.h renamed from include/linux/sched.h~a +1 -1
@@ -1924,7 +1924,7 @@ extern int task_curr(const struct task_s
 extern int idle_cpu(int cpu);
 extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
 extern int sched_setscheduler_nocheck(struct task_struct *, int,
-				      struct sched_param *);
+				      const struct sched_param *);
 extern struct task_struct *idle_task(int cpu);
 extern struct task_struct *curr_task(int cpu);
 extern void set_curr_task(int cpu, struct task_struct *p);
Quoted 2 lines

_

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#28 lore raw

PATCH 1/2 security: add const to security_task_setscheduler()

All security modules shouldn't change sched_param parameter of security_task_setscheduler(). This is not only meaningless, but also make harmful result if caller pass static variable.

This patch add const to it.

---
 include/linux/security.h   |    9 +++++----
 security/commoncap.c       |    2 +-
 security/security.c        |    4 ++--
 security/selinux/hooks.c   |    3 ++-
 security/smack/smack_lsm.c |    2 +-
 5 files changed, 11 insertions(+), 9 deletions(-)
include/linux/security.h +5 -4
index 5bcb395..07e94e5 100644
@@ -74,7 +74,8 @@ extern int cap_file_mmap(struct file *file, unsigned long reqprot,
 extern int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags);
 extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
 			  unsigned long arg4, unsigned long arg5);
-extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp);
+extern int cap_task_setscheduler(struct task_struct *p, int policy,
+				 const struct sched_param *lp);
 extern int cap_task_setioprio(struct task_struct *p, int ioprio);
 extern int cap_task_setnice(struct task_struct *p, int nice);
 extern int cap_syslog(int type, bool from_file);
@@ -1501,7 +1502,7 @@ struct security_operations {
 	int (*task_getioprio) (struct task_struct *p);
 	int (*task_setrlimit) (unsigned int resource, struct rlimit *new_rlim);
 	int (*task_setscheduler) (struct task_struct *p, int policy,
-				  struct sched_param *lp);
+				  const struct sched_param *lp);
 	int (*task_getscheduler) (struct task_struct *p);
 	int (*task_movememory) (struct task_struct *p);
 	int (*task_kill) (struct task_struct *p,
@@ -1750,8 +1751,8 @@ int security_task_setnice(struct task_struct *p, int nice);
 int security_task_setioprio(struct task_struct *p, int ioprio);
 int security_task_getioprio(struct task_struct *p);
 int security_task_setrlimit(unsigned int resource, struct rlimit *new_rlim);
-int security_task_setscheduler(struct task_struct *p,
-				int policy, struct sched_param *lp);
+int security_task_setscheduler(struct task_struct *p, int policy,
+			       const struct sched_param *lp);
 int security_task_getscheduler(struct task_struct *p);
 int security_task_movememory(struct task_struct *p);
 int security_task_kill(struct task_struct *p, struct siginfo *info,
security/commoncap.c +1 -1
index 4e01599..b74d460 100644
@@ -726,7 +726,7 @@ static int cap_safe_nice(struct task_struct *p)
  * specified task, returning 0 if permission is granted, -ve if denied.
  */
 int cap_task_setscheduler(struct task_struct *p, int policy,
-			   struct sched_param *lp)
+			  const struct sched_param *lp)
 {
 	return cap_safe_nice(p);
 }
security/security.c +2 -2
index 7461b1b..6151322 100644
@@ -785,8 +785,8 @@ int security_task_setrlimit(unsigned int resource, struct rlimit *new_rlim)
 	return security_ops->task_setrlimit(resource, new_rlim);
 }
 
-int security_task_setscheduler(struct task_struct *p,
-				int policy, struct sched_param *lp)
+int security_task_setscheduler(struct task_struct *p, int policy,
+			       const struct sched_param *lp)
 {
 	return security_ops->task_setscheduler(p, policy, lp);
 }
security/selinux/hooks.c +2 -1
index 5c9f25b..dd136bd 100644
@@ -3385,7 +3385,8 @@ static int selinux_task_setrlimit(unsigned int resource, struct rlimit *new_rlim
 	return 0;
 }
 
-static int selinux_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp)
+static int selinux_task_setscheduler(struct task_struct *p, int policy,
+				     const struct sched_param *lp)
 {
 	int rc;
 
security/smack/smack_lsm.c +1 -1
index 07abc9c..c3336f1 100644
@@ -1280,7 +1280,7 @@ static int smack_task_getioprio(struct task_struct *p)
  * Return 0 if read access is permitted
  */
 static int smack_task_setscheduler(struct task_struct *p, int policy,
-				   struct sched_param *lp)
+				   const struct sched_param *lp)
 {
 	int rc;
 
Signature · 9 lines
1.6.5.2



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#29 lore raw

PATCH 2/2 sched: make sched_param arugment static variables in some sched_setscheduler() caller

In reply to KOSAKI Motohiro

Andrew Morton pointed out almost sched_setscheduler() caller are using fixed parameter and it can be converted static. it reduce runtume memory waste a bit.

---
 include/linux/sched.h         |    5 +++--
 kernel/irq/manage.c           |    4 +++-
 kernel/kthread.c              |    2 +-
 kernel/sched.c                |    6 +++---
 kernel/softirq.c              |    4 +++-
 kernel/stop_machine.c         |    2 +-
 kernel/trace/trace_selftest.c |    2 +-
 kernel/watchdog.c             |    2 +-
 kernel/workqueue.c            |    2 +-
 9 files changed, 17 insertions(+), 12 deletions(-)
include/linux/sched.h +3 -2
index cfcd13e..97b7fe3 100644
@@ -1917,9 +1917,10 @@ extern int task_nice(const struct task_struct *p);
 extern int can_nice(const struct task_struct *p, const int nice);
 extern int task_curr(const struct task_struct *p);
 extern int idle_cpu(int cpu);
-extern int sched_setscheduler(struct task_struct *, int, struct sched_param *);
+extern int sched_setscheduler(struct task_struct *, int,
+			      const struct sched_param *);
 extern int sched_setscheduler_nocheck(struct task_struct *, int,
-				      struct sched_param *);
+				      const struct sched_param *);
 extern struct task_struct *idle_task(int cpu);
 extern struct task_struct *curr_task(int cpu);
 extern void set_curr_task(int cpu, struct task_struct *p);
kernel/irq/manage.c +3 -1
index 3164ba7..ce1dbb8 100644
@@ -569,7 +569,9 @@ irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *action) { }
  */
 static int irq_thread(void *data)
 {
-	struct sched_param param = { .sched_priority = MAX_USER_RT_PRIO/2, };
+	static struct sched_param param = {
+		.sched_priority = MAX_USER_RT_PRIO/2,
+	};
 	struct irqaction *action = data;
 	struct irq_desc *desc = irq_to_desc(action->irq);
 	int wake, oneshot = desc->status & IRQ_ONESHOT;
kernel/kthread.c +1 -1
index 83911c7..3b55a26 100644
@@ -131,7 +131,7 @@ struct task_struct *kthread_create(int (*threadfn)(void *data),
 	wait_for_completion(&create.done);
 
 	if (!IS_ERR(create.result)) {
-		struct sched_param param = { .sched_priority = 0 };
+		static struct sched_param param = { .sched_priority = 0 };
 		va_list args;
 
 		va_start(args, namefmt);
kernel/sched.c +3 -3
index 18faf4d..8f2f4b4 100644
@@ -4396,7 +4396,7 @@ static bool check_same_owner(struct task_struct *p)
 }
 
 static int __sched_setscheduler(struct task_struct *p, int policy,
-				struct sched_param *param, bool user)
+				const struct sched_param *param, bool user)
 {
 	int retval, oldprio, oldpolicy = -1, on_rq, running;
 	unsigned long flags;
@@ -4540,7 +4540,7 @@ recheck:
  * NOTE that the task may be already dead.
  */
 int sched_setscheduler(struct task_struct *p, int policy,
-		       struct sched_param *param)
+		       const struct sched_param *param)
 {
 	return __sched_setscheduler(p, policy, param, true);
 }
@@ -4558,7 +4558,7 @@ EXPORT_SYMBOL_GPL(sched_setscheduler);
  * but our caller might not have that capability.
  */
 int sched_setscheduler_nocheck(struct task_struct *p, int policy,
-			       struct sched_param *param)
+			       const struct sched_param *param)
 {
 	return __sched_setscheduler(p, policy, param, false);
 }
kernel/softirq.c +3 -1
index 07b4f1b..be3ec11 100644
@@ -827,7 +827,9 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
 			     cpumask_any(cpu_online_mask));
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN: {
-		struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
+		static struct sched_param param = {
+			.sched_priority = MAX_RT_PRIO-1
+		};
 
 		p = per_cpu(ksoftirqd, hotcpu);
 		per_cpu(ksoftirqd, hotcpu) = NULL;
kernel/stop_machine.c +1 -1
index 70f8d90..da9bb42 100644
@@ -291,7 +291,7 @@ repeat:
 static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
 					   unsigned long action, void *hcpu)
 {
-	struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
+	static struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
 	unsigned int cpu = (unsigned long)hcpu;
 	struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
 	struct task_struct *p;
kernel/trace/trace_selftest.c +1 -1
index 250e7f9..d2ebe6e 100644
@@ -560,7 +560,7 @@ trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
 static int trace_wakeup_test_thread(void *data)
 {
 	/* Make this a RT thread, doesn't need to be too high */
-	struct sched_param param = { .sched_priority = 5 };
+	static struct sched_param param = { .sched_priority = 5 };
 	struct completion *x = data;
 
 	sched_setscheduler(current, SCHED_FIFO, &param);
kernel/watchdog.c +1 -1
index 91b0b26..95d8463 100644
@@ -310,7 +310,7 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
  */
 static int watchdog(void *unused)
 {
-	struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
+	static struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
 	struct hrtimer *hrtimer = &__raw_get_cpu_var(watchdog_hrtimer);
 
 	sched_setscheduler(current, SCHED_FIFO, &param);
kernel/workqueue.c +1 -1
index 327d2de..036939a 100644
@@ -947,7 +947,7 @@ init_cpu_workqueue(struct workqueue_struct *wq, int cpu)
 
 static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
 {
-	struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
+	static struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
 	struct workqueue_struct *wq = cwq->wq;
 	const char *fmt = is_wq_single_threaded(wq) ? "%s" : "%s/%d";
 	struct task_struct *p;
Signature · 1 line
1.6.5.2
maintainer
#30 lore raw

Re: [PATCH 2/2] sched: make sched_param arugment static variables in some sched_setscheduler() caller

Quoted 3 lines · KOSAKI Motohiro

Andrew Morton pointed out almost sched_setscheduler() caller are using fixed parameter and it can be converted static. it reduce runtume memory waste a bit.

We are replacing runtime waste with permanent waste?

Quoted 9 lines

kernel/trace/trace_selftest.c trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr) · line 565

Quoted 7 lines
kernel/trace/trace_selftest.c +1 -1
@@ -560,7 +560,7 @@ trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
 static int trace_wakeup_test_thread(void *data)
 {
 	/* Make this a RT thread, doesn't need to be too high */
-	struct sched_param param = { .sched_priority = 5 };
+	static struct sched_param param = { .sched_priority = 5 };
 	struct completion *x = data;
 

This is a thread that runs on boot up to test the sched_wakeup tracer. Then it is deleted and all memory is reclaimed.

Thus, this patch just took memory that was usable at run time and removed it permanently.

Please Cc me on all tracing changes.

-- Steve

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#31 lore raw

Re: [PATCH 2/2] sched: make sched_param arugment static variables in some sched_setscheduler() caller

Quoted 6 lines · On Tue, 06 Jul 2010 18:13:58 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · KOSAKI Motohiro

Andrew Morton pointed out almost sched_setscheduler() caller are using fixed parameter and it can be converted static. it reduce runtume memory waste a bit.

We are replacing runtime waste with permanent waste?

Confused. kernel/trace/ appears to waste resources by design, so what's the issue?

I don't think this change will cause more waste. It'll consume 4 bytes of .data and will save a little more .text.

Quoted 20 lines
Quoted 9 lines

kernel/trace/trace_selftest.c trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr) · line 565

Quoted 7 lines
kernel/trace/trace_selftest.c +1 -1
@@ -560,7 +560,7 @@ trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
 static int trace_wakeup_test_thread(void *data)
 {
 	/* Make this a RT thread, doesn't need to be too high */
-	struct sched_param param = { .sched_priority = 5 };
+	static struct sched_param param = { .sched_priority = 5 };
 	struct completion *x = data;
 

This is a thread that runs on boot up to test the sched_wakeup tracer. Then it is deleted and all memory is reclaimed.

Quoted 4 lines

Thus, this patch just took memory that was usable at run time and removed it permanently.

Please Cc me on all tracing changes.

Well if we're so worried about resource wastage then how about making all boot-time-only text and data reside in __init and __initdata sections rather than hanging around uselessly in memory for ever?

Only that's going to be hard because we went and added pointers into .init.text from .data due to `struct tracer.selftest', which will cause a storm of section mismatch warnings. Doh, should have invoked the selftests from initcalls. That might open the opportunity of running the selftests by modprobing the selftest module, too.

And I _do_ wish the selftest module was modprobeable, rather than this monstrosity:

#ifdef CONFIG_FTRACE_SELFTEST
/* Let selftest have access to static functions in this file */ #include "trace_selftest.c"
#endif

Really? Who had a tastebudectomy over there? At least call it trace_selftest.inc or something, so poor schmucks don't go scrabbling around wondering "how the hell does this thing get built oh no they didn't really go and #include it did they?"

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#32 lore raw

Re: [PATCH 2/2] sched: make sched_param arugment static variables in some sched_setscheduler() caller

Quoted 3 lines · Andrew Morton

Well if we're so worried about resource wastage then how about making all boot-time-only text and data reside in __init and __initdata sections rather than hanging around uselessly in memory for ever?

That would be a patch I would like :-)

I could probably do that when I get some time.

Quoted 6 lines

Only that's going to be hard because we went and added pointers into .init.text from .data due to `struct tracer.selftest', which will cause a storm of section mismatch warnings. Doh, should have invoked the selftests from initcalls. That might open the opportunity of running the selftests by modprobing the selftest module, too.

They are called by initcalls. The initcalls register the tracers and that is the time we call the selftest. No other time.

Is there a way that we set up a function pointer to let the section checks know that it is only called at bootup?

Quoted 3 lines

And I _do_ wish the selftest module was modprobeable, rather than this monstrosity:

The selftests are done by individual tracers at boot up. It would be hard to modprobe them at that time.

Quoted 9 lines

#ifdef CONFIG_FTRACE_SELFTEST
/* Let selftest have access to static functions in this file */ #include "trace_selftest.c"
#endif

Really? Who had a tastebudectomy over there? At least call it trace_selftest.inc or something, so poor schmucks don't go scrabbling around wondering "how the hell does this thing get built oh no they didn't really go and #include it did they?"

Well this is also the way sched.c adds all its extra code. Making it trace_selftest.inc would make it hard to know what the hell it was. And also hard for editors to know what type of file it is, or things can be missed with a 'find . -name "*.[ch]" | xargs grep blahblah'

Yes, the self tests are ugly and can probably go with an overhaul. Since we are trying to get away from the tracer plugins anyway, they will start disappearing when the plugins do.

We should have some main selftests anyway. Those are for the TRACE_EVENT tests (which are not even in the trace_selftest.c file, and the function testing which currently are, as well as the latency testers.

The trace_selftest.c should eventually be replaced with more compact tests for the specific types of tracing.

-- Steve

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#33 lore raw

Re: [PATCH 2/2] sched: make sched_param arugment static variables in some sched_setscheduler() caller

Quoted 11 lines · On Tue, 06 Jul 2010 19:49:47 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · Andrew Morton

Well if we're so worried about resource wastage then how about making all boot-time-only text and data reside in __init and __initdata sections rather than hanging around uselessly in memory for ever?

That would be a patch I would like :-)

I could probably do that when I get some time.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

Only that's going to be hard because we went and added pointers into .init.text from .data due to `struct tracer.selftest', which will cause a storm of section mismatch warnings. Doh, should have invoked the selftests from initcalls. That might open the opportunity of running the selftests by modprobing the selftest module, too.

They are called by initcalls. The initcalls register the tracers and that is the time we call the selftest. No other time.

It should all be __init!

Quoted 2 lines

Is there a way that we set up a function pointer to let the section checks know that it is only called at bootup?

<sticks his nose in modpost.c for the first time>

There are various whitelisting hacks in there based on the name of the offending symbol. Search term: DEFAULT_SYMBOL_WHITE_LIST.

It'd be cleaner to just zap the tracer.selftest field altogether and run the tests from initcalls if possible?

Quoted 6 lines
Quoted 3 lines

And I _do_ wish the selftest module was modprobeable, rather than this monstrosity:

The selftests are done by individual tracers at boot up. It would be hard to modprobe them at that time.

No, if tracer_selftest.o was linked into vmlinux then the tests get run within do_initcalls(). If tracer_selftest.o is a module, then the tests get run at modprobe-time. The latter option may not be terribly useful but it comes basically for free as a reward for doing stuff correctly.

Quoted 6 lines
Quoted 6 lines

#ifdef CONFIG_FTRACE_SELFTEST
/* Let selftest have access to static functions in this file */ #include "trace_selftest.c"
#endif

Quoted 7 lines
Quoted 4 lines

Really? Who had a tastebudectomy over there? At least call it trace_selftest.inc or something, so poor schmucks don't go scrabbling around wondering "how the hell does this thing get built oh no they didn't really go and #include it did they?"

Well this is also the way sched.c adds all its extra code.

The sched.c hack sucks too.

Quoted 2 lines

Making it
trace_selftest.inc would make it hard to know what the hell it was.

trace_selftest.i_really_suck?

Quoted 3 lines

And
also hard for editors to know what type of file it is, or things can be missed with a 'find . -name "*.[ch]" | xargs grep blahblah'

Well bad luck. Of _course_ it makes a mess. It's already a mess.

How's about just removing the `static' from whichever symbols tracer_selftest needs? That'd surely be better than #including a .c file.

Quoted 10 lines

Yes, the self tests are ugly and can probably go with an overhaul. Since we are trying to get away from the tracer plugins anyway, they will start disappearing when the plugins do.

We should have some main selftests anyway. Those are for the TRACE_EVENT tests (which are not even in the trace_selftest.c file, and the function testing which currently are, as well as the latency testers.

The trace_selftest.c should eventually be replaced with more compact tests for the specific types of tracing.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#34 lore raw

Re: [PATCH 2/2] sched: make sched_param arugment static variables in some sched_setscheduler() caller

Quoted 3 lines · Andrew Morton
Quoted 1 line

Well this is also the way sched.c adds all its extra code.

The sched.c hack sucks too.

Agreed, moving things to kernel/sched/ and adding some internal.h thing could cure that, but I simply haven't gotten around to cleaning that up..

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#35 lore raw

PATCH 11/11 oom: multi threaded process coredump don't make deadlock

In reply to KOSAKI Motohiro

Oleg pointed out current PF_EXITING check is wrong. Because PF_EXITING is per-thread flag, not per-process flag. He said,

Two threads, group-leader L and its sub-thread T. T dumps the code. In this case both threads have ->mm != NULL, L has PF_EXITING.

The first problem is, select_bad_process() always return -1 in this case (even if the caller is T, this doesn't matter).

The second problem is that we should add TIF_MEMDIE to T, not L.

I think we can remove this dubious PF_EXITING check. but as first step, This patch add the protection of multi threaded issue.

---
 mm/oom_kill.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/oom_kill.c +1 -1
index 0858b18..b04e557 100644
@@ -360,7 +360,7 @@ static struct task_struct *select_bad_process(unsigned long *ppoints,
 		 * the process of exiting and releasing its resources.
 		 * Otherwise we could get an easy OOM deadlock.
 		 */
-		if ((p->flags & PF_EXITING) && p->mm) {
+		if (thread_group_empty(p) && (p->flags & PF_EXITING) && p->mm) {
 			if (p != current)
 				return ERR_PTR(-1UL);
 
Signature · 1 line
1.6.5.2