From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 7556E367F40 for ; Wed, 15 Apr 2026 11:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776251699; cv=none; b=ADoQfjX6Um1/SFM8dtBEaRUKL5ZqlRr8lE3zQCXNFrs1WA2m4BRHYnIkpxeWTgV5MA/h6NxLqGmo6m41vmxDAHFDPz5l7E3zkBdudqgWpXpyIKlwilJHtJaquzLvNy9GKaDee/YwXSuK8SOrUurHraDULVuWtr9kaKL8zOzKGik= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776251699; c=relaxed/simple; bh=eaYlGmdNTGMhO6SKUx0BUddmt3tOQxCaGHyqTB+T3jw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nMBA0x0aggLIsRfAz04Vgon8CX/eC0leSNwFCC4kxytncfTLzsV1MZ2bo8MkmRKH69CcOWEzEUMylvplxmivSvm5emAbnZR8/RLFM6emf9YhufQDD6nq4VDuFxayASDlWiMbacpWrfqlAUDXVuhEStnFKz2w6T/60RyUqDSSyLQ= 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=KlQVBp83; arc=none smtp.client-ip=209.85.214.171 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="KlQVBp83" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2b24fdac394so60010275ad.3 for ; Wed, 15 Apr 2026 04:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1776251698; x=1776856498; 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=M2tbh3r8pv+EpSWaqLjjsd7slEO4DRhf7DkjZnRXEmM=; b=KlQVBp831WnMSphhU+WwA8tdD5IQ2QlckO7n+eNC11kvAM3RlhpuGcBTM5PXrgHa1N imANnhMoVhAAjXfHmrvts/8sCmAMUTTpodIGeT0CzApspfOiUghKe1mMCDUQaxTxgK9P sY7M91Lj0L+s9Ex1y+SXaqd+QsZ5T8U5GQJHksVibRFt5ZPrTUxPHgB6zGkGizH4r3Hs lK7SoA6f9X6Tm5DIq44G2sPHlFslBrE55z1W4vKYBfxnYo39QtXqI8+li45JPrnJtQNS 7XrpTZl0MrOd7PjRCGlPxJeIX5XpGZi18nH6eY+ZOQxHxFdqE7dWqD557EsqtfyLgX7z 9X1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776251698; x=1776856498; 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=M2tbh3r8pv+EpSWaqLjjsd7slEO4DRhf7DkjZnRXEmM=; b=Qxj56qqXe1/7mmWdKOpIhxspvxQtT8vwclZLjqjdK215/C7KHlQSoFTI73WG38sinj yM58gTyJrohXZRddCMDnccyCBy9medcgl69lLPn1oUbiVshs+Y8i+0wkEeHiEfiK/3b0 yhwHUHrX4i4YPEAVxZsFcGHLcKcqBJfdQgmRv9RsTGQ/S5z6k4lHEYLXlzHCxP9CEJUD HMsjZU2ipP9/otfdLQ1wONl17pRoWUuY+CbuHybvIgTeZuR+k5qtVcYBU8mikQoR0Kn2 BL7dcwzMxjFEmluLZI2lk10G6lUvK8KHzmy3soIReb9NVyFWm0xig/fCbGHUUqAuDnV6 at8g== X-Forwarded-Encrypted: i=1; AFNElJ9t/UEBVwC4R51EPy7qJ/lMYpClooDuJ+a313H+XJLyp3SpEa7Qu+7YC4XoEeoRMHtk2jWvNBOf7ZWcvZY=@vger.kernel.org X-Gm-Message-State: AOJu0YwoGHOzUvaXQUZUW2Z8yKPacGN4yfqU5NkzknCsst4h3dRA1hGS XDpdDOVvbu8CRmA8WuiBRtMWzeX9fdYNdCqlrRu59LIcGOPeNhBQLY47ov9X15RBInY= X-Gm-Gg: AeBDietfuhmd17m42Hmh7ImSgugawqKfoObTUj33rDzuM6c9HrAst2dzwVXsyjQ4bLf m0pNrK8TIGpHM25RNSJvqUHPNwt6Qm4isUmDGxEIgxq0N7jFGmWG9QiQ5rZr39D3JoTGg1Vj2Ir 0o+3WhZMF5s/Yz7WABYxMkW3ynP1SzuGETMT+dsdnhfTtAqzvbkzBuwh3pCeeWEesXwgO34jKxT WFYizhmlt9FSWHT/z+SN7PwVaxPjdPFk9C3synUsIlCz8chKWLaCO6hz7Jym+2jvB3FMtvUTiWz hcpeh206pMKlWOeCoywz7SG0JbrKOnIsaXiDaUd6hbkJzReK0fpOf8V/CQv5MTgoIj9l0YKNZmP 6C+krgNB9yP1ApCAe68MJcEKEwlxDbtFiXGJXcmvGmSXOrvjRmgcucS/Cjnzuv35ycSEc4+5Yqm VGHdkvQJadlVgU9QxHWk40VzTO0EjbbARpQXSzH0SPsu0= X-Received: by 2002:a17:903:1a24:b0:2b4:63c8:ce18 with SMTP id d9443c01a7336-2b463c8db7emr113441015ad.12.1776251697718; Wed, 15 Apr 2026 04:14:57 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.96]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b477fd3724sm19509485ad.0.2026.04.15.04.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 04:14:57 -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 Subject: [PATCH v2 6/6] mm/mm_init: Fix pageblock migratetype for ZONE_DEVICE compound pages Date: Wed, 15 Apr 2026 19:14:12 +0800 Message-Id: <20260415111412.1003526-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260415111412.1003526-1-songmuchun@bytedance.com> References: <20260415111412.1003526-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. Fixes: c4386bd8ee3a ("mm/memremap: add ZONE_DEVICE support for compound pages") Signed-off-by: Muchun Song --- mm/mm_init.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index f9f8e1af921c..30528c4206c1 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -674,6 +674,19 @@ static inline void fixup_hashdist(void) static inline void fixup_hashdist(void) {} #endif /* CONFIG_NUMA */ +static __meminit void pageblock_migratetype_init_range(unsigned long pfn, + unsigned long nr_pages, + int migratetype) +{ + 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(); + } +} + /* * Initialize a reserved page unconditionally, finding its zone first. */ @@ -1011,21 +1024,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 +1120,8 @@ void __ref memmap_init_zone_device(struct zone *zone, __init_zone_device_page(page, pfn, zone_idx, nid, pgmap); + cond_resched(); + if (pfns_per_compound == 1) continue; @@ -1129,6 +1129,18 @@ void __ref memmap_init_zone_device(struct zone *zone, compound_nr_pages(altmap, pgmap)); } + /* + * 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() + */ + 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