public inbox for xfs-stable@lists.linux.dev
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, xfs-stable@lists.linux.dev,
	Uros Bizjak <ubizjak@gmail.com>,
	Christoph Hellwig <hch@infradead.org>,
	Chandan Babu R <chandan.babu@oracle.com>,
	"Darrick J. Wong" <djwong@kernel.org>,
	Dave Chinner <dchinner@redhat.com>,
	Carlos Maiolino <cem@kernel.org>,
	Catherine Hoang <catherine.hoang@oracle.com>
Subject: [PATCH 6.6 016/140] xfs: Use try_cmpxchg() in xlog_cil_insert_pcp_aggregate()
Date: Mon, 24 Feb 2025 15:33:35 +0100	[thread overview]
Message-ID: <20250224142603.644672193@linuxfoundation.org> (raw)
In-Reply-To: <20250224142602.998423469@linuxfoundation.org>

6.6-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Uros Bizjak <ubizjak@gmail.com>

commit 20195d011c840b01fa91a85ebcd099ca95fbf8fc upstream.

Use !try_cmpxchg instead of cmpxchg (*ptr, old, new) != old in
xlog_cil_insert_pcp_aggregate().  x86 CMPXCHG instruction returns
success in ZF flag, so this change saves a compare after cmpxchg.

Also, try_cmpxchg implicitly assigns old *ptr value to "old" when
cmpxchg fails. There is no need to re-read the value in the loop.

Note that the value from *ptr should be read using READ_ONCE to
prevent the compiler from merging, refetching or reordering the read.

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Reviewed-by: Christoph Hellwig <hch@infradead.org>
Cc: Chandan Babu R <chandan.babu@oracle.com>
Cc: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 fs/xfs/xfs_log_cil.c |   11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

--- a/fs/xfs/xfs_log_cil.c
+++ b/fs/xfs/xfs_log_cil.c
@@ -156,7 +156,6 @@ xlog_cil_insert_pcp_aggregate(
 	struct xfs_cil		*cil,
 	struct xfs_cil_ctx	*ctx)
 {
-	struct xlog_cil_pcp	*cilpcp;
 	int			cpu;
 	int			count = 0;
 
@@ -171,13 +170,11 @@ xlog_cil_insert_pcp_aggregate(
 	 * structures that could have a nonzero space_used.
 	 */
 	for_each_cpu(cpu, &ctx->cil_pcpmask) {
-		int	old, prev;
+		struct xlog_cil_pcp	*cilpcp = per_cpu_ptr(cil->xc_pcp, cpu);
+		int			old = READ_ONCE(cilpcp->space_used);
 
-		cilpcp = per_cpu_ptr(cil->xc_pcp, cpu);
-		do {
-			old = cilpcp->space_used;
-			prev = cmpxchg(&cilpcp->space_used, old, 0);
-		} while (old != prev);
+		while (!try_cmpxchg(&cilpcp->space_used, &old, 0))
+			;
 		count += old;
 	}
 	atomic_add(count, &ctx->space_used);



  parent reply	other threads:[~2025-02-24 14:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250224142602.998423469@linuxfoundation.org>
2025-02-24 14:33 ` [PATCH 6.6 002/140] xfs: assert a valid limit in xfs_rtfind_forw Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 003/140] xfs: validate inumber in xfs_iget Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 004/140] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 005/140] xfs: fix a typo Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 006/140] xfs: skip background cowblock trims on inodes open for write Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 007/140] xfs: dont free cowblocks from under dirty pagecache on unshare Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 008/140] xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 009/140] xfs: return bool from xfs_attr3_leaf_add Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 010/140] xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 011/140] xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 012/140] xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 013/140] xfs: dont ifdef around the exact minlen allocations Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 014/140] xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 015/140] xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc Greg Kroah-Hartman
2025-02-24 14:33 ` Greg Kroah-Hartman [this message]
2025-02-24 14:33 ` [PATCH 6.6 017/140] xfs: Remove empty declartion in header file Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 018/140] xfs: pass the exact range to initialize to xfs_initialize_perag Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 019/140] xfs: update the file system geometry after recoverying superblock buffers Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 020/140] xfs: error out when a superblock buffer update reduces the agcount Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 021/140] xfs: dont use __GFP_RETRY_MAYFAIL in xfs_initialize_perag Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 022/140] xfs: update the pag for the last AG at recovery time Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 023/140] xfs: Reduce unnecessary searches when searching for the best extents Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 024/140] xfs: streamline xfs_filestream_pick_ag Greg Kroah-Hartman
2025-02-24 14:33 ` [PATCH 6.6 025/140] xfs: Check for delayed allocations before setting extsize Greg Kroah-Hartman

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=20250224142603.644672193@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=catherine.hoang@oracle.com \
    --cc=cem@kernel.org \
    --cc=chandan.babu@oracle.com \
    --cc=dchinner@redhat.com \
    --cc=djwong@kernel.org \
    --cc=hch@infradead.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=ubizjak@gmail.com \
    --cc=xfs-stable@lists.linux.dev \
    /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