[RFC PATCH v3 18/31] drivers/base/node: add unregister_mem_block_under_nodes()
From: Cody P Schafer
Date: Thu May 02 2013 - 20:02:20 EST
Provides similar functionality to
unregister_mem_block_section_under_nodes() (which was previously named
identically to the newly added funtion), but operates on all memory
sections included in the memory block, not just the specified one.
---
drivers/base/node.c | 53 +++++++++++++++++++++++++++++++++++++++-------------
include/linux/node.h | 6 ++++++
2 files changed, 46 insertions(+), 13 deletions(-)
diff --git a/drivers/base/node.c b/drivers/base/node.c
index d3f981e..2861ef6 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -424,6 +424,24 @@ int register_mem_block_under_node(struct memory_block *mem_blk, int nid)
return 0;
}
+static void unregister_mem_block_pfn_under_nodes(struct memory_block *mem_blk,
+ unsigned long pfn, nodemask_t *unlinked_nodes)
+{
+ int nid;
+
+ nid = get_nid_for_pfn(pfn);
+ if (nid < 0)
+ return;
+ if (!node_online(nid))
+ return;
+ if (node_test_and_set(nid, *unlinked_nodes))
+ return;
+ sysfs_remove_link(&node_devices[nid]->dev.kobj,
+ kobject_name(&mem_blk->dev.kobj));
+ sysfs_remove_link(&mem_blk->dev.kobj,
+ kobject_name(&node_devices[nid]->dev.kobj));
+}
+
/*
* unregister memory block under all nodes that a particular section it
* contains spans spans
@@ -444,20 +462,29 @@ int unregister_mem_block_section_under_nodes(struct memory_block *mem_blk,
sect_start_pfn = section_nr_to_pfn(sec_num);
sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
- for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
- int nid;
+ for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++)
+ unregister_mem_block_pfn_under_nodes(mem_blk, pfn,
+ unlinked_nodes);
+ NODEMASK_FREE(unlinked_nodes);
+ return 0;
+}
- nid = get_nid_for_pfn(pfn);
- if (nid < 0)
- continue;
- if (!node_online(nid))
- continue;
- if (node_test_and_set(nid, *unlinked_nodes))
- continue;
- sysfs_remove_link(&node_devices[nid]->dev.kobj,
- kobject_name(&mem_blk->dev.kobj));
- sysfs_remove_link(&mem_blk->dev.kobj,
- kobject_name(&node_devices[nid]->dev.kobj));
+int unregister_mem_block_under_nodes(struct memory_block *mem_blk)
+{
+ NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
+ unsigned long pfn, sect_start_pfn, sect_end_pfn, sec_num;
+
+ if (!unlinked_nodes)
+ return -ENOMEM;
+ nodes_clear(*unlinked_nodes);
+
+ for (sec_num = mem_blk->start_section_nr;
+ sec_num < mem_blk->end_section_nr; sec_num++) {
+ sect_start_pfn = section_nr_to_pfn(sec_num);
+ sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
+ for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++)
+ unregister_mem_block_pfn_under_nodes(mem_blk, pfn,
+ unlinked_nodes);
}
NODEMASK_FREE(unlinked_nodes);
return 0;
diff --git a/include/linux/node.h b/include/linux/node.h
index f438c45..04b464e 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -41,6 +41,7 @@ extern int register_mem_block_under_node(struct memory_block *mem_blk,
extern int unregister_mem_block_section_under_nodes(
struct memory_block *mem_blk,
unsigned long sec_nr);
+extern int unregister_mem_block_under_nodes(struct memory_block *mem_blk);
#ifdef CONFIG_HUGETLBFS
extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
@@ -75,6 +76,11 @@ static inline int unregister_mem_block_section_under_nodes(
return 0;
}
+static inline int unregister_mem_block_under_nodes(struct memory_block *mem_blk)
+{
+ return 0;
+}
+
static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
node_registration_func_t unreg)
{
--
1.8.2.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/