Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752145AbbBUWUn (ORCPT ); Sat, 21 Feb 2015 17:20:43 -0500 Received: from mout.gmx.net ([212.227.17.20]:50440 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751850AbbBUWUl (ORCPT ); Sat, 21 Feb 2015 17:20:41 -0500 From: Heinrich Schuchardt To: Andrew Morton Cc: Joe Perches , Peter Zijlstra , Oleg Nesterov , Ingo Molnar , Vladimir Davydov , Thomas Gleixner , Kees Cook , David Rientjes , Johannes Weiner , "David S. Miller" , Andy Lutomirski , Michael Marineau , Aaron Tomlin , Prarit Bhargava , Steven Rostedt , Jens Axboe , "Paul E. McKenney" , Rik van Riel , Davidlohr Bueso , Guenter Roeck , linux-kernel@vger.kernel.org, Heinrich Schuchardt Subject: [PATCH 3/3 v3] kernel/fork.c: memory hotplug updates max_threads Date: Sat, 21 Feb 2015 23:19:06 +0100 Message-Id: <1424557146-29965-4-git-send-email-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1424557146-29965-1-git-send-email-xypron.glpk@gmx.de> References: <20150218122851.d1ae723ff12887f9ab919431@linux-foundation.org> <1424557146-29965-1-git-send-email-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:CxL3ZgHwbEgDSGghatjMdIlQZEJkUJ+86ExncwQ7WqUXW8USHwh wUzMIrvuXnyX/Em8MC3nCZxvyg9tBvK+CN6T4K0rPLAPIVzTZDgEioYyI4zZEP95mYI3wiS piSMvYEhmcFOUij6vt7sqMJrO8InFqdwfDRs7ZotB/DMmLKsNFSJIiXsNYfMqvgY+j07GQC nvgS4dgcKwb9755BpRMhw== 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: 2185 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 38ffce5..7125be3 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(unsigned long mempages) { #ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR @@ -311,6 +338,8 @@ void __init fork_init(unsigned long mempages) 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/