Skip to contentSkip to conversation

+ mem-hotplug-implement-get-put_online_mems.patch added to -mm tree

PATCH [email protected] 1 participant 1 message Apr 18, 2014

Subsystems (8)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

Subject: + mem-hotplug-implement-get-put_online_mems.patch added to -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Fri, 18 Apr 2014 13:18:46 -0700

The patch titled
Subject: mem-hotplug: implement get/put_online_mems
has been added to the -mm tree. Its filename is
mem-hotplug-implement-get-put_online_mems.patch

This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/mem-hotplug-implement-get-put_online_mems.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/mem-hotplug-implement-get-put_online_mems.patch

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated there every 3-4 working days

------------------------------------------------------
From: Vladimir Davydov <[email protected]>
Subject: mem-hotplug: implement get/put_online_mems

kmem_cache_{create,destroy,shrink} need to get a stable value of cpu/node online mask, because they init/destroy/access per-cpu/node kmem_cache parts, which can be allocated or destroyed on cpu/mem hotplug. To protect against cpu hotplug, these functions use {get,put}_online_cpus. However, they do nothing to synchronize with memory hotplug - taking the slab_mutex does not eliminate the possibility of race as described in patch 2.

What we need there is something like get_online_cpus, but for memory. We already have lock_memory_hotplug, which serves for the purpose, but it's a bit of a hammer right now, because it's backed by a mutex. As a result, it imposes some limitations to locking order, which are not desirable, and can't be used just like get_online_cpus. That's why in patch 1 I substitute it with get/put_online_mems, which work exactly like get/put_online_cpus except they block not cpu, but memory hotplug.

