We don't need to use READ_ONCE() to read the map depth and word
fields. This reduces overhead of __sbitmap_queue_get() dramatically
on high IOPS devices, taking it from ~3% to a tenth of that.

Signed-off-by: Jens Axboe <[email protected]>
---
 lib/sbitmap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index fdd1b8aa8ac6..77442e04aeac 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -243,8 +243,8 @@ void sbitmap_bitmap_show(struct sbitmap *sb, struct 
seq_file *m)
        int i;
 
        for (i = 0; i < sb->map_nr; i++) {
-               unsigned long word = READ_ONCE(sb->map[i].word);
-               unsigned int word_bits = READ_ONCE(sb->map[i].depth);
+               unsigned long word = sb->map[i].word;
+               unsigned int word_bits = sb->map[i].depth;
 
                while (word_bits > 0) {
                        unsigned int bits = min(8 - byte_bits, word_bits);
@@ -375,7 +375,7 @@ int __sbitmap_queue_get(struct sbitmap_queue *sbq)
        int nr;
 
        hint = this_cpu_read(*sbq->alloc_hint);
-       depth = READ_ONCE(sbq->sb.depth);
+       depth = sbq->sb.depth;
        if (unlikely(hint >= depth)) {
                hint = depth ? prandom_u32() % depth : 0;
                this_cpu_write(*sbq->alloc_hint, hint);
@@ -406,7 +406,7 @@ int __sbitmap_queue_get_shallow(struct sbitmap_queue *sbq,
        WARN_ON_ONCE(shallow_depth < sbq->min_shallow_depth);
 
        hint = this_cpu_read(*sbq->alloc_hint);
-       depth = READ_ONCE(sbq->sb.depth);
+       depth = sbq->sb.depth;
        if (unlikely(hint >= depth)) {
                hint = depth ? prandom_u32() % depth : 0;
                this_cpu_write(*sbq->alloc_hint, hint);
-- 
2.17.1

-- 
Jens Axboe

Reply via email to