sbitmap: don't update the allocation hint on clear after resize
authorOmar Sandoval <osandov@fb.com>
Sat, 17 Sep 2016 19:20:54 +0000 (12:20 -0700)
committerJens Axboe <axboe@fb.com>
Sat, 17 Sep 2016 19:39:06 +0000 (13:39 -0600)
If we have a bunch of high-numbered bits allocated and then we resize
the struct sbitmap_queue, when those bits get cleared, we'll update the
hint and then have to re-randomize it repeatedly. Avoid that by checking
that the cleared bit is still a valid hint. No measurable performance
difference in the common case.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
lib/sbitmap.c

index f736c52a712c060e8ec41f3b00392267f5b9f88a..e408089215445c2d590960b4e4e10a0040ab9864 100644 (file)
@@ -321,7 +321,7 @@ void sbitmap_queue_clear(struct sbitmap_queue *sbq, unsigned int nr,
 {
        sbitmap_clear_bit(&sbq->sb, nr);
        sbq_wake_up(sbq);
-       if (likely(!sbq->round_robin))
+       if (likely(!sbq->round_robin && nr < sbq->sb.depth))
                *per_cpu_ptr(sbq->alloc_hint, cpu) = nr;
 }
 EXPORT_SYMBOL_GPL(sbitmap_queue_clear);