Skip to content

Commit bc32df0

Browse files
heicarsttorvalds
authored andcommitted
memory hotplug: allow setting of phys_device
/sys/devices/system/memory/memoryX/phys_device is supposed to contain the number of the physical device that the corresponding piece of memory belongs to. In case a physical device should be replaced or taken offline for whatever reason it is necessary to set all corresponding memory pieces offline. The current implementation always sets phys_device to '0' and there is no way or hook to change that. Seems like there was a plan to implement that but it wasn't finished for whatever reason. So add a weak function which architectures can override to actually set the phys_device from within add_memory_block(). Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Dave Hansen <haveblue@us.ibm.com> Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e5d6151 commit bc32df0

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎drivers/base/memory.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,16 @@ static inline int memory_fail_init(void)
429429
* differentiation between which *physical* devices each
430430
* section belongs to...
431431
*/
432+
int __weak arch_get_memory_phys_device(unsigned long start_pfn)
433+
{
434+
return 0;
435+
}
432436

433437
static int add_memory_block(int nid, struct mem_section *section,
434-
unsigned long state, int phys_device,
435-
enum mem_add_context context)
438+
unsigned long state, enum mem_add_context context)
436439
{
437440
struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL);
441+
unsigned long start_pfn;
438442
int ret = 0;
439443

440444
if (!mem)
@@ -443,7 +447,8 @@ static int add_memory_block(int nid, struct mem_section *section,
443447
mem->phys_index = __section_nr(section);
444448
mem->state = state;
445449
mutex_init(&mem->state_mutex);
446-
mem->phys_device = phys_device;
450+
start_pfn = section_nr_to_pfn(mem->phys_index);
451+
mem->phys_device = arch_get_memory_phys_device(start_pfn);
447452

448453
ret = register_memory(mem, section);
449454
if (!ret)
@@ -515,7 +520,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
515520
*/
516521
int register_new_memory(int nid, struct mem_section *section)
517522
{
518-
return add_memory_block(nid, section, MEM_OFFLINE, 0, HOTPLUG);
523+
return add_memory_block(nid, section, MEM_OFFLINE, HOTPLUG);
519524
}
520525

521526
int unregister_memory_section(struct mem_section *section)
@@ -548,7 +553,7 @@ int __init memory_dev_init(void)
548553
if (!present_section_nr(i))
549554
continue;
550555
err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE,
551-
0, BOOT);
556+
BOOT);
552557
if (!ret)
553558
ret = err;
554559
}

‎include/linux/memory.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ struct memory_block {
3636
struct sys_device sysdev;
3737
};
3838

39+
int arch_get_memory_phys_device(unsigned long start_pfn);
40+
3941
/* These states are exposed to userspace as text strings in sysfs */
4042
#define MEM_ONLINE (1<<0) /* exposed to userspace */
4143
#define MEM_GOING_OFFLINE (1<<1) /* exposed to userspace */

0 commit comments

Comments
 (0)