Skip to content

Commit d336016

Browse files
Nathan Fontenotgregkh
authored andcommitted
memory hotplug: Update phys_index to [start|end]_section_nr
Update the 'phys_index' property of a the memory_block struct to be called start_section_nr, and add a end_section_nr property. The data tracked here is the same but the updated naming is more in line with what is stored here, namely the first and last section number that the memory block spans. The names presented to userspace remain the same, phys_index for start_section_nr and end_phys_index for end_section_nr, to avoid breaking anything in userspace. This also updates the node sysfs code to be aware of the new capability for a memory block to contain multiple memory sections and be aware of the memory block structure name changes (start_section_nr). This requires an additional parameter to unregister_mem_sect_under_nodes so that we know which memory section of the memory block to unregister. Signed-off-by: Nathan Fontenot <nfont@austin.ibm.com> Reviewed-by: Robin Holt <holt@sgi.com> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 0c2c99b commit d336016

4 files changed

Lines changed: 45 additions & 17 deletions

File tree

‎drivers/base/memory.c‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int register_memory(struct memory_block *memory)
9797
int error;
9898

9999
memory->sysdev.cls = &memory_sysdev_class;
100-
memory->sysdev.id = memory->phys_index / sections_per_block;
100+
memory->sysdev.id = memory->start_section_nr / sections_per_block;
101101

102102
error = sysdev_register(&memory->sysdev);
103103
return error;
@@ -138,12 +138,26 @@ static unsigned long get_memory_block_size(void)
138138
* uses.
139139
*/
140140

141-
static ssize_t show_mem_phys_index(struct sys_device *dev,
141+
static ssize_t show_mem_start_phys_index(struct sys_device *dev,
142142
struct sysdev_attribute *attr, char *buf)
143143
{
144144
struct memory_block *mem =
145145
container_of(dev, struct memory_block, sysdev);
146-
return sprintf(buf, "%08lx\n", mem->phys_index / sections_per_block);
146+
unsigned long phys_index;
147+
148+
phys_index = mem->start_section_nr / sections_per_block;
149+
return sprintf(buf, "%08lx\n", phys_index);
150+
}
151+
152+
static ssize_t show_mem_end_phys_index(struct sys_device *dev,
153+
struct sysdev_attribute *attr, char *buf)
154+
{
155+
struct memory_block *mem =
156+
container_of(dev, struct memory_block, sysdev);
157+
unsigned long phys_index;
158+
159+
phys_index = mem->end_section_nr / sections_per_block;
160+
return sprintf(buf, "%08lx\n", phys_index);
147161
}
148162

149163
/*
@@ -158,7 +172,7 @@ static ssize_t show_mem_removable(struct sys_device *dev,
158172
container_of(dev, struct memory_block, sysdev);
159173

160174
for (i = 0; i < sections_per_block; i++) {
161-
pfn = section_nr_to_pfn(mem->phys_index + i);
175+
pfn = section_nr_to_pfn(mem->start_section_nr + i);
162176
ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
163177
}
164178

@@ -275,14 +289,15 @@ static int memory_block_change_state(struct memory_block *mem,
275289
mem->state = MEM_GOING_OFFLINE;
276290

277291
for (i = 0; i < sections_per_block; i++) {
278-
ret = memory_section_action(mem->phys_index + i, to_state);
292+
ret = memory_section_action(mem->start_section_nr + i,
293+
to_state);
279294
if (ret)
280295
break;
281296
}
282297

283298
if (ret) {
284299
for (i = 0; i < sections_per_block; i++)
285-
memory_section_action(mem->phys_index + i,
300+
memory_section_action(mem->start_section_nr + i,
286301
from_state_req);
287302

288303
mem->state = from_state_req;
@@ -330,7 +345,8 @@ static ssize_t show_phys_device(struct sys_device *dev,
330345
return sprintf(buf, "%d\n", mem->phys_device);
331346
}
332347

333-
static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL);
348+
static SYSDEV_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
349+
static SYSDEV_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
334350
static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
335351
static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
336352
static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL);
@@ -522,16 +538,20 @@ static int init_memory_block(struct memory_block **memory,
522538
return -ENOMEM;
523539

524540
scn_nr = __section_nr(section);
525-
mem->phys_index = base_memory_block_id(scn_nr) * sections_per_block;
541+
mem->start_section_nr =
542+
base_memory_block_id(scn_nr) * sections_per_block;
543+
mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
526544
mem->state = state;
527545
mem->section_count++;
528546
mutex_init(&mem->state_mutex);
529-
start_pfn = section_nr_to_pfn(mem->phys_index);
547+
start_pfn = section_nr_to_pfn(mem->start_section_nr);
530548
mem->phys_device = arch_get_memory_phys_device(start_pfn);
531549

532550
ret = register_memory(mem);
533551
if (!ret)
534552
ret = mem_create_simple_file(mem, phys_index);
553+
if (!ret)
554+
ret = mem_create_simple_file(mem, end_phys_index);
535555
if (!ret)
536556
ret = mem_create_simple_file(mem, state);
537557
if (!ret)
@@ -575,11 +595,12 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
575595

576596
mutex_lock(&mem_sysfs_mutex);
577597
mem = find_memory_block(section);
598+
unregister_mem_sect_under_nodes(mem, __section_nr(section));
578599

579600
mem->section_count--;
580601
if (mem->section_count == 0) {
581-
unregister_mem_sect_under_nodes(mem);
582602
mem_remove_simple_file(mem, phys_index);
603+
mem_remove_simple_file(mem, end_phys_index);
583604
mem_remove_simple_file(mem, state);
584605
mem_remove_simple_file(mem, phys_device);
585606
mem_remove_simple_file(mem, removable);

‎drivers/base/node.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,10 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
375375
return -EFAULT;
376376
if (!node_online(nid))
377377
return 0;
378-
sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index);
379-
sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
378+
379+
sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
380+
sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
381+
sect_end_pfn += PAGES_PER_SECTION - 1;
380382
for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
381383
int page_nid;
382384

@@ -400,7 +402,8 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
400402
}
401403

402404
/* unregister memory section under all nodes that it spans */
403-
int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
405+
int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
406+
unsigned long phys_index)
404407
{
405408
NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
406409
unsigned long pfn, sect_start_pfn, sect_end_pfn;
@@ -412,7 +415,8 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
412415
if (!unlinked_nodes)
413416
return -ENOMEM;
414417
nodes_clear(*unlinked_nodes);
415-
sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index);
418+
419+
sect_start_pfn = section_nr_to_pfn(phys_index);
416420
sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
417421
for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
418422
int nid;

‎include/linux/memory.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
#include <linux/mutex.h>
2222

2323
struct memory_block {
24-
unsigned long phys_index;
24+
unsigned long start_section_nr;
25+
unsigned long end_section_nr;
2526
unsigned long state;
2627
int section_count;
2728

‎include/linux/node.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
3939
extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
4040
extern int register_mem_sect_under_node(struct memory_block *mem_blk,
4141
int nid);
42-
extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk);
42+
extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
43+
unsigned long phys_index);
4344

4445
#ifdef CONFIG_HUGETLBFS
4546
extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
@@ -67,7 +68,8 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
6768
{
6869
return 0;
6970
}
70-
static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
71+
static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
72+
unsigned long phys_index)
7173
{
7274
return 0;
7375
}

0 commit comments

Comments
 (0)