From nobody Mon Apr 6 13:28:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 430C03D47C1 for ; Thu, 19 Mar 2026 13:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773925246; cv=none; b=UyWGGaB8qIg+tfZbFZfOTl31ZyhLG3xBYwnMhEk/T8PCWPaW5j6Q8JwSX3vosXSPg75B6uzmxkUD0GMMwkL1IFNNP+p8A6QLujUmRun6u/58Nm4SWueegkoB1ld6ajBznrCiFN+s9QwbngI5PebweySOhgxam9ctiNtWIB8sEXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773925246; c=relaxed/simple; bh=9GL71TGtr4Xl48AxLVp+Sw8hVkXKWEDVrPJDeJyAQmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=acwT0SwAmJ3HuY1EZibpnfl32wNuf2ZKk7AspKUtI8SMhFIV9C4ycsy30lfHdZ4jeRAxzBuzs9QeZD+sazuNdY47kj5K40VzSrLG7thUcmAGBA1ctcQEdEWLWeeLKmiGzUTa2Ln0Sc70bWfhttgev1p2TvyiC29moNTV0Fjduh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OA9gxtDY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OA9gxtDY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F9DAC2BC9E; Thu, 19 Mar 2026 13:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773925245; bh=9GL71TGtr4Xl48AxLVp+Sw8hVkXKWEDVrPJDeJyAQmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OA9gxtDYCARiW/xFj3Sq62/bn+4nR4RBKTIioCsZQ28gTNNA9AcNWYSFoBaWEpGas LddWivmQh6y897zbvCavLhQY8U+wF9VqufAyVfsIP/KcCpP43VuFcu27fwppyYMCRq ZmpwL6pd5CoX+a6a/TfzSb9tBw6ND/qHm2ufVxR+5H6hAtMLSvB7BKQSb7tGtPRsYz UHA9O3fRmq76zqwEex9NpH2fefSW0+bYKjCNzvxYbanyFd4ankQcsFD4fPts6tIUW2 uJMQWIrTHVw33/FrL+K6yWQWUyu+e10K9vnX0fXZwvXoBwZz97LTIsVJvBrfYJMLQS bM5OYt36Az/9A== From: "Lorenzo Stoakes (Oracle)" To: Andrew Morton Cc: David Hildenbrand , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 9/9] mm/huge_memory: have zap_huge_pmd() use vm_normal_folio_pmd() Date: Thu, 19 Mar 2026 13:00:15 +0000 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than having special handling for the 'special huge' and huge zero pages, have vm_normal_folio_pmd() figure this out for us, and use the presence of a folio to determine whether to exit early. We can therefore delete code, move the 'present or not' logic up and make things clearer this way. Suggested-by: David Hildenbrand (ARM) Signed-off-by: Lorenzo Stoakes (Oracle) --- mm/huge_memory.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 22715027e56c..5ffe3334c80d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2431,9 +2431,9 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm_a= rea_struct *vma, pmd_t *pmd, unsigned long addr) { bool needs_remove_rmap =3D false; - struct folio *folio =3D NULL; bool needs_deposit =3D false; bool is_present =3D false; + struct folio *folio; spinlock_t *ptl; pmd_t orig_pmd; =20 @@ -2453,28 +2453,26 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm= _area_struct *vma, =20 arch_check_zapped_pmd(vma, orig_pmd); tlb_remove_pmd_tlb_entry(tlb, pmd, addr); - if (vma_is_special_huge(vma)) - goto out; - if (is_huge_zero_pmd(orig_pmd)) { - needs_deposit =3D !vma_is_dax(vma); - goto out; - } =20 - is_present =3D pmd_present(orig_pmd); - if (is_present) { - folio =3D pmd_folio(orig_pmd); - needs_remove_rmap =3D true; + if (pmd_present(orig_pmd)) { + folio =3D vm_normal_folio_pmd(vma, addr, orig_pmd); + if (folio) { + needs_remove_rmap =3D true; + is_present =3D true; + } else if (is_huge_zero_pmd(orig_pmd)) { + needs_deposit =3D !vma_is_dax(vma); + } } else if (pmd_is_valid_softleaf(orig_pmd)) { - const softleaf_t entry =3D softleaf_from_pmd(orig_pmd); - - folio =3D softleaf_to_folio(entry); + folio =3D softleaf_to_folio(softleaf_from_pmd(orig_pmd)); needs_remove_rmap =3D folio_is_device_private(folio); if (!thp_migration_supported()) WARN_ONCE(1, "Non present huge pmd without pmd migration enabled!"); } else { WARN_ON_ONCE(true); - goto out; + folio =3D NULL; } + if (!folio) + goto out; =20 if (folio_test_anon(folio)) { needs_deposit =3D true; --=20 2.53.0