Skip to content

Commit f1f8618

Browse files
committed
mm/mm_init: deferred_init_memmap: use a job per zone
deferred_init_memmap() loops over free memory ranges and creates a padata_mt_job for every free range that intersects with the zone being initialized. padata_do_multithreaded() then splits every such range to several chunks and runs a thread that initializes struct pages in that chunk using deferred_init_memmap_chunk(). The number of threads is limited by amount of the CPUs on the node (or 1 for memoryless nodes). Looping through free memory ranges is then repeated in deferred_init_memmap_chunk() first to find the first range that should be initialized and then to traverse the ranges until the end of the chunk is reached. Remove the loop over free memory regions in deferred_init_memmap() and pass the entire zone to padata_do_multithreaded() so that it will be divided to several chunks by the parallelization code. Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Wei Yang <richard.weiyang@gmail.com> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
1 parent 3acb913 commit f1f8618

1 file changed

Lines changed: 16 additions & 22 deletions

File tree

mm/mm_init.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,12 +2179,10 @@ static int __init deferred_init_memmap(void *data)
21792179
{
21802180
pg_data_t *pgdat = data;
21812181
const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id);
2182-
unsigned long spfn = 0, epfn = 0;
2183-
unsigned long first_init_pfn, flags;
2182+
int max_threads = deferred_page_init_max_threads(cpumask);
2183+
unsigned long first_init_pfn, last_pfn, flags;
21842184
unsigned long start = jiffies;
21852185
struct zone *zone;
2186-
int max_threads;
2187-
u64 i = 0;
21882186

21892187
/* Bind memory initialisation thread to a local node if possible */
21902188
if (!cpumask_empty(cpumask))
@@ -2212,24 +2210,20 @@ static int __init deferred_init_memmap(void *data)
22122210

22132211
/* Only the highest zone is deferred */
22142212
zone = pgdat->node_zones + pgdat->nr_zones - 1;
2215-
2216-
max_threads = deferred_page_init_max_threads(cpumask);
2217-
2218-
while (deferred_init_mem_pfn_range_in_zone(&i, zone, &spfn, &epfn, first_init_pfn)) {
2219-
first_init_pfn = ALIGN(epfn, PAGES_PER_SECTION);
2220-
struct padata_mt_job job = {
2221-
.thread_fn = deferred_init_memmap_job,
2222-
.fn_arg = zone,
2223-
.start = spfn,
2224-
.size = first_init_pfn - spfn,
2225-
.align = PAGES_PER_SECTION,
2226-
.min_chunk = PAGES_PER_SECTION,
2227-
.max_threads = max_threads,
2228-
.numa_aware = false,
2229-
};
2230-
2231-
padata_do_multithreaded(&job);
2232-
}
2213+
last_pfn = SECTION_ALIGN_UP(zone_end_pfn(zone));
2214+
2215+
struct padata_mt_job job = {
2216+
.thread_fn = deferred_init_memmap_job,
2217+
.fn_arg = zone,
2218+
.start = first_init_pfn,
2219+
.size = last_pfn - first_init_pfn,
2220+
.align = PAGES_PER_SECTION,
2221+
.min_chunk = PAGES_PER_SECTION,
2222+
.max_threads = max_threads,
2223+
.numa_aware = false,
2224+
};
2225+
2226+
padata_do_multithreaded(&job);
22332227

22342228
/* Sanity check that the next zone really is unpopulated */
22352229
WARN_ON(pgdat->nr_zones < MAX_NR_ZONES && populated_zone(++zone));

0 commit comments

Comments
 (0)