linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anton Vorontsov <anton.vorontsov@linaro.org>
To: "Arve Hjønnevåg" <arve@android.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com>,
	Greg Kroah-Hartman <gregkh@suse.de>, San Mehat <san@google.com>,
	Colin Cross <ccross@android.com>, Oleg Nesterov <oleg@redhat.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-kernel@vger.kernel.org, kernel-team@android.com,
	linaro-kernel@lists.linaro.org
Subject: [PATCH 3/3] staging: android: lowmemorykiller: Drop tasklist_lock usage
Date: Mon, 30 Jan 2012 05:13:48 +0400	[thread overview]
Message-ID: <20120130011348.GC30274@oksana.dev.rtsoft.ru> (raw)

Instead of walking through the whole task list (where we must hold the
task list lock for the whole period while we search for the victim),
let's take procfs' approach of walking up the tgids (for_each_tgit()
walks a pidmap, which internally grabs an rcu lock, but only while
it searches for the next tgid).

Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
---
 drivers/staging/android/lowmemorykiller.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c
index 2d8d2b7..a9edb53 100644
--- a/drivers/staging/android/lowmemorykiller.c
+++ b/drivers/staging/android/lowmemorykiller.c
@@ -34,6 +34,7 @@
 #include <linux/mm.h>
 #include <linux/oom.h>
 #include <linux/sched.h>
+#include <linux/pid.h>
 #include <linux/profile.h>
 #include <linux/notifier.h>
 
@@ -81,7 +82,8 @@ task_notify_func(struct notifier_block *self, unsigned long val, void *data)
 
 static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
 {
-	struct task_struct *p;
+	struct pid_namespace *ns = &init_pid_ns;
+	struct tgid_iter iter = {};
 	struct task_struct *selected = NULL;
 	int rem = 0;
 	int tasksize;
@@ -132,8 +134,8 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
 	}
 	selected_oom_adj = min_adj;
 
-	read_lock(&tasklist_lock);
-	for_each_process(p) {
+	for_each_tgid(ns, iter) {
+		struct task_struct *p = iter.task;
 		struct mm_struct *mm;
 		struct signal_struct *sig;
 		int oom_adj;
@@ -160,7 +162,9 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
 			if (oom_adj == selected_oom_adj &&
 			    tasksize <= selected_tasksize)
 				continue;
+			put_task_struct(selected);
 		}
+		get_task_struct(p);
 		selected = p;
 		selected_tasksize = tasksize;
 		selected_oom_adj = oom_adj;
@@ -181,11 +185,11 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
 		task_handoff_register(&task_nb);
 #endif
 		force_sig(SIGKILL, selected);
+		put_task_struct(selected);
 		rem -= selected_tasksize;
 	}
 	lowmem_print(4, "lowmem_shrink %lu, %x, return %d\n",
 		     sc->nr_to_scan, sc->gfp_mask, rem);
-	read_unlock(&tasklist_lock);
 	return rem;
 }
 
-- 
1.7.7

             reply	other threads:[~2012-01-30  1:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-30  1:13 Anton Vorontsov [this message]
2012-01-30 13:46 ` [PATCH 3/3] staging: android: lowmemorykiller: Drop tasklist_lock usage Oleg Nesterov

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=20120130011348.GC30274@oksana.dev.rtsoft.ru \
    --to=anton.vorontsov@linaro.org \
    --cc=arve@android.com \
    --cc=ccross@android.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@suse.de \
    --cc=kernel-team@android.com \
    --cc=kosaki.motohiro@gmail.com \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=san@google.com \
    /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;
as well as URLs for NNTP newsgroup(s).