[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250611052706.515408-2-shivankg@amd.com>
Date: Wed, 11 Jun 2025 05:27:07 +0000
From: Shivank Garg <shivankg@....com>
To: <mhiramat@...nel.org>, <oleg@...hat.com>, <peterz@...radead.org>,
<mingo@...hat.com>, <acme@...nel.org>, <namhyung@...nel.org>,
<mark.rutland@....com>, <alexander.shishkin@...ux.intel.com>,
<jolsa@...nel.org>, <irogers@...gle.com>, <adrian.hunter@...el.com>,
<kan.liang@...ux.intel.com>, <willy@...radead.org>, <rostedt@...dmis.org>,
<apopple@...dia.com>, <david@...hat.com>, <akpm@...ux-foundation.org>
CC: <linux-kernel@...r.kernel.org>, <linux-trace-kernel@...r.kernel.org>,
<linux-perf-users@...r.kernel.org>, <linux-mm@...ck.org>, Shivank Garg
<shivankg@....com>
Subject: [PATCH V2] mm: use folio_expected_ref_count() helper for reference counting
Replace open-coded folio reference count calculations with the
folio_expected_ref_count().
No functional changes intended.
Acked-by: David Hildenbrand <david@...hat.com>
Signed-off-by: Shivank Garg <shivankg@....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
Powered by blists - more mailing lists