Skip to content

Commit f1180fd

Browse files
RichardWeiYangrppt
authored andcommitted
mm/mm_init.c: not always search next deferred_init_pfn from very beginning
In function deferred_init_memmap(), we call deferred_init_mem_pfn_range_in_zone() to get the next deferred_init_pfn. But we always search it from the very beginning. Since we save the index in i, we can leverage this to search from i next time. [rppt refine the comment] Signed-off-by: Wei Yang <[email protected]> Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Mike Rapoport (IBM) <[email protected]>
1 parent 544b8e1 commit f1180fd

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

include/linux/memblock.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,6 @@ void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
299299
void __next_mem_pfn_range_in_zone(u64 *idx, struct zone *zone,
300300
unsigned long *out_spfn,
301301
unsigned long *out_epfn);
302-
/**
303-
* for_each_free_mem_pfn_range_in_zone - iterate through zone specific free
304-
* memblock areas
305-
* @i: u64 used as loop variable
306-
* @zone: zone in which all of the memory blocks reside
307-
* @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
308-
* @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
309-
*
310-
* Walks over free (memory && !reserved) areas of memblock in a specific
311-
* zone. Available once memblock and an empty zone is initialized. The main
312-
* assumption is that the zone start, end, and pgdat have been associated.
313-
* This way we can use the zone to determine NUMA node, and if a given part
314-
* of the memblock is valid for the zone.
315-
*/
316-
#define for_each_free_mem_pfn_range_in_zone(i, zone, p_start, p_end) \
317-
for (i = 0, \
318-
__next_mem_pfn_range_in_zone(&i, zone, p_start, p_end); \
319-
i != U64_MAX; \
320-
__next_mem_pfn_range_in_zone(&i, zone, p_start, p_end))
321302

322303
/**
323304
* for_each_free_mem_pfn_range_in_zone_from - iterate through zone specific

mm/mm_init.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,24 +2021,29 @@ static unsigned long __init deferred_init_pages(struct zone *zone,
20212021
}
20222022

20232023
/*
2024-
* This function is meant to pre-load the iterator for the zone init.
2025-
* Specifically it walks through the ranges until we are caught up to the
2026-
* first_init_pfn value and exits there. If we never encounter the value we
2027-
* return false indicating there are no valid ranges left.
2024+
* This function is meant to pre-load the iterator for the zone init from
2025+
* a given point.
2026+
* Specifically it walks through the ranges starting with initial index
2027+
* passed to it until we are caught up to the first_init_pfn value and
2028+
* exits there. If we never encounter the value we return false indicating
2029+
* there are no valid ranges left.
20282030
*/
20292031
static bool __init
20302032
deferred_init_mem_pfn_range_in_zone(u64 *i, struct zone *zone,
20312033
unsigned long *spfn, unsigned long *epfn,
20322034
unsigned long first_init_pfn)
20332035
{
2034-
u64 j;
2036+
u64 j = *i;
2037+
2038+
if (j == 0)
2039+
__next_mem_pfn_range_in_zone(&j, zone, spfn, epfn);
20352040

20362041
/*
20372042
* Start out by walking through the ranges in this zone that have
20382043
* already been initialized. We don't need to do anything with them
20392044
* so we just need to flush them out of the system.
20402045
*/
2041-
for_each_free_mem_pfn_range_in_zone(j, zone, spfn, epfn) {
2046+
for_each_free_mem_pfn_range_in_zone_from(j, zone, spfn, epfn) {
20422047
if (*epfn <= first_init_pfn)
20432048
continue;
20442049
if (*spfn < first_init_pfn)
@@ -2110,7 +2115,7 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn,
21102115
{
21112116
unsigned long spfn, epfn;
21122117
struct zone *zone = arg;
2113-
u64 i;
2118+
u64 i = 0;
21142119

21152120
deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn, start_pfn);
21162121

@@ -2141,7 +2146,7 @@ static int __init deferred_init_memmap(void *data)
21412146
unsigned long start = jiffies;
21422147
struct zone *zone;
21432148
int max_threads;
2144-
u64 i;
2149+
u64 i = 0;
21452150

21462151
/* Bind memory initialisation thread to a local node if possible */
21472152
if (!cpumask_empty(cpumask))
@@ -2216,7 +2221,7 @@ bool __init deferred_grow_zone(struct zone *zone, unsigned int order)
22162221
unsigned long first_deferred_pfn = pgdat->first_deferred_pfn;
22172222
unsigned long spfn, epfn, flags;
22182223
unsigned long nr_pages = 0;
2219-
u64 i;
2224+
u64 i = 0;
22202225

22212226
/* Only the last zone may have deferred pages */
22222227
if (zone_end_pfn(zone) != pgdat_end_pfn(pgdat))

0 commit comments

Comments
 (0)