Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753032AbbBWUR3 (ORCPT ); Mon, 23 Feb 2015 15:17:29 -0500 Received: from mout.gmx.net ([212.227.15.19]:49700 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752993AbbBWURZ (ORCPT ); Mon, 23 Feb 2015 15:17:25 -0500 From: Heinrich Schuchardt To: Andrew Morton Cc: Aaron Tomlin , Andy Lutomirski , Davidlohr Bueso , David Rientjes , "David S. Miller" , Fabian Frederick , Guenter Roeck , "H. Peter Anvin" , Ingo Molnar , Jens Axboe , Joe Perches , Johannes Weiner , Kees Cook , Michael Marineau , Oleg Nesterov , "Paul E. McKenney" , Peter Zijlstra , Prarit Bhargava , Rik van Riel , Rusty Russell , Steven Rostedt , Thomas Gleixner , Vladimir Davydov , linux-kernel@vger.kernel.org, Heinrich Schuchardt Subject: [PATCH 4/4 v4] kernel/fork.c: memory hotplug updates max_threads Date: Mon, 23 Feb 2015 21:14:37 +0100 Message-Id: <1424722477-23758-5-git-send-email-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1424722477-23758-1-git-send-email-xypron.glpk@gmx.de> References: <20150222075825.GA20626@gmail.com> <1424722477-23758-1-git-send-email-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:MwrJa+0+XKqomvx6AqA3QY2iSu5cQm8PAw5pqmY8RkmYWqGTG8G MWFGp9zlOAPqLmDVl5pzSYvVpNTLOy+KKfPEkzKyQw51VUWEyRJfZOm4kLIBKwf1fO99gpo Q+so006l+AZBS4VD7gM2V+BBuDQkDfcPYV97T9e2qi02jQulkPzJpZHXnqYhHN/8lHfTWn/ k1LsThLwIarh5lkVjAsxg== X-UI-Out-Filterresults: notjunk:1; Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2150 Lines: 81 Memory may be added or removed while the system is online. With the patch the value of max_threads is updated accordingly. The limits of the init process are also updated. This does not include updating limits of other running processes. Tested with commands like echo 5000 > /proc/sys/kernel/threads-max echo 0 > /sys/devices/system/memory/memory7/online cat /proc/sys/kernel/threads-max echo 1 > /sys/devices/system/memory/memory7/online cat /proc/sys/kernel/threads-max Signed-off-by: Heinrich Schuchardt --- kernel/fork.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index 33b084e..7fd7c0a9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -75,6 +75,8 @@ #include #include #include +#include +#include #include #include @@ -295,6 +297,31 @@ static void set_max_threads(unsigned int max_threads_suggested) init_task.signal->rlim[RLIMIT_NPROC]; } +/* + * Callback function called for memory hotplug events. + */ +static int memory_hotplug_callback(struct notifier_block *self, + unsigned long action, void *arg) +{ + switch (action) { + case MEM_ONLINE: + /* + * If memory was added, try to maximize the number of allowed + * threads. + */ + set_max_threads(UINT_MAX); + break; + case MEM_OFFLINE: + /* + * If memory was removed, try to keep current value. + */ + set_max_threads(max_threads); + break; + } + + return NOTIFY_OK; +} + void __init fork_init(void) { #ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR @@ -311,6 +338,8 @@ void __init fork_init(void) arch_task_cache_init(); set_max_threads(UINT_MAX); + + hotplug_memory_notifier(memory_hotplug_callback, 0); } int __weak arch_dup_task_struct(struct task_struct *dst, -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/