mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:41:42 +00:00
xfs: Use try_cmpxchg() in xlog_cil_insert_pcp_aggregate()
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>
This commit is contained in:
parent
6148b77960
commit
20195d011c
@ -156,7 +156,6 @@ xlog_cil_insert_pcp_aggregate(
|
|||||||
struct xfs_cil *cil,
|
struct xfs_cil *cil,
|
||||||
struct xfs_cil_ctx *ctx)
|
struct xfs_cil_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct xlog_cil_pcp *cilpcp;
|
|
||||||
int cpu;
|
int cpu;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
@ -171,13 +170,11 @@ xlog_cil_insert_pcp_aggregate(
|
|||||||
* structures that could have a nonzero space_used.
|
* structures that could have a nonzero space_used.
|
||||||
*/
|
*/
|
||||||
for_each_cpu(cpu, &ctx->cil_pcpmask) {
|
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);
|
while (!try_cmpxchg(&cilpcp->space_used, &old, 0))
|
||||||
do {
|
;
|
||||||
old = cilpcp->space_used;
|
|
||||||
prev = cmpxchg(&cilpcp->space_used, old, 0);
|
|
||||||
} while (old != prev);
|
|
||||||
count += old;
|
count += old;
|
||||||
}
|
}
|
||||||
atomic_add(count, &ctx->space_used);
|
atomic_add(count, &ctx->space_used);
|
||||||
|
Loading…
Reference in New Issue
Block a user