On Fri, Feb 21, 2025 at 4:24 PM <gregkh@xxxxxxxxxxxxxxxxxxx> wrote: > > > This is a note to let you know that I've just added the patch titled > > xfs: Use try_cmpxchg() in xlog_cil_insert_pcp_aggregate() > > to the 6.6-stable tree which can be found at: > http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary > > The filename of the patch is: > xfs-use-try_cmpxchg-in-xlog_cil_insert_pcp_aggregate.patch > and it can be found in the queue-6.6 subdirectory. > > If you, or anyone else, feels it should not be added to the stable tree, > please let <stable@xxxxxxxxxxxxxxx> know about it. Dear stable maintainers, the referred patch has a follow-up patch that optimizes this part even further: "xfs: Use xchg() in xlog_cil_insert_pcp_aggregate()" commit 214093534f3c046bf5acc9affbf4e6bd9af4538b upstream. Uros. > > > From stable+bounces-113981-greg=kroah.com@xxxxxxxxxxxxxxx Wed Feb 5 22:41:10 2025 > From: Catherine Hoang <catherine.hoang@xxxxxxxxxx> > Date: Wed, 5 Feb 2025 13:40:16 -0800 > Subject: xfs: Use try_cmpxchg() in xlog_cil_insert_pcp_aggregate() > To: stable@xxxxxxxxxxxxxxx > Cc: xfs-stable@xxxxxxxxxxxxxxx > Message-ID: <20250205214025.72516-16-catherine.hoang@xxxxxxxxxx> > > From: Uros Bizjak <ubizjak@xxxxxxxxx> > > 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@xxxxxxxxx> > Reviewed-by: Christoph Hellwig <hch@xxxxxxxxxxxxx> > Cc: Chandan Babu R <chandan.babu@xxxxxxxxxx> > Cc: Darrick J. Wong <djwong@xxxxxxxxxx> > Reviewed-by: Dave Chinner <dchinner@xxxxxxxxxx> > Signed-off-by: Carlos Maiolino <cem@xxxxxxxxxx> > Signed-off-by: Catherine Hoang <catherine.hoang@xxxxxxxxxx> > Acked-by: Darrick J. Wong <djwong@xxxxxxxxxx> > Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> > --- > 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); > > > Patches currently in stable-queue which might be from catherine.hoang@xxxxxxxxxx are > > queue-6.6/xfs-return-bool-from-xfs_attr3_leaf_add.patch > queue-6.6/xfs-fix-a-sloppy-memory-handling-bug-in-xfs_iroot_realloc.patch > queue-6.6/xfs-streamline-xfs_filestream_pick_ag.patch > queue-6.6/xfs-merge-xfs_attr_leaf_try_add-into-xfs_attr_leaf_addname.patch > queue-6.6/xfs-don-t-free-cowblocks-from-under-dirty-pagecache-on-unshare.patch > queue-6.6/xfs-pass-the-exact-range-to-initialize-to-xfs_initialize_perag.patch > queue-6.6/xfs-assert-a-valid-limit-in-xfs_rtfind_forw.patch > queue-6.6/xfs-don-t-use-__gfp_retry_mayfail-in-xfs_initialize_perag.patch > queue-6.6/xfs-use-try_cmpxchg-in-xlog_cil_insert_pcp_aggregate.patch > queue-6.6/xfs-don-t-ifdef-around-the-exact-minlen-allocations.patch > queue-6.6/xfs-reduce-unnecessary-searches-when-searching-for-the-best-extents.patch > queue-6.6/xfs-validate-inumber-in-xfs_iget.patch > queue-6.6/xfs-support-lowmode-allocations-in-xfs_bmap_exact_minlen_extent_alloc.patch > queue-6.6/xfs-skip-background-cowblock-trims-on-inodes-open-for-write.patch > queue-6.6/xfs-remove-empty-declartion-in-header-file.patch > queue-6.6/xfs-fold-xfs_bmap_alloc_userdata-into-xfs_bmapi_allocate.patch > queue-6.6/xfs-update-the-file-system-geometry-after-recoverying-superblock-buffers.patch > queue-6.6/xfs-call-xfs_bmap_exact_minlen_extent_alloc-from-xfs_bmap_btalloc.patch > queue-6.6/xfs-distinguish-extra-split-from-real-enospc-from-xfs_attr_node_try_addname.patch > queue-6.6/xfs-error-out-when-a-superblock-buffer-update-reduces-the-agcount.patch > queue-6.6/xfs-update-the-pag-for-the-last-ag-at-recovery-time.patch > queue-6.6/xfs-check-for-delayed-allocations-before-setting-extsize.patch > queue-6.6/xfs-fix-a-typo.patch > queue-6.6/xfs-distinguish-extra-split-from-real-enospc-from-xfs_attr3_leaf_split.patch