diff options
author | Mike Rapoport <rppt@linux.ibm.com> | 2019-03-12 02:30:50 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-12 13:04:02 -0400 |
commit | c9a688a3e918c4eb4f3916ff99a6dae8995af41b (patch) | |
tree | 29faf621dd594f941023178df41afdcc6fe2c58c | |
parent | fe145124dbe53c86bf32b941b2f2f88f891d985d (diff) |
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>
-rw-r--r-- | mm/memblock.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/mm/memblock.c b/mm/memblock.c index 068e147695ee..dfe90bc210d9 100644 --- a/mm/memblock.c +++ b/mm/memblock.c | |||
@@ -965,6 +965,29 @@ void __init_memblock __next_reserved_mem_region(u64 *idx, | |||
965 | *idx = ULLONG_MAX; | 965 | *idx = ULLONG_MAX; |
966 | } | 966 | } |
967 | 967 | ||
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 | |||
968 | /** | 991 | /** |
969 | * __next__mem_range - next function for for_each_free_mem_range() etc. | 992 | * __next__mem_range - next function for for_each_free_mem_range() etc. |
970 | * @idx: pointer to u64 loop variable | 993 | * @idx: pointer to u64 loop variable |
@@ -1012,20 +1035,7 @@ void __init_memblock __next_mem_range(u64 *idx, int nid, | |||
1012 | phys_addr_t m_end = m->base + m->size; | 1035 | phys_addr_t m_end = m->base + m->size; |
1013 | int m_nid = memblock_get_region_node(m); | 1036 | int m_nid = memblock_get_region_node(m); |
1014 | 1037 | ||
1015 | /* only memory regions are associated with nodes, check it */ | 1038 | if (should_skip_region(m, nid, flags)) |
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)) | ||
1029 | continue; | 1039 | continue; |
1030 | 1040 | ||
1031 | if (!type_b) { | 1041 | if (!type_b) { |
@@ -1129,20 +1139,7 @@ void __init_memblock __next_mem_range_rev(u64 *idx, int nid, | |||
1129 | phys_addr_t m_end = m->base + m->size; | 1139 | phys_addr_t m_end = m->base + m->size; |
1130 | int m_nid = memblock_get_region_node(m); | 1140 | int m_nid = memblock_get_region_node(m); |
1131 | 1141 | ||
1132 | /* only memory regions are associated with nodes, check it */ | 1142 | if (should_skip_region(m, nid, flags)) |
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)) | ||
1146 | continue; | 1143 | continue; |
1147 | 1144 | ||
1148 | if (!type_b) { | 1145 | if (!type_b) { |