From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7DBA314D26 for ; Tue, 28 Apr 2026 08:19:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777364373; cv=none; b=nOlBDS0C2cKThrXwVPWFNJI/AZpjknpLJew8S8QM4ewUTYZ/2dOyNvAFpGpPOV+BXcbhsT3rwu6yU3T8oGTAEcO8iw3Q2L1aMWXa1mc4af1VxrGnzS9RyVe4CQe91V2Ca73kSkxPl/hRhUQSwLT1DMKjlV+p9Wjpvt1zhN2XaAo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777364373; c=relaxed/simple; bh=I09DVnwUmT2FgjMlL1sbr+fqXGO2fhcK42PNEcwA7S4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=exiBKioClsiPhd+WGPEBPRSntGbZL2iWL1xWnUZpnunzhLRNomoJjyllLGJNXmqoxM5TeqjqzapZb+pKt71XkiRy4dotE/DL2SWDR4hYUW+Iax/ZdRJxzHj7YWAPene/GvLm5cx/PRi74K1txq88BSHXytXg4oh0+r38Quv5KnM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=UuoZxxdF; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="UuoZxxdF" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-362e30526f8so2065112a91.3 for ; Tue, 28 Apr 2026 01:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1777364371; x=1777969171; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X8jAPi1Ug7YtuxDodtBim0VZYTDek6DS5vd5ro+n0/g=; b=UuoZxxdFvqi3tYk964lJaaEa0q2ohWRuPhcP8tD9feMemxnE/tk+hCn6pqCwHNcZVZ B8Z8b1gA6bHZDCtZOA1nJFI8VWTm74l7xFcWHRGdThwvDKWp9JqMDdb5ctlLjmejxH5y f1lwlqqmjfam8mF5cG4iuYjpljZWkp8hwggPt1ZDEuxM25slrjRiG7PVYZ9hVONJkMT6 3vOgnw535O9xKwfilVUEY1Fx6BU4fEZKNYf9AMQjKRQqKlrryYeVvO+tRz5cHs/1sYly YtmvbagFyei+bKEPydR7d/ubr/LhU31xTWJnN3MzZaePbiwWXS/1uD9KLnYLq0wB7X0M 7MIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777364371; x=1777969171; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=X8jAPi1Ug7YtuxDodtBim0VZYTDek6DS5vd5ro+n0/g=; b=jxWiQVW6sGawpSmPAWhp6XT0B16/h2F0UDdIHVBgqJcPh9FTlOhs0mI9YpPUm6JzxH ih0kxKTdCUjatsxuM/2WyP0FMTDapyTG5dUNlrUdxXq+ZBNl/r3aKCEYnfPTmZqGPL2K DiYsXkzDYqpvZIY3tzxMLKObzcoCixPBzWmNO15CoIxL+fNcP6FtY9QY8zzT9PoVQxUa a4WXX8tPHAmhyXpGXHO11Mt27BhLNUMW4Fa93bBtx3WxRsZZffcrzZPMlQRxi3OJhUjy kfLMJkmA+Y0f/1NqsNgPYWMd9DqkqtijSOZ99l/kuYF1xcPA1rw4PQpq+6Pp7trItdMG 3wEw== X-Forwarded-Encrypted: i=1; AFNElJ85Ts9aAlYdsyWBzpE6LyT4fmtPKic/tdUuvM/uCvtpURQ9A6ExfKIxFs20jgKPEtORavXCitRdy6UMmiE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5Fz/nxGvEvmg58dvfQx4DRwZDn/X+qjaySexpSTAB8LZoFO66 95MQrqoVSm/LvItETIMOycelDpSF3dqq1d90NJ0kk1uXFVv/0N667N0MWCeDkon8uPI= X-Gm-Gg: AeBDievnfcix5Sea6tGXGgBQrA8+bpcVp/5RbZknmdah55LChDljjqcooRHN1A67uxW uGszy7L8zJbyXbeRcgEgnsDNfdqVrIOaf8mItgy3N0ToZqvrST5LqdBisQ29yeGGhCoqf363Ncb Xw/Iv9MemmV6oiJLzVGA7DGXGFA0wcl/gD8auehqOegK9OdkPX6I09AL/wVR09Sth7lE892RmBD ge8bk76c1I4HsB50izluYapiATNTIB5AFAU0NKd32wjTHIuLtpCaBcVsyTEvpuf91M8efeU5jj2 PRD6h/gAcuAMbsBNUI+l9HzryMOpPxJ36S6SJoKMFsjiICBUYHH7GZ2o3iW+U8x1fxoxBhl3kYM 0KUG0d0nHqCkZ12lmMWVr95IcJbr1BROnOGiBDQIxzl8skPO6+/C9nj7FkHw0Q0fkK7TjNWAyh1 snfwGkjJv0dVbhFtJv7ID8e5X1MfhfJRQ3uYKrELqshPdV+9ccNsxoK9E= X-Received: by 2002:a17:90b:17c1:b0:35d:a3b4:2ef6 with SMTP id 98e67ed59e1d1-364920601f9mr2483211a91.21.1777364371205; Tue, 28 Apr 2026 01:19:31 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.101]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3649003650esm2181356a91.8.2026.04.28.01.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 01:19:30 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Muchun Song , stable@vger.kernel.org Subject: [PATCH v8 5/6] mm/mm_init: Fix pageblock migratetype for ZONE_DEVICE compound pages Date: Tue, 28 Apr 2026 16:18:54 +0800 Message-Id: <20260428081855.1249045-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260428081855.1249045-1-songmuchun@bytedance.com> References: <20260428081855.1249045-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The memmap_init_zone_device() function only initializes the migratetype of the first pageblock of a compound page. If the compound page size exceeds pageblock_nr_pages (e.g., 1GB hugepages with 2MB pageblocks), subsequent pageblocks in the compound page remain uninitialized. Move the migratetype initialization out of __init_zone_device_page() and into a separate pageblock_migratetype_init_range() function. This iterates over the entire PFN range of the memory, ensuring that all pageblocks are correctly initialized. Also remove the stale confusing comment about MEMINIT_HOTPLUG above the migratetype setting since it is an obsolete relic from commit 966cf44f637e ("mm: defer ZONE_DEVICE page initialization to the point where we init pgmap") and no longer makes sense here. Fixes: c4386bd8ee3a ("mm/memremap: add ZONE_DEVICE support for compound pages") Cc: stable@vger.kernel.org Signed-off-by: Muchun Song Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Oscar Salvador Acked-by: David Hildenbrand (Arm) --- mm/mm_init.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index f9f8e1af921c..cfc76953e249 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -674,6 +674,20 @@ static inline void fixup_hashdist(void) static inline void fixup_hashdist(void) {} #endif /* CONFIG_NUMA */ +#ifdef CONFIG_ZONE_DEVICE +static __meminit void pageblock_migratetype_init_range(unsigned long pfn, + unsigned long nr_pages, int migratetype) +{ + const unsigned long end = pfn + nr_pages; + + for (pfn = pageblock_align(pfn); pfn < end; pfn += pageblock_nr_pages) { + init_pageblock_migratetype(pfn_to_page(pfn), migratetype, false); + if (IS_ALIGNED(pfn, PAGES_PER_SECTION)) + cond_resched(); + } +} +#endif + /* * Initialize a reserved page unconditionally, finding its zone first. */ @@ -1011,21 +1025,6 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, page_folio(page)->pgmap = pgmap; page->zone_device_data = NULL; - /* - * Mark the block movable so that blocks are reserved for - * movable at startup. This will force kernel allocations - * to reserve their blocks rather than leaking throughout - * the address space during boot when many long-lived - * kernel allocations are made. - * - * Please note that MEMINIT_HOTPLUG path doesn't clear memmap - * because this is done early in section_activate() - */ - if (pageblock_aligned(pfn)) { - init_pageblock_migratetype(page, MIGRATE_MOVABLE, false); - cond_resched(); - } - /* * ZONE_DEVICE pages other than MEMORY_TYPE_GENERIC are released * directly to the driver page allocator which will set the page count @@ -1122,6 +1121,9 @@ void __ref memmap_init_zone_device(struct zone *zone, __init_zone_device_page(page, pfn, zone_idx, nid, pgmap); + if (IS_ALIGNED(pfn, PAGES_PER_SECTION)) + cond_resched(); + if (pfns_per_compound == 1) continue; @@ -1129,6 +1131,8 @@ void __ref memmap_init_zone_device(struct zone *zone, compound_nr_pages(altmap, pgmap)); } + pageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE); + pr_debug("%s initialised %lu pages in %ums\n", __func__, nr_pages, jiffies_to_msecs(jiffies - start)); } -- 2.20.1