linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] mm: use folio_expected_ref_count() helper for reference counting
@ 2025-06-11  5:27 Shivank Garg
  2025-06-11  7:39 ` Oscar Salvador
  0 siblings, 1 reply; 2+ messages in thread
From: Shivank Garg @ 2025-06-11  5:27 UTC (permalink / raw)
  To: mhiramat, oleg, peterz, mingo, acme, namhyung, mark.rutland,
	alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang,
	willy, rostedt, apopple, david, akpm
  Cc: linux-kernel, linux-trace-kernel, linux-perf-users, linux-mm,
	Shivank Garg

Replace open-coded folio reference count calculations with the
folio_expected_ref_count().

No functional changes intended.

Acked-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
Changes from V1:
- https://lore.kernel.org/linux-mm/20250609170806.447302-2-shivankg@amd.com
- remove extra comments
- drop RFC tag
---
 kernel/events/uprobes.c | 3 +--
 mm/memfd.c              | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 4c965ba77f9f..8a601df87072 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -436,8 +436,7 @@ static int __uprobe_write_opcode(struct vm_area_struct *vma,
 	 * there are no unexpected folio references ...
 	 */
 	if (is_register || userfaultfd_missing(vma) ||
-	    (folio_ref_count(folio) != folio_mapcount(folio) + 1 +
-	     folio_test_swapcache(folio) * folio_nr_pages(folio)))
+	    (folio_ref_count(folio) != folio_expected_ref_count(folio) + 1))
 		goto remap;
 
 	/*
diff --git a/mm/memfd.c b/mm/memfd.c
index ab367e61553d..4db1fd2959aa 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -32,8 +32,7 @@
 
 static bool memfd_folio_has_extra_refs(struct folio *folio)
 {
-	return folio_ref_count(folio) - folio_mapcount(folio) !=
-	       folio_nr_pages(folio);
+	return folio_ref_count(folio) != folio_expected_ref_count(folio);
 }
 
 static void memfd_tag_pins(struct xa_state *xas)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-11  7:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11  5:27 [PATCH V2] mm: use folio_expected_ref_count() helper for reference counting Shivank Garg
2025-06-11  7:39 ` Oscar Salvador

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).