From: Greg Kroah-Hartman Date: Tue, 10 Apr 2012 20:11:07 +0000 (-0700) Subject: 3.3-stable patches X-Git-Tag: v3.3.2~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e3101089d4fa4f95dc25d49a5023e6b2755dbea4;p=thirdparty%2Fkernel%2Fstable-queue.git 3.3-stable patches added patches: android-lowmemorykiller-remove-task-handoff-notifier.patch --- diff --git a/queue-3.3/android-lowmemorykiller-remove-task-handoff-notifier.patch b/queue-3.3/android-lowmemorykiller-remove-task-handoff-notifier.patch new file mode 100644 index 00000000000..ab02e4d833a --- /dev/null +++ b/queue-3.3/android-lowmemorykiller-remove-task-handoff-notifier.patch @@ -0,0 +1,138 @@ +From 83dbbdbb38666e20a75fad2294cf1df77c52f121 Mon Sep 17 00:00:00 2001 +From: David Rientjes +Date: Mon, 9 Apr 2012 16:56:18 -0700 +Subject: android, lowmemorykiller: remove task handoff notifier + +From: David Rientjes + +commit 83dbbdbb38666e20a75fad2294cf1df77c52f121 upstream. + +The task handoff notifier leaks task_struct since it never gets freed +after the callback returns NOTIFY_OK, which means it is responsible for +doing so. + +It turns out the lowmemorykiller actually doesn't need this notifier at +all. It's used to prevent unnecessary killing by waiting for a thread +to exit as a result of lowmem_shrink(), however, it's possible to do +this in the same way the kernel oom killer works by setting TIF_MEMDIE +and avoid killing if we're still waiting for it to exit. + +The kernel oom killer will already automatically set TIF_MEMDIE for +threads that are attempting to allocate memory that have a fatal signal. +The thread selected by lowmem_shrink() will have such a signal after the +lowmemorykiller sends it a SIGKILL, so this won't result in an +unnecessary use of memory reserves for the thread to exit. + +This has the added benefit that we don't have to rely on +CONFIG_PROFILING to prevent needlessly killing tasks. + +Reported-by: Werner Landgraf +Signed-off-by: David Rientjes +Acked-by: Colin Cross +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/staging/android/lowmemorykiller.c | 47 +++--------------------------- + 1 file changed, 6 insertions(+), 41 deletions(-) + +--- a/drivers/staging/android/lowmemorykiller.c ++++ b/drivers/staging/android/lowmemorykiller.c +@@ -53,7 +53,6 @@ static size_t lowmem_minfree[6] = { + }; + static int lowmem_minfree_size = 4; + +-static struct task_struct *lowmem_deathpending; + static unsigned long lowmem_deathpending_timeout; + + #define lowmem_print(level, x...) \ +@@ -62,24 +61,6 @@ static unsigned long lowmem_deathpending + printk(x); \ + } while (0) + +-static int +-task_notify_func(struct notifier_block *self, unsigned long val, void *data); +- +-static struct notifier_block task_nb = { +- .notifier_call = task_notify_func, +-}; +- +-static int +-task_notify_func(struct notifier_block *self, unsigned long val, void *data) +-{ +- struct task_struct *task = data; +- +- if (task == lowmem_deathpending) +- lowmem_deathpending = NULL; +- +- return NOTIFY_OK; +-} +- + static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc) + { + struct task_struct *p; +@@ -95,19 +76,6 @@ static int lowmem_shrink(struct shrinker + int other_file = global_page_state(NR_FILE_PAGES) - + global_page_state(NR_SHMEM); + +- /* +- * If we already have a death outstanding, then +- * bail out right away; indicating to vmscan +- * that we have nothing further to offer on +- * this pass. +- * +- * Note: Currently you need CONFIG_PROFILING +- * for this to work correctly. +- */ +- if (lowmem_deathpending && +- time_before_eq(jiffies, lowmem_deathpending_timeout)) +- return 0; +- + if (lowmem_adj_size < array_size) + array_size = lowmem_adj_size; + if (lowmem_minfree_size < array_size) +@@ -140,6 +108,11 @@ static int lowmem_shrink(struct shrinker + struct signal_struct *sig; + int oom_adj; + ++ if (test_tsk_thread_flag(p, TIF_MEMDIE) && ++ time_before_eq(jiffies, lowmem_deathpending_timeout)) { ++ read_unlock(&tasklist_lock); ++ return 0; ++ } + task_lock(p); + mm = p->mm; + sig = p->signal; +@@ -173,15 +146,9 @@ static int lowmem_shrink(struct shrinker + lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n", + selected->pid, selected->comm, + selected_oom_adj, selected_tasksize); +- /* +- * If CONFIG_PROFILING is off, then we don't want to stall +- * the killer by setting lowmem_deathpending. +- */ +-#ifdef CONFIG_PROFILING +- lowmem_deathpending = selected; + lowmem_deathpending_timeout = jiffies + HZ; +-#endif + force_sig(SIGKILL, selected); ++ set_tsk_thread_flag(selected, TIF_MEMDIE); + rem -= selected_tasksize; + } + lowmem_print(4, "lowmem_shrink %lu, %x, return %d\n", +@@ -197,7 +164,6 @@ static struct shrinker lowmem_shrinker = + + static int __init lowmem_init(void) + { +- task_handoff_register(&task_nb); + register_shrinker(&lowmem_shrinker); + return 0; + } +@@ -205,7 +171,6 @@ static int __init lowmem_init(void) + static void __exit lowmem_exit(void) + { + unregister_shrinker(&lowmem_shrinker); +- task_handoff_unregister(&task_nb); + } + + module_param_named(cost, lowmem_shrinker.seeks, int, S_IRUGO | S_IWUSR); diff --git a/queue-3.3/series b/queue-3.3/series index a3f1ac7d99a..d79cf2fa5c3 100644 --- a/queue-3.3/series +++ b/queue-3.3/series @@ -60,3 +60,4 @@ sysctl-fix-write-access-to-dmesg_restrict-kptr_restrict.patch regmap-prevent-division-by-zero-in-rbtree_show.patch modpost-fix-modpost-license-checking-of-vmlinux.o.patch mfd-fix-section-mismatch-warning-for-da9052-spi.patch +android-lowmemorykiller-remove-task-handoff-notifier.patch