[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1424557146-29965-4-git-send-email-xypron.glpk@gmx.de>
Date: Sat, 21 Feb 2015 23:19:06 +0100
From: Heinrich Schuchardt <xypron.glpk@....de>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Joe Perches <joe@...ches.com>,
Peter Zijlstra <peterz@...radead.org>,
Oleg Nesterov <oleg@...hat.com>,
Ingo Molnar <mingo@...nel.org>,
Vladimir Davydov <vdavydov@...allels.com>,
Thomas Gleixner <tglx@...utronix.de>,
Kees Cook <keescook@...omium.org>,
David Rientjes <rientjes@...gle.com>,
Johannes Weiner <hannes@...xchg.org>,
"David S. Miller" <davem@...emloft.net>,
Andy Lutomirski <luto@...capital.net>,
Michael Marineau <mike@...ineau.org>,
Aaron Tomlin <atomlin@...hat.com>,
Prarit Bhargava <prarit@...hat.com>,
Steven Rostedt <rostedt@...dmis.org>,
Jens Axboe <axboe@...com>,
"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
Rik van Riel <riel@...hat.com>,
Davidlohr Bueso <dave@...olabs.net>,
Guenter Roeck <linux@...ck-us.net>,
linux-kernel@...r.kernel.org,
Heinrich Schuchardt <xypron.glpk@....de>
Subject: [PATCH 3/3 v3] kernel/fork.c: memory hotplug updates max_threads
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 <xypron.glpk@....de>
---
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 <linux/aio.h>
#include <linux/compiler.h>
#include <linux/sysctl.h>
+#include <linux/memory.h>
+#include <linux/notifier.h>
#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists