Commit b1154233 authored by Grygorii Strashko's avatar Grygorii Strashko Committed by Linus Torvalds

mm/memblock: switch to use NUMA_NO_NODE instead of MAX_NUMNODES

It's recommended to use NUMA_NO_NODE everywhere to select "process any
node" behavior or to indicate that "no node id specified".

Hence, update __next_free_mem_range*() API's to accept both NUMA_NO_NODE
and MAX_NUMNODES, but emit warning once on MAX_NUMNODES, and correct
corresponding API's documentation to describe new behavior.  Also,
update other memblock/nobootmem APIs where MAX_NUMNODES is used
dirrectly.

The change was suggested by Tejun Heo.
Signed-off-by: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: default avatarSantosh Shilimkar <santosh.shilimkar@ti.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Paul Walmsley <paul@pwsan.com>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Tony Lindgren <tony@atomide.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 87029ee9
...@@ -118,7 +118,7 @@ void __next_free_mem_range(u64 *idx, int nid, phys_addr_t *out_start, ...@@ -118,7 +118,7 @@ void __next_free_mem_range(u64 *idx, int nid, phys_addr_t *out_start,
/** /**
* for_each_free_mem_range - iterate through free memblock areas * for_each_free_mem_range - iterate through free memblock areas
* @i: u64 used as loop variable * @i: u64 used as loop variable
* @nid: node selector, %MAX_NUMNODES for all nodes * @nid: node selector, %NUMA_NO_NODE for all nodes
* @p_start: ptr to phys_addr_t for start address of the range, can be %NULL * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
* @p_end: ptr to phys_addr_t for end address of the range, can be %NULL * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
* @p_nid: ptr to int for nid of the range, can be %NULL * @p_nid: ptr to int for nid of the range, can be %NULL
...@@ -138,7 +138,7 @@ void __next_free_mem_range_rev(u64 *idx, int nid, phys_addr_t *out_start, ...@@ -138,7 +138,7 @@ void __next_free_mem_range_rev(u64 *idx, int nid, phys_addr_t *out_start,
/** /**
* for_each_free_mem_range_reverse - rev-iterate through free memblock areas * for_each_free_mem_range_reverse - rev-iterate through free memblock areas
* @i: u64 used as loop variable * @i: u64 used as loop variable
* @nid: node selector, %MAX_NUMNODES for all nodes * @nid: node selector, %NUMA_NO_NODE for all nodes
* @p_start: ptr to phys_addr_t for start address of the range, can be %NULL * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
* @p_end: ptr to phys_addr_t for end address of the range, can be %NULL * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
* @p_nid: ptr to int for nid of the range, can be %NULL * @p_nid: ptr to int for nid of the range, can be %NULL
......
...@@ -94,7 +94,7 @@ static long __init_memblock memblock_overlaps_region(struct memblock_type *type, ...@@ -94,7 +94,7 @@ static long __init_memblock memblock_overlaps_region(struct memblock_type *type,
* @end: end of candidate range, can be %MEMBLOCK_ALLOC_{ANYWHERE|ACCESSIBLE} * @end: end of candidate range, can be %MEMBLOCK_ALLOC_{ANYWHERE|ACCESSIBLE}
* @size: size of free area to find * @size: size of free area to find
* @align: alignment of free area to find * @align: alignment of free area to find
* @nid: nid of the free area to find, %MAX_NUMNODES for any node * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
* *
* Utility called from memblock_find_in_range_node(), find free area bottom-up. * Utility called from memblock_find_in_range_node(), find free area bottom-up.
* *
...@@ -126,7 +126,7 @@ __memblock_find_range_bottom_up(phys_addr_t start, phys_addr_t end, ...@@ -126,7 +126,7 @@ __memblock_find_range_bottom_up(phys_addr_t start, phys_addr_t end,
* @end: end of candidate range, can be %MEMBLOCK_ALLOC_{ANYWHERE|ACCESSIBLE} * @end: end of candidate range, can be %MEMBLOCK_ALLOC_{ANYWHERE|ACCESSIBLE}
* @size: size of free area to find * @size: size of free area to find
* @align: alignment of free area to find * @align: alignment of free area to find
* @nid: nid of the free area to find, %MAX_NUMNODES for any node * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
* *
* Utility called from memblock_find_in_range_node(), find free area top-down. * Utility called from memblock_find_in_range_node(), find free area top-down.
* *
...@@ -161,7 +161,7 @@ __memblock_find_range_top_down(phys_addr_t start, phys_addr_t end, ...@@ -161,7 +161,7 @@ __memblock_find_range_top_down(phys_addr_t start, phys_addr_t end,
* @align: alignment of free area to find * @align: alignment of free area to find
* @start: start of candidate range * @start: start of candidate range
* @end: end of candidate range, can be %MEMBLOCK_ALLOC_{ANYWHERE|ACCESSIBLE} * @end: end of candidate range, can be %MEMBLOCK_ALLOC_{ANYWHERE|ACCESSIBLE}
* @nid: nid of the free area to find, %MAX_NUMNODES for any node * @nid: nid of the free area to find, %NUMA_NO_NODE for any node
* *
* Find @size free area aligned to @align in the specified range and node. * Find @size free area aligned to @align in the specified range and node.
* *
...@@ -242,7 +242,7 @@ phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start, ...@@ -242,7 +242,7 @@ phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start,
phys_addr_t align) phys_addr_t align)
{ {
return memblock_find_in_range_node(size, align, start, end, return memblock_find_in_range_node(size, align, start, end,
MAX_NUMNODES); NUMA_NO_NODE);
} }
static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r) static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r)
...@@ -754,7 +754,7 @@ int __init_memblock memblock_clear_hotplug(phys_addr_t base, phys_addr_t size) ...@@ -754,7 +754,7 @@ int __init_memblock memblock_clear_hotplug(phys_addr_t base, phys_addr_t size)
/** /**
* __next_free_mem_range - next function for for_each_free_mem_range() * __next_free_mem_range - next function for for_each_free_mem_range()
* @idx: pointer to u64 loop variable * @idx: pointer to u64 loop variable
* @nid: node selector, %MAX_NUMNODES for all nodes * @nid: node selector, %NUMA_NO_NODE for all nodes
* @out_start: ptr to phys_addr_t for start address of the range, can be %NULL * @out_start: ptr to phys_addr_t for start address of the range, can be %NULL
* @out_end: ptr to phys_addr_t for end address of the range, can be %NULL * @out_end: ptr to phys_addr_t for end address of the range, can be %NULL
* @out_nid: ptr to int for nid of the range, can be %NULL * @out_nid: ptr to int for nid of the range, can be %NULL
...@@ -782,6 +782,11 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid, ...@@ -782,6 +782,11 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
struct memblock_type *rsv = &memblock.reserved; struct memblock_type *rsv = &memblock.reserved;
int mi = *idx & 0xffffffff; int mi = *idx & 0xffffffff;
int ri = *idx >> 32; int ri = *idx >> 32;
bool check_node = (nid != NUMA_NO_NODE) && (nid != MAX_NUMNODES);
if (nid == MAX_NUMNODES)
pr_warn_once("%s: Usage of MAX_NUMNODES is depricated. Use NUMA_NO_NODE instead\n",
__func__);
for ( ; mi < mem->cnt; mi++) { for ( ; mi < mem->cnt; mi++) {
struct memblock_region *m = &mem->regions[mi]; struct memblock_region *m = &mem->regions[mi];
...@@ -789,7 +794,7 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid, ...@@ -789,7 +794,7 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
phys_addr_t m_end = m->base + m->size; phys_addr_t m_end = m->base + m->size;
/* only memory regions are associated with nodes, check it */ /* only memory regions are associated with nodes, check it */
if (nid != MAX_NUMNODES && nid != memblock_get_region_node(m)) if (check_node && nid != memblock_get_region_node(m))
continue; continue;
/* scan areas before each reservation for intersection */ /* scan areas before each reservation for intersection */
...@@ -830,7 +835,7 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid, ...@@ -830,7 +835,7 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
/** /**
* __next_free_mem_range_rev - next function for for_each_free_mem_range_reverse() * __next_free_mem_range_rev - next function for for_each_free_mem_range_reverse()
* @idx: pointer to u64 loop variable * @idx: pointer to u64 loop variable
* @nid: nid: node selector, %MAX_NUMNODES for all nodes * @nid: nid: node selector, %NUMA_NO_NODE for all nodes
* @out_start: ptr to phys_addr_t for start address of the range, can be %NULL * @out_start: ptr to phys_addr_t for start address of the range, can be %NULL
* @out_end: ptr to phys_addr_t for end address of the range, can be %NULL * @out_end: ptr to phys_addr_t for end address of the range, can be %NULL
* @out_nid: ptr to int for nid of the range, can be %NULL * @out_nid: ptr to int for nid of the range, can be %NULL
...@@ -850,6 +855,11 @@ void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid, ...@@ -850,6 +855,11 @@ void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid,
struct memblock_type *rsv = &memblock.reserved; struct memblock_type *rsv = &memblock.reserved;
int mi = *idx & 0xffffffff; int mi = *idx & 0xffffffff;
int ri = *idx >> 32; int ri = *idx >> 32;
bool check_node = (nid != NUMA_NO_NODE) && (nid != MAX_NUMNODES);
if (nid == MAX_NUMNODES)
pr_warn_once("%s: Usage of MAX_NUMNODES is depricated. Use NUMA_NO_NODE instead\n",
__func__);
if (*idx == (u64)ULLONG_MAX) { if (*idx == (u64)ULLONG_MAX) {
mi = mem->cnt - 1; mi = mem->cnt - 1;
...@@ -862,7 +872,7 @@ void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid, ...@@ -862,7 +872,7 @@ void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid,
phys_addr_t m_end = m->base + m->size; phys_addr_t m_end = m->base + m->size;
/* only memory regions are associated with nodes, check it */ /* only memory regions are associated with nodes, check it */
if (nid != MAX_NUMNODES && nid != memblock_get_region_node(m)) if (check_node && nid != memblock_get_region_node(m))
continue; continue;
/* skip hotpluggable memory regions if needed */ /* skip hotpluggable memory regions if needed */
...@@ -989,7 +999,7 @@ phys_addr_t __init memblock_alloc_nid(phys_addr_t size, phys_addr_t align, int n ...@@ -989,7 +999,7 @@ phys_addr_t __init memblock_alloc_nid(phys_addr_t size, phys_addr_t align, int n
phys_addr_t __init __memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr) phys_addr_t __init __memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr)
{ {
return memblock_alloc_base_nid(size, align, max_addr, MAX_NUMNODES); return memblock_alloc_base_nid(size, align, max_addr, NUMA_NO_NODE);
} }
phys_addr_t __init memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr) phys_addr_t __init memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr)
......
...@@ -117,7 +117,7 @@ static unsigned long __init free_low_memory_core_early(void) ...@@ -117,7 +117,7 @@ static unsigned long __init free_low_memory_core_early(void)
phys_addr_t start, end, size; phys_addr_t start, end, size;
u64 i; u64 i;
for_each_free_mem_range(i, MAX_NUMNODES, &start, &end, NULL) for_each_free_mem_range(i, NUMA_NO_NODE, &start, &end, NULL)
count += __free_memory_core(start, end); count += __free_memory_core(start, end);
/* free range that is used for reserved array if we allocate it */ /* free range that is used for reserved array if we allocate it */
...@@ -161,7 +161,7 @@ unsigned long __init free_all_bootmem(void) ...@@ -161,7 +161,7 @@ unsigned long __init free_all_bootmem(void)
reset_all_zones_managed_pages(); reset_all_zones_managed_pages();
/* /*
* We need to use MAX_NUMNODES instead of NODE_DATA(0)->node_id * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id
* because in some case like Node0 doesn't have RAM installed * because in some case like Node0 doesn't have RAM installed
* low ram will be on Node1 * low ram will be on Node1
*/ */
...@@ -215,7 +215,7 @@ static void * __init ___alloc_bootmem_nopanic(unsigned long size, ...@@ -215,7 +215,7 @@ static void * __init ___alloc_bootmem_nopanic(unsigned long size,
restart: restart:
ptr = __alloc_memory_core_early(MAX_NUMNODES, size, align, goal, limit); ptr = __alloc_memory_core_early(NUMA_NO_NODE, size, align, goal, limit);
if (ptr) if (ptr)
return ptr; return ptr;
...@@ -299,7 +299,7 @@ void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat, ...@@ -299,7 +299,7 @@ void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
if (ptr) if (ptr)
return ptr; return ptr;
ptr = __alloc_memory_core_early(MAX_NUMNODES, size, align, ptr = __alloc_memory_core_early(NUMA_NO_NODE, size, align,
goal, limit); goal, limit);
if (ptr) if (ptr)
return ptr; return ptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment