linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 3/3] mm: reinititalise user and admin reserves if memory is added or removed
@ 2013-04-08 19:07 Andrew Shewmaker
  2013-04-08 20:37 ` Andrew Morton
  2013-04-08 20:57 ` Andrew Morton
  0 siblings, 2 replies; 11+ messages in thread
From: Andrew Shewmaker @ 2013-04-08 19:07 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, alan, simon.jeons, ric.masonn

This patch alters the admin and user reserves of the previous patches 
in this series when memory is added or removed.

If memory is added and the reserves have been eliminated or increased above
the default max, then we'll trust the admin.

If memory is removed and there isn't enough free memory, then we
need to reset the reserves.

Otherwise keep the reserve set by the admin.

The reserve reset code is the same as the reserve initialization code.

Does this sound reasonable to other people? I figured that hot removal
with too large of memory in the reserves was the most important case 
to get right.

I tested hot addition and removal by triggering it via sysfs. The reserves 
shrunk when they were set high and memory was removed. They were reset 
higher when memory was added again.

---
 mm/mmap.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index 8fb9d99..321348b 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -33,6 +33,8 @@
 #include <linux/uprobes.h>
 #include <linux/rbtree_augmented.h>
 #include <linux/sched/sysctl.h>
+#include <linux/notifier.h>
+#include <linux/memory.h>
 
 #include <asm/uaccess.h>
 #include <asm/cacheflush.h>
@@ -3111,3 +3113,64 @@ int __meminit init_admin_reserve(void)
 	return 0;
 }
 module_init(init_admin_reserve)
+
+/*
+ * Reinititalise user and admin reserves if memory is added or removed.
+ *
+ * If memory is added and the reserves have been eliminated or increased above
+ * the default max, then we'll trust the admin. 
+ *
+ * If memory is removed and there isn't enough free memory, then we 
+ * need to reset the reserves.
+ *
+ * Otherwise keep the reserve set by the admin.
+ */
+static int reserve_mem_notifier(struct notifier_block *nb,
+			     unsigned long action, void *data)
+{
+	unsigned long tmp, free_kbytes;
+
+	switch (action) {
+	case MEM_ONLINE:
+		tmp = sysctl_user_reserve_kbytes;
+		if (0 < tmp && tmp < (1UL << 17))
+			init_user_reserve();
+
+		tmp = sysctl_admin_reserve_kbytes;
+		if (0 < tmp && tmp < (1UL << 13))
+			init_admin_reserve();
+
+		break;
+	case MEM_OFFLINE:
+		free_kbytes = global_page_state(NR_FREE_PAGES) << (PAGE_SHIFT - 10);
+
+		if (sysctl_user_reserve_kbytes > free_kbytes) {
+			init_user_reserve();
+			pr_info("vm.user_reserve_kbytes reset to %lu\n",
+				sysctl_user_reserve_kbytes);
+		}
+
+		if (sysctl_admin_reserve_kbytes > free_kbytes) {
+			init_admin_reserve();
+			pr_info("vm.admin_reserve_kbytes reset to %lu\n",
+				sysctl_admin_reserve_kbytes);
+		}
+		break;
+	default:
+		break;
+	}
+	return NOTIFY_OK;
+}
+
+static struct notifier_block reserve_mem_nb = {
+	.notifier_call = reserve_mem_notifier,
+};
+
+int __meminit init_reserve_notifier(void)
+{
+	if (register_memory_notifier(&reserve_mem_nb))
+		printk("Failed registering memory add/remove notifier for admin reserve");
+
+	return 0;
+}
+module_init(init_reserve_notifier)
-- 
1.8.0.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-04-10 16:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-08 19:07 [PATCH v8 3/3] mm: reinititalise user and admin reserves if memory is added or removed Andrew Shewmaker
2013-04-08 20:37 ` Andrew Morton
2013-04-08 21:00   ` Andrew Shewmaker
2013-04-09 22:19     ` Andrew Morton
2013-04-09 23:56       ` Andrew Shewmaker
2013-04-10  0:05         ` Simon Jeons
2013-04-10  0:11           ` Andrew Shewmaker
2013-04-10  0:14             ` Simon Jeons
2013-04-10 15:56       ` Andrew Shewmaker
2013-04-09  0:42   ` Andrew Shewmaker
2013-04-08 20:57 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).