[ v1 can be found at https://lkml.org/lkml/2014/4/6/68. I NAK'ed it by myself, because it used an rw semaphore for get/put_online_mems, making them dead lock prune. ]

This patch (of 2):

{un}lock_memory_hotplug, which is used to synchronize against memory hotplug, is currently backed by a mutex, which makes it a bit of a hammer
- threads that only want to get a stable value of online nodes mask won't be able to proceed concurrently. Also, it imposes some strong locking ordering rules on it, which narrows down the set of its usage scenarios.

This patch introduces get/put_online_mems, which are the same as get/put_online_cpus, but for memory hotplug, i.e. executing a code inside a get/put_online_mems section will guarantee a stable value of online nodes, present pages, etc.

lock_memory_hotplug()/unlock_memory_hotplug() are removed altogether.

Cc Christoph Lameter <[email protected]>
Cc Pekka Enberg <[email protected]>
Cc Tang Chen <[email protected]>
Cc Zhang Yanfei <[email protected]>
Cc Toshi Kani <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Jiang Liu <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc David Rientjes <[email protected]>
Cc Wen Congyang <[email protected]>
Cc Yasuaki Ishimatsu <[email protected]>
Cc Lai Jiangshan <[email protected]>

---

 include/linux/memory_hotplug.h |   14 ---
 include/linux/mmzone.h         |    8 -
 mm/kmemleak.c                  |    4 
 mm/memory-failure.c            |    8 -
 mm/memory_hotplug.c            |  142 ++++++++++++++++++++++---------
 mm/slub.c                      |    4 
 mm/vmscan.c                    |    2 
 7 files changed, 116 insertions(+), 66 deletions(-)
include/linux/memory_hotplug.h renamed from include/linux/memory_hotplug.h~mem-hotplug-implement-get-put_online_mems +4 -10
diff -puN include/linux/memory_hotplug.h~mem-hotplug-implement-get-put_online_mems include/linux/memory_hotplug.h
@@ -187,14 +187,8 @@ extern void put_page_bootmem(struct page
 extern void get_page_bootmem(unsigned long ingo, struct page *page,
 			     unsigned long type);
 
-/*
- * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug
- * notifier will be called under this. 2) offline/online/add/remove memory
- * will not run simultaneously.
- */
-
-void lock_memory_hotplug(void);
-void unlock_memory_hotplug(void);
+void get_online_mems(void);
+void put_online_mems(void);
 
 #else /* ! CONFIG_MEMORY_HOTPLUG */
 /*
@@ -232,8 +226,8 @@ static inline int try_online_node(int ni
 	return 0;
 }
 
-static inline void lock_memory_hotplug(void) {}
-static inline void unlock_memory_hotplug(void) {}
+static inline void get_online_mems(void) {}
+static inline void put_online_mems(void) {}
 
 #endif /* ! CONFIG_MEMORY_HOTPLUG */
 
include/linux/mmzone.h renamed from include/linux/mmzone.h~mem-hotplug-implement-get-put_online_mems +4 -4
diff -puN include/linux/mmzone.h~mem-hotplug-implement-get-put_online_mems include/linux/mmzone.h
@@ -481,9 +481,8 @@ struct zone {
 	 * give them a chance of being in the same cacheline.
 	 *
 	 * Write access to present_pages at runtime should be protected by
-	 * lock_memory_hotplug()/unlock_memory_hotplug().  Any reader who can't
-	 * tolerant drift of present_pages should hold memory hotplug lock to
-	 * get a stable value.
+	 * mem_hotplug_begin/end(). Any reader who can't tolerant drift of
+	 * present_pages should get_online_mems() to get a stable value.
 	 *
 	 * Read access to managed_pages should be safe because it's unsigned
 	 * long. Write access to zone->managed_pages and totalram_pages are
@@ -765,7 +764,8 @@ typedef struct pglist_data {
 	int node_id;
 	wait_queue_head_t kswapd_wait;
 	wait_queue_head_t pfmemalloc_wait;
-	struct task_struct *kswapd;	/* Protected by lock_memory_hotplug() */
+	struct task_struct *kswapd;	/* Protected by
+					   mem_hotplug_begin/end() */
 	int kswapd_max_order;
 	enum zone_type classzone_idx;
 #ifdef CONFIG_NUMA_BALANCING
mm/kmemleak.c renamed from mm/kmemleak.c~mem-hotplug-implement-get-put_online_mems +2 -2
diff -puN mm/kmemleak.c~mem-hotplug-implement-get-put_online_mems mm/kmemleak.c
@@ -1300,7 +1300,7 @@ static void kmemleak_scan(void)
 	/*
 	 * Struct page scanning for each node.
 	 */
-	lock_memory_hotplug();
+	get_online_mems();
 	for_each_online_node(i) {
 		unsigned long start_pfn = node_start_pfn(i);
 		unsigned long end_pfn = node_end_pfn(i);
@@ -1318,7 +1318,7 @@ static void kmemleak_scan(void)
 			scan_block(page, page + 1, NULL, 1);
 		}
 	}
-	unlock_memory_hotplug();
+	put_online_mems();
 
 	/*
 	 * Scanning the task stacks (may introduce false negatives).
mm/memory-failure.c renamed from mm/memory-failure.c~mem-hotplug-implement-get-put_online_mems +2 -6
diff -puN mm/memory-failure.c~mem-hotplug-implement-get-put_online_mems mm/memory-failure.c
@@ -1661,11 +1661,7 @@ int soft_offline_page(struct page *page,
 		}
 	}
 
-	/*
-	 * The lock_memory_hotplug prevents a race with memory hotplug.
-	 * This is a big hammer, a better would be nicer.
-	 */
-	lock_memory_hotplug();
+	get_online_mems();
 
 	/*
 	 * Isolate the page, so that it doesn't get reallocated if it
@@ -1676,7 +1672,7 @@ int soft_offline_page(struct page *page,
 		set_migratetype_isolate(page, true);
 
 	ret = get_any_page(page, pfn, flags);
-	unlock_memory_hotplug();
+	put_online_mems();
 	if (ret > 0) { /* for in-use pages */
 		if (PageHuge(page))
 			ret = soft_offline_huge_page(page, flags);
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mem-hotplug-implement-get-put_online_mems +101 -41

276 lines not on this page · raw message

mm/slub.c renamed from mm/slub.c~mem-hotplug-implement-get-put_online_mems +2 -2
diff -puN mm/slub.c~mem-hotplug-implement-get-put_online_mems mm/slub.c
@@ -4362,7 +4362,7 @@ static ssize_t show_slab_objects(struct
 		}
 	}
 
-	lock_memory_hotplug();
+	get_online_mems();
 #ifdef CONFIG_SLUB_DEBUG
 	if (flags & SO_ALL) {
 		for_each_node_state(node, N_NORMAL_MEMORY) {
@@ -4402,7 +4402,7 @@ static ssize_t show_slab_objects(struct
 			x += sprintf(buf + x, " N%d=%lu",
 					node, nodes[node]);
 #endif
-	unlock_memory_hotplug();
+	put_online_mems();
 	kfree(nodes);
 	return x + sprintf(buf + x, "\n");
 }
mm/vmscan.c renamed from mm/vmscan.c~mem-hotplug-implement-get-put_online_mems +1 -1
diff -puN mm/vmscan.c~mem-hotplug-implement-get-put_online_mems mm/vmscan.c
@@ -3419,7 +3419,7 @@ int kswapd_run(int nid)
 
 /*
  * Called by memory hotplug when all memory in a node is offlined.  Caller must
- * hold lock_memory_hotplug().
+ * hold mem_hotplug_begin/end().
  */
 void kswapd_stop(int nid)
 {

_

Patches currently in -mm which might be from [email protected] are

slub-fix-memcg_propagate_slab_attrs.patch slb-charge-slabs-to-kmemcg-explicitly.patch mm-get-rid-of-__gfp_kmemcg.patch mm-get-rid-of-__gfp_kmemcg-fix.patch slab-document-kmalloc_order.patch memcg-un-export-__memcg_kmem_get_cache.patch mem-hotplug-implement-get-put_online_mems.patch slab-get_online_mems-for-kmem_cache_createdestroyshrink.patch