Skip to content

Commit c9a688a

Browse files
rppttorvalds
authored andcommitted
memblock: split checks whether a region should be skipped to a helper function
__next_mem_range() and __next_mem_range_rev() duplicate the code that checks whether a region should be skipped because of node or flags incompatibility. Split this code into a helper function. Link: http://lkml.kernel.org/r/1549455025-17706-3-git-send-email-rppt@linux.ibm.com Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Michal Hocko <mhocko@suse.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fe14512 commit c9a688a

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

mm/memblock.c

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,29 @@ void __init_memblock __next_reserved_mem_region(u64 *idx,
965965
*idx = ULLONG_MAX;
966966
}
967967

968+
static bool should_skip_region(struct memblock_region *m, int nid, int flags)
969+
{
970+
int m_nid = memblock_get_region_node(m);
971+
972+
/* only memory regions are associated with nodes, check it */
973+
if (nid != NUMA_NO_NODE && nid != m_nid)
974+
return true;
975+
976+
/* skip hotpluggable memory regions if needed */
977+
if (movable_node_is_enabled() && memblock_is_hotpluggable(m))
978+
return true;
979+
980+
/* if we want mirror memory skip non-mirror memory regions */
981+
if ((flags & MEMBLOCK_MIRROR) && !memblock_is_mirror(m))
982+
return true;
983+
984+
/* skip nomap memory unless we were asked for it explicitly */
985+
if (!(flags & MEMBLOCK_NOMAP) && memblock_is_nomap(m))
986+
return true;
987+
988+
return false;
989+
}
990+
968991
/**
969992
* __next__mem_range - next function for for_each_free_mem_range() etc.
970993
* @idx: pointer to u64 loop variable
@@ -1012,20 +1035,7 @@ void __init_memblock __next_mem_range(u64 *idx, int nid,
10121035
phys_addr_t m_end = m->base + m->size;
10131036
int m_nid = memblock_get_region_node(m);
10141037

1015-
/* only memory regions are associated with nodes, check it */
1016-
if (nid != NUMA_NO_NODE && nid != m_nid)
1017-
continue;
1018-
1019-
/* skip hotpluggable memory regions if needed */
1020-
if (movable_node_is_enabled() && memblock_is_hotpluggable(m))
1021-
continue;
1022-
1023-
/* if we want mirror memory skip non-mirror memory regions */
1024-
if ((flags & MEMBLOCK_MIRROR) && !memblock_is_mirror(m))
1025-
continue;
1026-
1027-
/* skip nomap memory unless we were asked for it explicitly */
1028-
if (!(flags & MEMBLOCK_NOMAP) && memblock_is_nomap(m))
1038+
if (should_skip_region(m, nid, flags))
10291039
continue;
10301040

10311041
if (!type_b) {
@@ -1129,20 +1139,7 @@ void __init_memblock __next_mem_range_rev(u64 *idx, int nid,
11291139
phys_addr_t m_end = m->base + m->size;
11301140
int m_nid = memblock_get_region_node(m);
11311141

1132-
/* only memory regions are associated with nodes, check it */
1133-
if (nid != NUMA_NO_NODE && nid != m_nid)
1134-
continue;
1135-
1136-
/* skip hotpluggable memory regions if needed */
1137-
if (movable_node_is_enabled() && memblock_is_hotpluggable(m))
1138-
continue;
1139-
1140-
/* if we want mirror memory skip non-mirror memory regions */
1141-
if ((flags & MEMBLOCK_MIRROR) && !memblock_is_mirror(m))
1142-
continue;
1143-
1144-
/* skip nomap memory unless we were asked for it explicitly */
1145-
if (!(flags & MEMBLOCK_NOMAP) && memblock_is_nomap(m))
1142+
if (should_skip_region(m, nid, flags))
11461143
continue;
11471144

11481145
if (!type_b) {

0 commit comments

Comments
 (0)