From: Shivank Garg <shivankg@amd.com>
To: <mhiramat@kernel.org>, <oleg@redhat.com>, <peterz@infradead.org>,
<mingo@redhat.com>, <acme@kernel.org>, <namhyung@kernel.org>,
<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
<jolsa@kernel.org>, <irogers@google.com>,
<adrian.hunter@intel.com>, <kan.liang@linux.intel.com>,
<willy@infradead.org>, <rostedt@goodmis.org>,
<apopple@nvidia.com>, <david@redhat.com>,
<akpm@linux-foundation.org>
Cc: <linux-kernel@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>,
<linux-perf-users@vger.kernel.org>, <linux-mm@kvack.org>,
Shivank Garg <shivankg@amd.com>
Subject: [PATCH V2] mm: use folio_expected_ref_count() helper for reference counting
Date: Wed, 11 Jun 2025 05:27:07 +0000 [thread overview]
Message-ID: <20250611052706.515408-2-shivankg@amd.com> (raw)
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
next reply other threads:[~2025-06-11 5:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 5:27 Shivank Garg [this message]
2025-06-11 7:39 ` Oscar Salvador
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=20250611052706.515408-2-shivankg@amd.com \
--to=shivankg@amd.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=apopple@nvidia.com \
--cc=david@redhat.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=willy@infradead.org \
/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