From: Zi Yan <ziy@nvidia.com>
To: David Hildenbrand <david@redhat.com>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Dan Carpenter <dan.carpenter@linaro.org>,
Antonio Quartulli <antonio@mandelbit.com>,
Hugh Dickins <hughd@google.com>,
Kirill Shutemov <k.shutemov@gmail.com>, Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Balbir Singh <balbirs@nvidia.com>,
Matthew Brost <matthew.brost@intel.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 5/6] mm/huge_memory: get frozen folio refcount with folio_expected_ref_count()
Date: Thu, 17 Jul 2025 22:29:59 -0400 [thread overview]
Message-ID: <20250718023000.4044406-6-ziy@nvidia.com> (raw)
In-Reply-To: <20250718023000.4044406-1-ziy@nvidia.com>
Instead of open coding the refcount calculation, use
folio_expected_ref_count() to calculate frozen folio refcount.
Because:
1. __folio_split() does not split a folio with PG_private, so no elevated
refcount from PG_private;
2. a frozen folio in __folio_split() is fully unmapped, so folio_mapcount()
in folio_expected_ref_count() is always 0;
3. (mapping || swap_cache) ? folio_nr_pages(folio) is taken care of by
folio_expected_ref_count() too.
Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Zi Yan <ziy@nvidia.com>
Acked-by: Balbir Singh <balbirs@nvidia.com>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
mm/huge_memory.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index d6ff5e8c89d7..4db67970ae69 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3737,6 +3737,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
if (folio_ref_freeze(folio, 1 + extra_pins)) {
struct address_space *swap_cache = NULL;
struct lruvec *lruvec;
+ int expected_refs;
if (folio_order(folio) > 1 &&
!list_empty(&folio->_deferred_list)) {
@@ -3800,11 +3801,8 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
new_folio = next) {
next = folio_next(new_folio);
- folio_ref_unfreeze(
- new_folio,
- 1 + ((mapping || swap_cache) ?
- folio_nr_pages(new_folio) :
- 0));
+ expected_refs = folio_expected_ref_count(new_folio) + 1;
+ folio_ref_unfreeze(new_folio, expected_refs);
lru_add_split_folio(folio, new_folio, lruvec, list);
@@ -3834,8 +3832,8 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
* Otherwise, a parallel folio_try_get() can grab @folio
* and its caller can see stale page cache entries.
*/
- folio_ref_unfreeze(folio, 1 +
- ((mapping || swap_cache) ? folio_nr_pages(folio) : 0));
+ expected_refs = folio_expected_ref_count(folio) + 1;
+ folio_ref_unfreeze(folio, expected_refs);
unlock_page_lruvec(lruvec);
--
2.47.2
next prev parent reply other threads:[~2025-07-18 2:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-18 2:29 [PATCH v4 0/6] __folio_split() clean up Zi Yan
2025-07-18 2:29 ` [PATCH v4 1/6] mm/huge_memory: move unrelated code out of __split_unmapped_folio() Zi Yan
2025-07-18 7:19 ` David Hildenbrand
2025-07-18 14:55 ` Lorenzo Stoakes
2025-07-18 2:29 ` [PATCH v4 2/6] mm/huge_memory: remove after_split label in __split_unmapped_folio() Zi Yan
2025-07-18 7:19 ` David Hildenbrand
2025-07-18 14:58 ` Lorenzo Stoakes
2025-07-18 2:29 ` [PATCH v4 3/6] mm/huge_memory: deduplicate code in __folio_split() Zi Yan
2025-07-18 7:23 ` David Hildenbrand
2025-07-18 2:29 ` [PATCH v4 4/6] mm/huge_memory: convert VM_BUG* to VM_WARN* in __folio_split Zi Yan
2025-07-18 7:22 ` David Hildenbrand
2025-07-18 14:48 ` Zi Yan
2025-07-18 15:05 ` Lorenzo Stoakes
2025-07-18 2:29 ` Zi Yan [this message]
2025-07-18 2:30 ` [PATCH v4 6/6] mm/huge_memory: refactor after-split (page) cache code Zi Yan
2025-07-18 5:26 ` [PATCH v4 0/6] __folio_split() clean up Lorenzo Stoakes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250718023000.4044406-6-ziy@nvidia.com \
--to=ziy@nvidia.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=antonio@mandelbit.com \
--cc=balbirs@nvidia.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dan.carpenter@linaro.org \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=hughd@google.com \
--cc=k.shutemov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=matthew.brost@intel.com \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®