From: David Rientjes <rientjes@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Michal Hocko <mhocko@suse.cz>,
Johannes Weiner <hannes@cmpxchg.org>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Minchan Kim <minchan@kernel.org>,
linux-mm@kvack.org, cgroups@vger.kernel.org
Subject: [rfc][patch 2/3] mm, oom: introduce helper function to process threads during scan
Date: Mon, 25 Jun 2012 18:47:49 -0700 (PDT) [thread overview]
Message-ID: <alpine.DEB.2.00.1206251846450.24838@chino.kir.corp.google.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1206251846020.24838@chino.kir.corp.google.com>
This patch introduces a helper function to process each thread during the
iteration over the tasklist. A new return type, enum oom_scan_t, is
defined to determine the future behavior of the iteration:
- OOM_SCAN_OK: continue scanning the thread and find its badness,
- OOM_SCAN_CONTINUE: do not consider this thread for oom kill, it's
ineligible,
- OOM_SCAN_ABORT: abort the iteration and return, or
- OOM_SCAN_SELECT: always select this thread with the highest badness
possible.
There is no functional change with this patch. This new helper function
will be used in the next patch in the memory controller.
Signed-off-by: David Rientjes <rientjes@google.com>
---
mm/oom_kill.c | 111 +++++++++++++++++++++++++++++++++------------------------
1 file changed, 65 insertions(+), 46 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -288,6 +288,59 @@ static enum oom_constraint constrained_alloc(struct zonelist *zonelist,
}
#endif
+enum oom_scan_t {
+ OOM_SCAN_OK,
+ OOM_SCAN_CONTINUE,
+ OOM_SCAN_ABORT,
+ OOM_SCAN_SELECT,
+};
+
+static enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
+ struct mem_cgroup *memcg, unsigned long totalpages,
+ const nodemask_t *nodemask, bool force_kill)
+{
+ if (task->exit_state)
+ return OOM_SCAN_CONTINUE;
+ if (oom_unkillable_task(task, memcg, nodemask))
+ return OOM_SCAN_CONTINUE;
+
+ /*
+ * This task already has access to memory reserves and is being killed.
+ * Don't allow any other task to have access to the reserves.
+ */
+ if (test_tsk_thread_flag(task, TIF_MEMDIE)) {
+ if (unlikely(frozen(task)))
+ __thaw_task(task);
+ if (!force_kill)
+ return OOM_SCAN_ABORT;
+ }
+ if (!task->mm)
+ return OOM_SCAN_CONTINUE;
+
+ if (task->flags & PF_EXITING) {
+ /*
+ * If task is current and is in the process of releasing memory,
+ * allow the "kill" to set TIF_MEMDIE, which will allow it to
+ * access memory reserves. Otherwise, it may stall forever.
+ *
+ * The iteration isn't broken here, however, in case other
+ * threads are found to have already been oom killed.
+ */
+ if (task == current)
+ return OOM_SCAN_SELECT;
+ else if (!force_kill) {
+ /*
+ * If this task is not being ptraced on exit, then wait
+ * for it to finish before killing some other task
+ * unnecessarily.
+ */
+ if (!(task->group_leader->ptrace & PT_TRACE_EXIT))
+ return OOM_SCAN_ABORT;
+ }
+ }
+ return OOM_SCAN_OK;
+}
+
/*
* Simple selection loop. We chose the process with the highest
* number of 'points'. We expect the caller will lock the tasklist.
@@ -305,53 +358,19 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
do_each_thread(g, p) {
unsigned int points;
- if (p->exit_state)
- continue;
- if (oom_unkillable_task(p, memcg, nodemask))
- continue;
-
- /*
- * This task already has access to memory reserves and is
- * being killed. Don't allow any other task access to the
- * memory reserve.
- *
- * Note: this may have a chance of deadlock if it gets
- * blocked waiting for another task which itself is waiting
- * for memory. Is there a better alternative?
- */
- if (test_tsk_thread_flag(p, TIF_MEMDIE)) {
- if (unlikely(frozen(p)))
- __thaw_task(p);
- if (!force_kill)
- return ERR_PTR(-1UL);
- }
- if (!p->mm)
+ switch (oom_scan_process_thread(p, memcg, totalpages, nodemask,
+ force_kill)) {
+ case OOM_SCAN_SELECT:
+ chosen = p;
+ chosen_points = ULONG_MAX;
+ /* fall through */
+ case OOM_SCAN_CONTINUE:
continue;
-
- if (p->flags & PF_EXITING) {
- /*
- * If p is the current task and is in the process of
- * releasing memory, we allow the "kill" to set
- * TIF_MEMDIE, which will allow it to gain access to
- * memory reserves. Otherwise, it may stall forever.
- *
- * The loop isn't broken here, however, in case other
- * threads are found to have already been oom killed.
- */
- if (p == current) {
- chosen = p;
- chosen_points = ULONG_MAX;
- } else if (!force_kill) {
- /*
- * If this task is not being ptraced on exit,
- * then wait for it to finish before killing
- * some other task unnecessarily.
- */
- if (!(p->group_leader->ptrace & PT_TRACE_EXIT))
- return ERR_PTR(-1UL);
- }
- }
-
+ case OOM_SCAN_ABORT:
+ return ERR_PTR(-1UL);
+ case OOM_SCAN_OK:
+ break;
+ };
points = oom_badness(p, memcg, nodemask, totalpages);
if (points > chosen_points) {
chosen = p;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-06-26 1:47 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-26 1:47 [patch 1/3] mm, oom: move declaration for mem_cgroup_out_of_memory to oom.h David Rientjes
2012-06-26 1:47 ` David Rientjes [this message]
2012-06-26 3:22 ` [rfc][patch 2/3] mm, oom: introduce helper function to process threads during scan Kamezawa Hiroyuki
2012-06-26 6:05 ` KOSAKI Motohiro
2012-06-26 8:48 ` Michal Hocko
2012-06-26 1:47 ` [rfc][patch 3/3] mm, memcg: introduce own oom handler to iterate only over its own threads David Rientjes
2012-06-26 5:32 ` Kamezawa Hiroyuki
2012-06-26 20:38 ` David Rientjes
2012-06-27 5:35 ` David Rientjes
2012-06-28 1:43 ` David Rientjes
2012-06-28 17:16 ` Oleg Nesterov
2012-06-29 20:37 ` David Rientjes
2012-06-28 8:55 ` Kamezawa Hiroyuki
2012-06-29 20:30 ` David Rientjes
2012-07-03 17:56 ` Oleg Nesterov
2012-06-28 8:52 ` Kamezawa Hiroyuki
2012-06-26 9:58 ` Michal Hocko
2012-06-26 3:12 ` [patch 1/3] mm, oom: move declaration for mem_cgroup_out_of_memory to oom.h Kamezawa Hiroyuki
2012-06-26 6:04 ` KOSAKI Motohiro
2012-06-26 8:34 ` Michal Hocko
2012-06-29 21:06 ` [patch 1/5] " David Rientjes
2012-06-29 21:06 ` [patch 2/5] mm, oom: introduce helper function to process threads during scan David Rientjes
2012-07-12 7:18 ` Sha Zhengju
2012-06-29 21:06 ` [patch 3/5] mm, memcg: introduce own oom handler to iterate only over its own threads David Rientjes
2012-07-10 21:19 ` Andrew Morton
2012-07-10 23:24 ` David Rientjes
2012-07-12 14:50 ` Sha Zhengju
2012-06-29 21:06 ` [patch 4/5] mm, oom: reduce dependency on tasklist_lock David Rientjes
2012-07-03 18:17 ` Oleg Nesterov
2012-07-10 21:04 ` David Rientjes
2012-07-13 14:32 ` Michal Hocko
2012-07-16 7:42 ` [PATCH mmotm] mm, oom: reduce dependency on tasklist_lock: fix Hugh Dickins
2012-07-16 8:06 ` Michal Hocko
2012-07-16 9:01 ` Hugh Dickins
2012-07-16 9:27 ` Michal Hocko
2012-07-19 10:11 ` Kamezawa Hiroyuki
2012-06-29 21:07 ` [patch 5/5] mm, memcg: move all oom handling to memcontrol.c David Rientjes
2012-07-04 5:51 ` Kamezawa Hiroyuki
2012-07-13 14:34 ` Michal Hocko
2012-07-10 21:05 ` [patch 1/5] mm, oom: move declaration for mem_cgroup_out_of_memory to oom.h David Rientjes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.00.1206251846450.24838@chino.kir.corp.google.com \
--to=rientjes@google.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
--cc=minchan@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox