From nobody Sat Apr 4 04:33:29 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 1EC653E316E for ; Fri, 20 Mar 2026 18:08:09 +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=1774030089; cv=none; b=BZ5vAAZJZ+Z3gBsx25goRCwpMh88Mh6tPVSUqDi2nLSiepzF7xmOSc1FK2juINzRtaLdq8szQMkw3ZmIGddpU5vKkqajj2pz9hXM3rW9EvO/y3MzVKw8cutcjqSfy/ARnahZfU+sM1tnn6uWE9pJWDLDWxbBA2r9BadDhaJa5k8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774030089; c=relaxed/simple; bh=ZH1v5KSbOjRMJis+xJElreGFGOfOHidqWPb9vPCbzbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AVp5EBMht3vgzIjm3uNL0OGbhgSNziENYQu3H23ZGtY7HLzQzDOSj3qvwyIomEnn/WhlUbvlBkbBIUcfXgVScYQ8WrATuwbToA9OLmtgsfrASPGMMSFR2ZEjNNa+JvWJqJC4Nck8h0SWVzjFqGqsiZo0OcG6s1MCN+RqmMk3XYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BSV5/vCW; 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="BSV5/vCW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77550C4CEF7; Fri, 20 Mar 2026 18:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774030088; bh=ZH1v5KSbOjRMJis+xJElreGFGOfOHidqWPb9vPCbzbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BSV5/vCWpCXSfa/ioXFIBAG+8nmeyr8ybamFgx0mpr5ZmqwisIsdb3aEZBNi0F0o+ sGA10+dmUWnY5UX/tWHlm72wgpiy2Td/BOcN5XBp7aY9m00c5lkmOQxQUN3TW6gYb5 YQVe3AGplKLmnPblpxiJosa6yq5UrC3AipQAYJVGNNh9VxQFHU89SkFP7ffARlhKs3 ORqPY9j+ElmMXhFwC+deQ7fmB7bUWwHXT7AINRSTRYakxvpSAcaswPVTYCNhGbpj9i QAmYjJQTVok8cYh+lXAnA4qW1VjNa42VKuSwx953WFANuANj1iP7K5YhTxIoBa4gMz eyBy2+z8eVA3A== 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 , Kiryl Shutsemau , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 13/13] mm/huge_memory: add and use has_deposited_pgtable() Date: Fri, 20 Mar 2026 18:07:30 +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 thread has_deposited through zap_huge_pmd(), make things clearer by adding has_deposited_pgtable() with comments describing why in each case. Signed-off-by: Lorenzo Stoakes (Oracle) Reviewed-by: Suren Baghdasaryan --- mm/huge_memory.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5831966391bd..610a6184e92c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2326,8 +2326,7 @@ static inline void zap_deposited_table(struct mm_stru= ct *mm, pmd_t *pmd) } =20 static void zap_huge_pmd_folio(struct mm_struct *mm, struct vm_area_struct= *vma, - pmd_t pmdval, struct folio *folio, bool is_present, - bool *has_deposit) + pmd_t pmdval, struct folio *folio, bool is_present) { const bool is_device_private =3D folio_is_device_private(folio); =20 @@ -2336,7 +2335,6 @@ static void zap_huge_pmd_folio(struct mm_struct *mm, = struct vm_area_struct *vma, folio_remove_rmap_pmd(folio, &folio->page, vma); =20 if (folio_test_anon(folio)) { - *has_deposit =3D true; add_mm_counter(mm, MM_ANONPAGES, -HPAGE_PMD_NR); } else { add_mm_counter(mm, mm_counter_file(folio), @@ -2363,6 +2361,27 @@ static struct folio *normal_or_softleaf_folio_pmd(st= ruct vm_area_struct *vma, return pmd_to_softleaf_folio(pmdval); } =20 +static bool has_deposited_pgtable(struct vm_area_struct *vma, pmd_t pmdval, + struct folio *folio) +{ + /* Some architectures require unconditional depositing. */ + if (arch_needs_pgtable_deposit()) + return true; + + /* + * Huge zero always deposited except for DAX which handles itself, see + * set_huge_zero_folio(). + */ + if (is_huge_zero_pmd(pmdval)) + return !vma_is_dax(vma); + + /* + * Otherwise, only anonymous folios are deposited, see + * __do_huge_pmd_anonymous_page(). + */ + return folio && folio_test_anon(folio); +} + /** * zap_huge_pmd - Zap a huge THP which is of PMD size. * @tlb: The MMU gather TLB state associated with the operation. @@ -2375,7 +2394,6 @@ static struct folio *normal_or_softleaf_folio_pmd(str= uct vm_area_struct *vma, bool zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr) { - bool has_deposit =3D arch_needs_pgtable_deposit(); struct mm_struct *mm =3D tlb->mm; struct folio *folio =3D NULL; bool is_present =3D false; @@ -2401,12 +2419,9 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm_= area_struct *vma, is_present =3D pmd_present(orig_pmd); folio =3D normal_or_softleaf_folio_pmd(vma, addr, orig_pmd, is_present); if (folio) - zap_huge_pmd_folio(mm, vma, orig_pmd, folio, is_present, - &has_deposit); - else if (is_huge_zero_pmd(orig_pmd)) - has_deposit =3D !vma_is_dax(vma); + zap_huge_pmd_folio(mm, vma, orig_pmd, folio, is_present); =20 - if (has_deposit) + if (has_deposited_pgtable(vma, orig_pmd, folio)) zap_deposited_table(mm, pmd); =20 spin_unlock(ptl); --=20 2.53.0