Skip to content

Commit e1c158e

Browse files
davidhildenbrandtorvalds
authored andcommitted
mm/memory_hotplug: remove nid parameter from remove_memory() and friends
There is only a single user remaining. We can simply lookup the nid only used for node offlining purposes when walking our memory blocks. We don't expect to remove multi-nid ranges; and if we'd ever do, we most probably don't care about removing multi-nid ranges that actually result in empty nodes. If ever required, we can detect the "multi-nid" scenario and simply try offlining all online nodes. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: David Hildenbrand <[email protected]> Acked-by: Michael Ellerman <[email protected]> (powerpc) Cc: Michael Ellerman <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Len Brown <[email protected]> Cc: Dan Williams <[email protected]> Cc: Vishal Verma <[email protected]> Cc: Dave Jiang <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Jason Wang <[email protected]> Cc: Nathan Lynch <[email protected]> Cc: Laurent Dufour <[email protected]> Cc: "Aneesh Kumar K.V" <[email protected]> Cc: Scott Cheloha <[email protected]> Cc: Anton Blanchard <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Anshuman Khandual <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Baoquan He <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jia He <[email protected]> Cc: Joe Perches <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Michel Lespinasse <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Pankaj Gupta <[email protected]> Cc: Pankaj Gupta <[email protected]> Cc: Pavel Tatashin <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Pierre Morel <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Rich Felker <[email protected]> Cc: Sergei Trofimovich <[email protected]> Cc: Thiago Jung Bauermann <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Vitaly Kuznetsov <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Wei Yang <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yoshinori Sato <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 65a2aa5 commit e1c158e

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

