Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752047AbbBUWUI (ORCPT ); Sat, 21 Feb 2015 17:20:08 -0500 Received: from mout.gmx.net ([212.227.17.20]:65525 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751734AbbBUWUE (ORCPT ); Sat, 21 Feb 2015 17:20:04 -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 2/3 v3] kernel/sysctl.c: threads-max observe limits Date: Sat, 21 Feb 2015 23:19:05 +0100 Message-Id: <1424557146-29965-3-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:e8Z0kuHXy+DlecTwQE8ELKaaPeSbabn/OFodALJTP/ysEz1Wers 9lLAQdPwdnls606yptVadS6FeCg2Gc2z/vA1KCi/nO7N6TB0JNTSylROZw/CnohY7Ofv5L7 RISurSgxofLt+Nj8BnJlWv2CGI7DJSyKUNOQF5gA0m/VnLwyuZlDH5nCfffgt+qulFKnQKL 0D2+iiZG8Wz7W/1/g2UiA== 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: 2745 Lines: 104 Users can change the maximum number of threads by writing to /proc/sys/kernel/threads-max. With the patch the value entered is checked according to the same limits that apply when fork_init is called. Furthermore the limits of the init process are adjusted. This will not update limits of any other existing processes. Signed-off-by: Heinrich Schuchardt --- include/linux/sysctl.h | 3 +++ kernel/fork.c | 24 ++++++++++++++++++++++++ kernel/sysctl.c | 6 ++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index b7361f8..795d5fe 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -212,4 +212,7 @@ static inline void setup_sysctl_set(struct ctl_table_set *p, #endif /* CONFIG_SYSCTL */ +int sysctl_max_threads(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos); + #endif /* _LINUX_SYSCTL_H */ diff --git a/kernel/fork.c b/kernel/fork.c index 69c30cd..38ffce5 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -74,6 +74,7 @@ #include #include #include +#include #include #include @@ -2024,3 +2025,26 @@ int unshare_files(struct files_struct **displaced) task_unlock(task); return 0; } + +int sysctl_max_threads(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos) +{ + struct ctl_table t; + int ret; + int threads = max_threads; + int min = MIN_THREADS; + int max = MAX_THREADS; + + t = *table; + t.data = &threads; + t.extra1 = &min; + t.extra2 = &max; + + ret = proc_dointvec_minmax(&t, write, buffer, lenp, ppos); + if (ret || !write) + return ret; + + set_max_threads(threads); + + return 0; +} diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 137c7f6..2e195ae 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -92,11 +92,9 @@ #include #endif - #if defined(CONFIG_SYSCTL) /* External variables not in a header file. */ -extern int max_threads; extern int suid_dumpable; #ifdef CONFIG_COREDUMP extern int core_uses_pid; @@ -709,10 +707,10 @@ static struct ctl_table kern_table[] = { #endif { .procname = "threads-max", - .data = &max_threads, + .data = NULL, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = sysctl_max_threads, }, { .procname = "random", -- 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/