* [PATCH v2] mm/mmzone.c: use try_cmpxchg() in page_cpupid_xchg_last()
@ 2022-01-20 1:11 Peter Collingbourne
0 siblings, 0 replies; only message in thread
From: Peter Collingbourne @ 2022-01-20 1:11 UTC (permalink / raw)
To: Andrey Konovalov, Andrew Morton
Cc: Peter Collingbourne, linux-mm, linux-kernel, Peter Zijlstra,
Mel Gorman
This will let us avoid an additional read from page->flags when
retrying the compare-exchange on some architectures.
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Peter Collingbourne <pcc@google.com>
Link: https://linux-review.googlesource.com/id/I2e1f5b5b080ac9c4e0eb7f98768dba6fd7821693
---
mm/mmzone.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/mm/mmzone.c b/mm/mmzone.c
index eb89d6e018e2..d8a9b0e1b526 100644
--- a/mm/mmzone.c
+++ b/mm/mmzone.c
@@ -89,13 +89,14 @@ int page_cpupid_xchg_last(struct page *page, int cpupid)
unsigned long old_flags, flags;
int last_cpupid;
+ old_flags = READ_ONCE(page->flags);
do {
- old_flags = flags = page->flags;
- last_cpupid = page_cpupid_last(page);
+ flags = old_flags;
+ last_cpupid = (flags >> LAST_CPUPID_PGSHIFT) & LAST_CPUPID_MASK;
flags &= ~(LAST_CPUPID_MASK << LAST_CPUPID_PGSHIFT);
flags |= (cpupid & LAST_CPUPID_MASK) << LAST_CPUPID_PGSHIFT;
- } while (unlikely(cmpxchg(&page->flags, old_flags, flags) != old_flags));
+ } while (unlikely(!try_cmpxchg(&page->flags, &old_flags, flags)));
return last_cpupid;
}
--
2.34.1.703.g22d0c6ccf7-goog
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-01-20 1:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-20 1:11 [PATCH v2] mm/mmzone.c: use try_cmpxchg() in page_cpupid_xchg_last() Peter Collingbourne
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).