arch/powerpc/platforms/pseries/hotplug-memory.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static int pseries_remove_memblock(unsigned long base, unsigned long memblock_si
286286
{
287287
unsigned long block_sz, start_pfn;
288288
int sections_per_block;
289-
int i, nid;
289+
int i;
290290

291291
start_pfn = base >> PAGE_SHIFT;
292292

@@ -297,10 +297,9 @@ static int pseries_remove_memblock(unsigned long base, unsigned long memblock_si
297297

298298
block_sz = pseries_memory_block_size();
299299
sections_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE;
300-
nid = memory_add_physaddr_to_nid(base);
301300

302301
for (i = 0; i < sections_per_block; i++) {
303-
__remove_memory(nid, base, MIN_MEMORY_BLOCK_SIZE);
302+
__remove_memory(base, MIN_MEMORY_BLOCK_SIZE);
304303
base += MIN_MEMORY_BLOCK_SIZE;
305304
}
306305

@@ -387,7 +386,7 @@ static int dlpar_remove_lmb(struct drmem_lmb *lmb)
387386

388387
block_sz = pseries_memory_block_size();
389388

390-
__remove_memory(mem_block->nid, lmb->base_addr, block_sz);
389+
__remove_memory(lmb->base_addr, block_sz);
391390
put_device(&mem_block->dev);
392391

393392
/* Update memory regions for memory remove */
@@ -660,7 +659,7 @@ static int dlpar_add_lmb(struct drmem_lmb *lmb)
660659

661660
rc = dlpar_online_lmb(lmb);
662661
if (rc) {
663-
__remove_memory(nid, lmb->base_addr, block_sz);
662+
__remove_memory(lmb->base_addr, block_sz);
664663
invalidate_lmb_associativity_index(lmb);
665664
} else {
666665
lmb->flags |= DRCONF_MEM_ASSIGNED;

drivers/acpi/acpi_memhotplug.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,14 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
239239

240240
static void acpi_memory_remove_memory(struct acpi_memory_device *mem_device)
241241
{
242-
acpi_handle handle = mem_device->device->handle;
243242
struct acpi_memory_info *info, *n;
244-
int nid = acpi_get_node(handle);
245243

246244
list_for_each_entry_safe(info, n, &mem_device->res_list, list) {
247245
if (!info->enabled)
248246
continue;
249247

250-
if (nid == NUMA_NO_NODE)
251-
nid = memory_add_physaddr_to_nid(info->start_addr);
252-
253248
acpi_unbind_memory_blocks(info);
254-
__remove_memory(nid, info->start_addr, info->length);
249+
__remove_memory(info->start_addr, info->length);
255250
list_del(&info->list);
256251
kfree(info);
257252
}

drivers/dax/kmem.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax)
156156
if (rc)
157157
continue;
158158

159-
rc = remove_memory(dev_dax->target_node, range.start,
160-
range_len(&range));
159+
rc = remove_memory(range.start, range_len(&range));
161160
if (rc == 0) {
162161
release_resource(data->res[i]);
163162
kfree(data->res[i]);

drivers/virtio/virtio_mem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ static int virtio_mem_remove_memory(struct virtio_mem *vm, uint64_t addr,
677677

678678
dev_dbg(&vm->vdev->dev, "removing memory: 0x%llx - 0x%llx\n", addr,
679679
addr + size - 1);
680-
rc = remove_memory(vm->nid, addr, size);
680+
rc = remove_memory(addr, size);
681681
if (!rc) {
682682
atomic64_sub(size, &vm->offline_size);
683683
/*
@@ -720,7 +720,7 @@ static int virtio_mem_offline_and_remove_memory(struct virtio_mem *vm,
720720
"offlining and removing memory: 0x%llx - 0x%llx\n", addr,
721721
addr + size - 1);
722722

723-
rc = offline_and_remove_memory(vm->nid, addr, size);
723+
rc = offline_and_remove_memory(addr, size);
724724
if (!rc) {
725725
atomic64_sub(size, &vm->offline_size);
726726
/*

include/linux/memory_hotplug.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ static inline void pgdat_resize_init(struct pglist_data *pgdat) {}
292292

293293
extern void try_offline_node(int nid);
294294
extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
295-
extern int remove_memory(int nid, u64 start, u64 size);
296-
extern void __remove_memory(int nid, u64 start, u64 size);
297-
extern int offline_and_remove_memory(int nid, u64 start, u64 size);
295+
extern int remove_memory(u64 start, u64 size);
296+
extern void __remove_memory(u64 start, u64 size);
297+
extern int offline_and_remove_memory(u64 start, u64 size);
298298

299299
#else
300300
static inline void try_offline_node(int nid) {}
@@ -304,12 +304,12 @@ static inline int offline_pages(unsigned long start_pfn, unsigned long nr_pages)
304304
return -EINVAL;
305305
}
306306

307-
static inline int remove_memory(int nid, u64 start, u64 size)
307+
static inline int remove_memory(u64 start, u64 size)
308308
{
309309
return -EBUSY;
310310
}
311311

312-
static inline void __remove_memory(int nid, u64 start, u64 size) {}
312+
static inline void __remove_memory(u64 start, u64 size) {}
313313
#endif /* CONFIG_MEMORY_HOTREMOVE */
314314

315315
extern void set_zone_contiguous(struct zone *zone);

mm/memory_hotplug.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,9 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages)
17391739
static int check_memblock_offlined_cb(struct memory_block *mem, void *arg)
17401740
{
17411741
int ret = !is_memblock_offlined(mem);
1742+
int *nid = arg;
17421743

1744+
*nid = mem->nid;
17431745
if (unlikely(ret)) {
17441746
phys_addr_t beginpa, endpa;
17451747

@@ -1832,21 +1834,25 @@ void try_offline_node(int nid)
18321834
}
18331835
EXPORT_SYMBOL(try_offline_node);
18341836

1835-
static int __ref try_remove_memory(int nid, u64 start, u64 size)
1837+
static int __ref try_remove_memory(u64 start, u64 size)
18361838
{
1837-
int rc = 0;
18381839
struct vmem_altmap mhp_altmap = {};
18391840
struct vmem_altmap *altmap = NULL;
18401841
unsigned long nr_vmemmap_pages;
1842+
int rc = 0, nid = NUMA_NO_NODE;
18411843

18421844
BUG_ON(check_hotplug_memory_range(start, size));
18431845

18441846
/*
18451847
* All memory blocks must be offlined before removing memory. Check
18461848
* whether all memory blocks in question are offline and return error
18471849
* if this is not the case.
1850+
*
1851+
* While at it, determine the nid. Note that if we'd have mixed nodes,
1852+
* we'd only try to offline the last determined one -- which is good
1853+
* enough for the cases we care about.
18481854
*/
1849-
rc = walk_memory_blocks(start, size, NULL, check_memblock_offlined_cb);
1855+
rc = walk_memory_blocks(start, size, &nid, check_memblock_offlined_cb);
18501856
if (rc)
18511857
return rc;
18521858

@@ -1895,43 +1901,43 @@ static int __ref try_remove_memory(int nid, u64 start, u64 size)
18951901

18961902
release_mem_region_adjustable(start, size);
18971903

1898-
try_offline_node(nid);
1904+
if (nid != NUMA_NO_NODE)
1905+
try_offline_node(nid);
18991906

19001907
mem_hotplug_done();
19011908
return 0;
19021909
}
19031910

19041911
/**
19051912
* __remove_memory - Remove memory if every memory block is offline
1906-
* @nid: the node ID
19071913
* @start: physical address of the region to remove
19081914
* @size: size of the region to remove
19091915
*
19101916
* NOTE: The caller must call lock_device_hotplug() to serialize hotplug
19111917
* and online/offline operations before this call, as required by
19121918
* try_offline_node().
19131919
*/
1914-
void __remove_memory(int nid, u64 start, u64 size)
1920+
void __remove_memory(u64 start, u64 size)
19151921
{
19161922

19171923
/*
19181924
* trigger BUG() if some memory is not offlined prior to calling this
19191925
* function
19201926
*/
1921-
if (try_remove_memory(nid, start, size))
1927+
if (try_remove_memory(start, size))
19221928
BUG();
19231929
}
19241930

19251931
/*
19261932
* Remove memory if every memory block is offline, otherwise return -EBUSY is
19271933
* some memory is not offline
19281934
*/
1929-
int remove_memory(int nid, u64 start, u64 size)
1935+
int remove_memory(u64 start, u64 size)
19301936
{
19311937
int rc;
19321938

19331939
lock_device_hotplug();
1934-
rc = try_remove_memory(nid, start, size);
1940+
rc = try_remove_memory(start, size);
19351941
unlock_device_hotplug();
19361942

19371943
return rc;
@@ -1991,7 +1997,7 @@ static int try_reonline_memory_block(struct memory_block *mem, void *arg)
19911997
* unplugged all memory (so it's no longer in use) and want to offline + remove
19921998
* that memory.
19931999
*/
1994-
int offline_and_remove_memory(int nid, u64 start, u64 size)
2000+
int offline_and_remove_memory(u64 start, u64 size)
19952001
{
19962002
const unsigned long mb_count = size / memory_block_size_bytes();
19972003
uint8_t *online_types, *tmp;
@@ -2027,7 +2033,7 @@ int offline_and_remove_memory(int nid, u64 start, u64 size)
20272033
* This cannot fail as it cannot get onlined in the meantime.
20282034
*/
20292035
if (!rc) {
2030-
rc = try_remove_memory(nid, start, size);
2036+
rc = try_remove_memory(start, size);
20312037
if (rc)
20322038
pr_err("%s: Failed to remove memory: %d", __func__, rc);
20332039
}

0 commit comments

Comments
 (0)