public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lowmemorykiller: prevent multiple instances of low memory killer
@ 2013-04-15 13:03 Oskar Andero
  2013-04-15 13:18 ` Dan Carpenter
  0 siblings, 1 reply; 13+ messages in thread
From: Oskar Andero @ 2013-04-15 13:03 UTC (permalink / raw)
  To: linux-kernel, devel
  Cc: Greg Kroah-Hartman, Brian Swetland, Radovan Lekanovic,
	Snild Dolkow, Oskar Andero

From: Snild Dolkow <snild.dolkow@sonymobile.com>

Running multiple instances of LMK is not useful since it will try to
kill the same process.

This patch adds a spinlock to prevent multiple instances of the LMK
running at the same time. Uses spin_trylock and return on failure to
avoid blocking.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Brian Swetland <swetland@google.com>
Reviewed-by: Radovan Lekanovic <radovan.lekanovic@sonymobile.com>
Signed-off-by: Snild Dolkow <snild.dolkow@sonymobile.com>
Signed-off-by: Oskar Andero <oskar.andero@sonymobile.com>
---
 drivers/staging/android/lowmemorykiller.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c
index 3b91b0f..0b19353 100644
--- a/drivers/staging/android/lowmemorykiller.c
+++ b/drivers/staging/android/lowmemorykiller.c
@@ -38,6 +38,7 @@
 #include <linux/rcupdate.h>
 #include <linux/profile.h>
 #include <linux/notifier.h>
+#include <linux/spinlock.h>
 
 static uint32_t lowmem_debug_level = 2;
 static short lowmem_adj[6] = {
@@ -57,6 +58,8 @@ static int lowmem_minfree_size = 4;
 
 static unsigned long lowmem_deathpending_timeout;
 
+#define LMK_BUSY (-1)
+
 #define lowmem_print(level, x...)			\
 	do {						\
 		if (lowmem_debug_level >= (level))	\
@@ -65,6 +68,7 @@ static unsigned long lowmem_deathpending_timeout;
 
 static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
 {
+	static DEFINE_SPINLOCK(lowmem_lock);
 	struct task_struct *tsk;
 	struct task_struct *selected = NULL;
 	int rem = 0;
@@ -104,6 +108,9 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
 	}
 	selected_oom_score_adj = min_score_adj;
 
+	if (spin_trylock(&lowmem_lock) == 0)
+		return LMK_BUSY;
+
 	rcu_read_lock();
 	for_each_process(tsk) {
 		struct task_struct *p;
@@ -120,6 +127,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
 		    time_before_eq(jiffies, lowmem_deathpending_timeout)) {
 			task_unlock(p);
 			rcu_read_unlock();
+			spin_unlock(&lowmem_lock);
 			return 0;
 		}
 		oom_score_adj = p->signal->oom_score_adj;
@@ -156,6 +164,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
 	lowmem_print(4, "lowmem_shrink %lu, %x, return %d\n",
 		     sc->nr_to_scan, sc->gfp_mask, rem);
 	rcu_read_unlock();
+	spin_unlock(&lowmem_lock);
 	return rem;
 }
 
-- 
1.8.1.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-04-24  8:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-15 13:03 [PATCH] lowmemorykiller: prevent multiple instances of low memory killer Oskar Andero
2013-04-15 13:18 ` Dan Carpenter
2013-04-15 13:38   ` Dolkow, Snild
2013-04-15 14:13     ` Dan Carpenter
2013-04-15 15:03       ` Oskar Andero
2013-04-15 18:28         ` Dolkow, Snild
2013-04-15 19:49           ` Greg Kroah-Hartman
2013-04-15 23:11             ` David Rientjes
2013-04-16  6:19               ` Dan Carpenter
2013-04-16 10:59                 ` Oskar Andero
2013-04-16 20:00                   ` David Rientjes
2013-04-23 21:54                     ` Oskar Andero
2013-04-24  8:33                     ` Dolkow, Snild

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox