Skip to content

Commit 3265cdc

Browse files
committed
sbitmap: Use atomic_long_try_cmpxchg in __sbitmap_queue_get_batch
jira LE-4066 Rebuild_History Non-Buildable kernel-4.18.0-553.72.1.el8_10 commit-author Uros Bizjak <ubizjak@gmail.com> commit c35227d Use atomic_long_try_cmpxchg instead of atomic_long_cmpxchg (*ptr, old, new) == old in __sbitmap_queue_get_batch. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). Also, atomic_long_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg fails, enabling further code simplifications, e.g. an extra memory read can be avoided in the loop. No functional change intended. Cc: Jens Axboe <axboe@kernel.dk> Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Link: https://lore.kernel.org/r/20220908151200.9993-1-ubizjak@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk> (cherry picked from commit c35227d) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 2b02c21 commit 3265cdc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/sbitmap.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,16 +532,16 @@ unsigned long __sbitmap_queue_get_batch(struct sbitmap_queue *sbq, int nr_tags,
532532
nr = find_first_zero_bit(&map->word, map_depth);
533533
if (nr + nr_tags <= map_depth) {
534534
atomic_long_t *ptr = (atomic_long_t *) &map->word;
535-
unsigned long val, ret;
535+
unsigned long val;
536536

537537
get_mask = ((1UL << nr_tags) - 1) << nr;
538+
val = READ_ONCE(map->word);
538539
do {
539-
val = READ_ONCE(map->word);
540540
if ((val & ~get_mask) != val)
541541
goto next;
542-
ret = atomic_long_cmpxchg(ptr, val, get_mask | val);
543-
} while (ret != val);
544-
get_mask = (get_mask & ~ret) >> nr;
542+
} while (!atomic_long_try_cmpxchg(ptr, &val,
543+
get_mask | val));
544+
get_mask = (get_mask & ~val) >> nr;
545545
if (get_mask) {
546546
*offset = nr + (index << sb->shift);
547547
update_alloc_hint_after_get(sb, depth, hint,

0 commit comments

Comments
 (0)