aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sbitmap.c
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2016-09-17 01:28:26 -0700
committerJens Axboe <axboe@fb.com>2016-09-17 08:39:16 -0600
commit05fd095d53b979878f016c3a7080d3683cc89d72 (patch)
tree93751c669d2cba783d4762127efa949ad4bda5f9 /lib/sbitmap.c
parent98d95416dbfaf4910caadfb4ddc75e4aacbdff8c (diff)
downloadnet-05fd095d53b979878f016c3a7080d3683cc89d72.tar.gz
sbitmap: re-initialize allocation hints after resize
After a struct sbitmap_queue is resized smaller, the allocation hints may still be set to bits beyond the new depth of the bitmap. This means that, for example, if the number of blk-mq tags is reduced through sysfs, more requests than the nominal queue depth may be in flight. It's tempting to fix this at resize time by doing a one-time reinitialization of the hints, but this can race with __sbitmap_queue_get() updating the hint. Instead, check the hint before we use it. This caused no measurable performance difference in my synthetic benchmarks. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'lib/sbitmap.c')
-rw-r--r--lib/sbitmap.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index 928b82a733f2cc..f736c52a712c06 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -246,10 +246,15 @@ EXPORT_SYMBOL_GPL(sbitmap_queue_resize);
int __sbitmap_queue_get(struct sbitmap_queue *sbq)
{
- unsigned int hint;
+ unsigned int hint, depth;
int nr;
hint = this_cpu_read(*sbq->alloc_hint);
+ depth = READ_ONCE(sbq->sb.depth);
+ if (unlikely(hint >= depth)) {
+ hint = depth ? prandom_u32() % depth : 0;
+ this_cpu_write(*sbq->alloc_hint, hint);
+ }
nr = sbitmap_get(&sbq->sb, hint, sbq->round_robin);
if (nr == -1) {
@@ -258,7 +263,7 @@ int __sbitmap_queue_get(struct sbitmap_queue *sbq)
} else if (nr == hint || unlikely(sbq->round_robin)) {
/* Only update the hint if we used it. */
hint = nr + 1;
- if (hint >= sbq->sb.depth - 1)
+ if (hint >= depth - 1)
hint = 0;
this_cpu_write(*sbq->alloc_hint, hint);
}
/core61-58 Intel wireless group's fork of linux.gitIntel wireless group
aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorXi Wang <xi.wang@gmail.com>2013-02-27 17:05:21 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-03-04 06:03:36 +0800
commit603e070fed3c15250c98b5de8af1db0f0647ff3c (patch)
tree08d3489213e4fb3eb726f2e508427172bb7dbfa7 /kernel
parentfd9471ef7e6ee38a7f29f5556928ddf4824f8bdd (diff)
downloadchromeos-603e070fed3c15250c98b5de8af1db0f0647ff3c.tar.gz
sysctl: fix null checking in bin_dn_node_address()
commit df1778be1a33edffa51d094eeda87c858ded6560 upstream. The null check of `strchr() + 1' is broken, which is always non-null, leading to OOB read. Instead, check the result of strchr(). Signed-off-by: Xi Wang <xi.wang@gmail.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>