Thomas Gleixner | 0fc479b | 2019-05-29 16:57:42 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Facebook |
| 4 | * Copyright (C) 2013-2014 Jens Axboe |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Ingo Molnar | af8601a | 2017-02-03 09:57:00 +0100 | [diff] [blame] | 7 | #include <linux/sched.h> |
Omar Sandoval | 98d9541 | 2016-09-17 01:28:25 -0700 | [diff] [blame] | 8 | #include <linux/random.h> |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 9 | #include <linux/sbitmap.h> |
Omar Sandoval | 24af1ccf | 2017-01-25 14:32:13 -0800 | [diff] [blame] | 10 | #include <linux/seq_file.h> |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 11 | |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 12 | /* |
| 13 | * See if we have deferred clears that we can batch move |
| 14 | */ |
Pavel Begunkov | b78beea | 2020-11-22 15:35:45 +0000 | [diff] [blame] | 15 | static inline bool sbitmap_deferred_clear(struct sbitmap_word *map) |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 16 | { |
Pavel Begunkov | c3250c8 | 2020-11-22 15:35:47 +0000 | [diff] [blame] | 17 | unsigned long mask; |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 18 | |
Pavel Begunkov | 661d4f5 | 2020-11-22 15:35:46 +0000 | [diff] [blame] | 19 | if (!READ_ONCE(map->cleared)) |
| 20 | return false; |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * First get a stable cleared mask, setting the old mask to 0. |
| 24 | */ |
Pavel Begunkov | b78beea | 2020-11-22 15:35:45 +0000 | [diff] [blame] | 25 | mask = xchg(&map->cleared, 0); |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Now clear the masked bits in our free word |
| 29 | */ |
Pavel Begunkov | c3250c8 | 2020-11-22 15:35:47 +0000 | [diff] [blame] | 30 | atomic_long_andnot(mask, (atomic_long_t *)&map->word); |
| 31 | BUILD_BUG_ON(sizeof(atomic_long_t) != sizeof(map->word)); |
Pavel Begunkov | 661d4f5 | 2020-11-22 15:35:46 +0000 | [diff] [blame] | 32 | return true; |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 35 | int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift, |
| 36 | gfp_t flags, int node) |
| 37 | { |
| 38 | unsigned int bits_per_word; |
| 39 | unsigned int i; |
| 40 | |
| 41 | if (shift < 0) { |
| 42 | shift = ilog2(BITS_PER_LONG); |
| 43 | /* |
| 44 | * If the bitmap is small, shrink the number of bits per word so |
| 45 | * we spread over a few cachelines, at least. If less than 4 |
| 46 | * bits, just forget about it, it's not going to work optimally |
| 47 | * anyway. |
| 48 | */ |
| 49 | if (depth >= 4) { |
| 50 | while ((4U << shift) > depth) |
| 51 | shift--; |
| 52 | } |
| 53 | } |
| 54 | bits_per_word = 1U << shift; |
| 55 | if (bits_per_word > BITS_PER_LONG) |
| 56 | return -EINVAL; |
| 57 | |
| 58 | sb->shift = shift; |
| 59 | sb->depth = depth; |
| 60 | sb->map_nr = DIV_ROUND_UP(sb->depth, bits_per_word); |
| 61 | |
| 62 | if (depth == 0) { |
| 63 | sb->map = NULL; |
| 64 | return 0; |
| 65 | } |
| 66 | |
Kees Cook | 590b5b7 | 2018-06-12 14:04:20 -0700 | [diff] [blame] | 67 | sb->map = kcalloc_node(sb->map_nr, sizeof(*sb->map), flags, node); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 68 | if (!sb->map) |
| 69 | return -ENOMEM; |
| 70 | |
| 71 | for (i = 0; i < sb->map_nr; i++) { |
| 72 | sb->map[i].depth = min(depth, bits_per_word); |
| 73 | depth -= sb->map[i].depth; |
| 74 | } |
| 75 | return 0; |
| 76 | } |
| 77 | EXPORT_SYMBOL_GPL(sbitmap_init_node); |
| 78 | |
| 79 | void sbitmap_resize(struct sbitmap *sb, unsigned int depth) |
| 80 | { |
| 81 | unsigned int bits_per_word = 1U << sb->shift; |
| 82 | unsigned int i; |
| 83 | |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 84 | for (i = 0; i < sb->map_nr; i++) |
Pavel Begunkov | b78beea | 2020-11-22 15:35:45 +0000 | [diff] [blame] | 85 | sbitmap_deferred_clear(&sb->map[i]); |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 86 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 87 | sb->depth = depth; |
| 88 | sb->map_nr = DIV_ROUND_UP(sb->depth, bits_per_word); |
| 89 | |
| 90 | for (i = 0; i < sb->map_nr; i++) { |
| 91 | sb->map[i].depth = min(depth, bits_per_word); |
| 92 | depth -= sb->map[i].depth; |
| 93 | } |
| 94 | } |
| 95 | EXPORT_SYMBOL_GPL(sbitmap_resize); |
| 96 | |
Omar Sandoval | c05e667 | 2017-04-14 00:59:58 -0700 | [diff] [blame] | 97 | static int __sbitmap_get_word(unsigned long *word, unsigned long depth, |
| 98 | unsigned int hint, bool wrap) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 99 | { |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 100 | int nr; |
| 101 | |
Pavel Begunkov | 0eff1f1 | 2020-11-22 15:35:48 +0000 | [diff] [blame] | 102 | /* don't wrap if starting from 0 */ |
| 103 | wrap = wrap && hint; |
| 104 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 105 | while (1) { |
Omar Sandoval | c05e667 | 2017-04-14 00:59:58 -0700 | [diff] [blame] | 106 | nr = find_next_zero_bit(word, depth, hint); |
| 107 | if (unlikely(nr >= depth)) { |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 108 | /* |
| 109 | * We started with an offset, and we didn't reset the |
| 110 | * offset to 0 in a failure case, so start from 0 to |
| 111 | * exhaust the map. |
| 112 | */ |
Pavel Begunkov | 0eff1f1 | 2020-11-22 15:35:48 +0000 | [diff] [blame] | 113 | if (hint && wrap) { |
| 114 | hint = 0; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 115 | continue; |
| 116 | } |
| 117 | return -1; |
| 118 | } |
| 119 | |
Omar Sandoval | 4ace53f | 2018-02-27 16:56:43 -0800 | [diff] [blame] | 120 | if (!test_and_set_bit_lock(nr, word)) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 121 | break; |
| 122 | |
| 123 | hint = nr + 1; |
Omar Sandoval | c05e667 | 2017-04-14 00:59:58 -0700 | [diff] [blame] | 124 | if (hint >= depth - 1) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 125 | hint = 0; |
| 126 | } |
| 127 | |
| 128 | return nr; |
| 129 | } |
| 130 | |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 131 | static int sbitmap_find_bit_in_index(struct sbitmap *sb, int index, |
| 132 | unsigned int alloc_hint, bool round_robin) |
| 133 | { |
Pavel Begunkov | b78beea | 2020-11-22 15:35:45 +0000 | [diff] [blame] | 134 | struct sbitmap_word *map = &sb->map[index]; |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 135 | int nr; |
| 136 | |
| 137 | do { |
Pavel Begunkov | b78beea | 2020-11-22 15:35:45 +0000 | [diff] [blame] | 138 | nr = __sbitmap_get_word(&map->word, map->depth, alloc_hint, |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 139 | !round_robin); |
| 140 | if (nr != -1) |
| 141 | break; |
Pavel Begunkov | b78beea | 2020-11-22 15:35:45 +0000 | [diff] [blame] | 142 | if (!sbitmap_deferred_clear(map)) |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 143 | break; |
| 144 | } while (1); |
| 145 | |
| 146 | return nr; |
| 147 | } |
| 148 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 149 | int sbitmap_get(struct sbitmap *sb, unsigned int alloc_hint, bool round_robin) |
| 150 | { |
| 151 | unsigned int i, index; |
| 152 | int nr = -1; |
| 153 | |
| 154 | index = SB_NR_TO_INDEX(sb, alloc_hint); |
| 155 | |
Jens Axboe | 27fae42 | 2018-11-29 12:35:16 -0700 | [diff] [blame] | 156 | /* |
| 157 | * Unless we're doing round robin tag allocation, just use the |
| 158 | * alloc_hint to find the right word index. No point in looping |
| 159 | * twice in find_next_zero_bit() for that case. |
| 160 | */ |
| 161 | if (round_robin) |
| 162 | alloc_hint = SB_NR_TO_BIT(sb, alloc_hint); |
| 163 | else |
| 164 | alloc_hint = 0; |
| 165 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 166 | for (i = 0; i < sb->map_nr; i++) { |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 167 | nr = sbitmap_find_bit_in_index(sb, index, alloc_hint, |
| 168 | round_robin); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 169 | if (nr != -1) { |
| 170 | nr += index << sb->shift; |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | /* Jump to next index. */ |
Jens Axboe | 27fae42 | 2018-11-29 12:35:16 -0700 | [diff] [blame] | 175 | alloc_hint = 0; |
| 176 | if (++index >= sb->map_nr) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 177 | index = 0; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | return nr; |
| 181 | } |
| 182 | EXPORT_SYMBOL_GPL(sbitmap_get); |
| 183 | |
Omar Sandoval | c05e667 | 2017-04-14 00:59:58 -0700 | [diff] [blame] | 184 | int sbitmap_get_shallow(struct sbitmap *sb, unsigned int alloc_hint, |
| 185 | unsigned long shallow_depth) |
| 186 | { |
| 187 | unsigned int i, index; |
| 188 | int nr = -1; |
| 189 | |
| 190 | index = SB_NR_TO_INDEX(sb, alloc_hint); |
| 191 | |
| 192 | for (i = 0; i < sb->map_nr; i++) { |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 193 | again: |
Omar Sandoval | c05e667 | 2017-04-14 00:59:58 -0700 | [diff] [blame] | 194 | nr = __sbitmap_get_word(&sb->map[index].word, |
| 195 | min(sb->map[index].depth, shallow_depth), |
| 196 | SB_NR_TO_BIT(sb, alloc_hint), true); |
| 197 | if (nr != -1) { |
| 198 | nr += index << sb->shift; |
| 199 | break; |
| 200 | } |
| 201 | |
Pavel Begunkov | b78beea | 2020-11-22 15:35:45 +0000 | [diff] [blame] | 202 | if (sbitmap_deferred_clear(&sb->map[index])) |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 203 | goto again; |
| 204 | |
Omar Sandoval | c05e667 | 2017-04-14 00:59:58 -0700 | [diff] [blame] | 205 | /* Jump to next index. */ |
| 206 | index++; |
| 207 | alloc_hint = index << sb->shift; |
| 208 | |
| 209 | if (index >= sb->map_nr) { |
| 210 | index = 0; |
| 211 | alloc_hint = 0; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return nr; |
| 216 | } |
| 217 | EXPORT_SYMBOL_GPL(sbitmap_get_shallow); |
| 218 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 219 | bool sbitmap_any_bit_set(const struct sbitmap *sb) |
| 220 | { |
| 221 | unsigned int i; |
| 222 | |
| 223 | for (i = 0; i < sb->map_nr; i++) { |
Jens Axboe | b2dbff1 | 2018-12-11 18:39:41 -0700 | [diff] [blame] | 224 | if (sb->map[i].word & ~sb->map[i].cleared) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 225 | return true; |
| 226 | } |
| 227 | return false; |
| 228 | } |
| 229 | EXPORT_SYMBOL_GPL(sbitmap_any_bit_set); |
| 230 | |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 231 | static unsigned int __sbitmap_weight(const struct sbitmap *sb, bool set) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 232 | { |
Colin Ian King | 60658e0 | 2016-09-19 14:34:08 +0100 | [diff] [blame] | 233 | unsigned int i, weight = 0; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 234 | |
| 235 | for (i = 0; i < sb->map_nr; i++) { |
| 236 | const struct sbitmap_word *word = &sb->map[i]; |
| 237 | |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 238 | if (set) |
| 239 | weight += bitmap_weight(&word->word, word->depth); |
| 240 | else |
| 241 | weight += bitmap_weight(&word->cleared, word->depth); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 242 | } |
| 243 | return weight; |
| 244 | } |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 245 | |
| 246 | static unsigned int sbitmap_weight(const struct sbitmap *sb) |
| 247 | { |
| 248 | return __sbitmap_weight(sb, true); |
| 249 | } |
| 250 | |
| 251 | static unsigned int sbitmap_cleared(const struct sbitmap *sb) |
| 252 | { |
| 253 | return __sbitmap_weight(sb, false); |
| 254 | } |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 255 | |
Omar Sandoval | 24af1ccf | 2017-01-25 14:32:13 -0800 | [diff] [blame] | 256 | void sbitmap_show(struct sbitmap *sb, struct seq_file *m) |
| 257 | { |
| 258 | seq_printf(m, "depth=%u\n", sb->depth); |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 259 | seq_printf(m, "busy=%u\n", sbitmap_weight(sb) - sbitmap_cleared(sb)); |
| 260 | seq_printf(m, "cleared=%u\n", sbitmap_cleared(sb)); |
Omar Sandoval | 24af1ccf | 2017-01-25 14:32:13 -0800 | [diff] [blame] | 261 | seq_printf(m, "bits_per_word=%u\n", 1U << sb->shift); |
| 262 | seq_printf(m, "map_nr=%u\n", sb->map_nr); |
| 263 | } |
| 264 | EXPORT_SYMBOL_GPL(sbitmap_show); |
| 265 | |
| 266 | static inline void emit_byte(struct seq_file *m, unsigned int offset, u8 byte) |
| 267 | { |
| 268 | if ((offset & 0xf) == 0) { |
| 269 | if (offset != 0) |
| 270 | seq_putc(m, '\n'); |
| 271 | seq_printf(m, "%08x:", offset); |
| 272 | } |
| 273 | if ((offset & 0x1) == 0) |
| 274 | seq_putc(m, ' '); |
| 275 | seq_printf(m, "%02x", byte); |
| 276 | } |
| 277 | |
| 278 | void sbitmap_bitmap_show(struct sbitmap *sb, struct seq_file *m) |
| 279 | { |
| 280 | u8 byte = 0; |
| 281 | unsigned int byte_bits = 0; |
| 282 | unsigned int offset = 0; |
| 283 | int i; |
| 284 | |
| 285 | for (i = 0; i < sb->map_nr; i++) { |
| 286 | unsigned long word = READ_ONCE(sb->map[i].word); |
John Garry | 6bf0eb5 | 2020-07-01 16:06:25 +0800 | [diff] [blame] | 287 | unsigned long cleared = READ_ONCE(sb->map[i].cleared); |
Omar Sandoval | 24af1ccf | 2017-01-25 14:32:13 -0800 | [diff] [blame] | 288 | unsigned int word_bits = READ_ONCE(sb->map[i].depth); |
| 289 | |
John Garry | 6bf0eb5 | 2020-07-01 16:06:25 +0800 | [diff] [blame] | 290 | word &= ~cleared; |
| 291 | |
Omar Sandoval | 24af1ccf | 2017-01-25 14:32:13 -0800 | [diff] [blame] | 292 | while (word_bits > 0) { |
| 293 | unsigned int bits = min(8 - byte_bits, word_bits); |
| 294 | |
| 295 | byte |= (word & (BIT(bits) - 1)) << byte_bits; |
| 296 | byte_bits += bits; |
| 297 | if (byte_bits == 8) { |
| 298 | emit_byte(m, offset, byte); |
| 299 | byte = 0; |
| 300 | byte_bits = 0; |
| 301 | offset++; |
| 302 | } |
| 303 | word >>= bits; |
| 304 | word_bits -= bits; |
| 305 | } |
| 306 | } |
| 307 | if (byte_bits) { |
| 308 | emit_byte(m, offset, byte); |
| 309 | offset++; |
| 310 | } |
| 311 | if (offset) |
| 312 | seq_putc(m, '\n'); |
| 313 | } |
| 314 | EXPORT_SYMBOL_GPL(sbitmap_bitmap_show); |
| 315 | |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 316 | static unsigned int sbq_calc_wake_batch(struct sbitmap_queue *sbq, |
| 317 | unsigned int depth) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 318 | { |
| 319 | unsigned int wake_batch; |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 320 | unsigned int shallow_depth; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 321 | |
| 322 | /* |
| 323 | * For each batch, we wake up one queue. We need to make sure that our |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 324 | * batch size is small enough that the full depth of the bitmap, |
| 325 | * potentially limited by a shallow depth, is enough to wake up all of |
| 326 | * the queues. |
| 327 | * |
| 328 | * Each full word of the bitmap has bits_per_word bits, and there might |
| 329 | * be a partial word. There are depth / bits_per_word full words and |
| 330 | * depth % bits_per_word bits left over. In bitwise arithmetic: |
| 331 | * |
| 332 | * bits_per_word = 1 << shift |
| 333 | * depth / bits_per_word = depth >> shift |
| 334 | * depth % bits_per_word = depth & ((1 << shift) - 1) |
| 335 | * |
| 336 | * Each word can be limited to sbq->min_shallow_depth bits. |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 337 | */ |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 338 | shallow_depth = min(1U << sbq->sb.shift, sbq->min_shallow_depth); |
| 339 | depth = ((depth >> sbq->sb.shift) * shallow_depth + |
| 340 | min(depth & ((1U << sbq->sb.shift) - 1), shallow_depth)); |
| 341 | wake_batch = clamp_t(unsigned int, depth / SBQ_WAIT_QUEUES, 1, |
| 342 | SBQ_WAKE_BATCH); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 343 | |
| 344 | return wake_batch; |
| 345 | } |
| 346 | |
| 347 | int sbitmap_queue_init_node(struct sbitmap_queue *sbq, unsigned int depth, |
Omar Sandoval | f4a644d | 2016-09-17 01:28:24 -0700 | [diff] [blame] | 348 | int shift, bool round_robin, gfp_t flags, int node) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 349 | { |
| 350 | int ret; |
| 351 | int i; |
| 352 | |
| 353 | ret = sbitmap_init_node(&sbq->sb, depth, shift, flags, node); |
| 354 | if (ret) |
| 355 | return ret; |
| 356 | |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 357 | sbq->alloc_hint = alloc_percpu_gfp(unsigned int, flags); |
| 358 | if (!sbq->alloc_hint) { |
| 359 | sbitmap_free(&sbq->sb); |
| 360 | return -ENOMEM; |
| 361 | } |
| 362 | |
Omar Sandoval | 98d9541 | 2016-09-17 01:28:25 -0700 | [diff] [blame] | 363 | if (depth && !round_robin) { |
| 364 | for_each_possible_cpu(i) |
| 365 | *per_cpu_ptr(sbq->alloc_hint, i) = prandom_u32() % depth; |
| 366 | } |
| 367 | |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 368 | sbq->min_shallow_depth = UINT_MAX; |
| 369 | sbq->wake_batch = sbq_calc_wake_batch(sbq, depth); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 370 | atomic_set(&sbq->wake_index, 0); |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 371 | atomic_set(&sbq->ws_active, 0); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 372 | |
Omar Sandoval | 48e2816 | 2016-09-17 01:28:22 -0700 | [diff] [blame] | 373 | sbq->ws = kzalloc_node(SBQ_WAIT_QUEUES * sizeof(*sbq->ws), flags, node); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 374 | if (!sbq->ws) { |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 375 | free_percpu(sbq->alloc_hint); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 376 | sbitmap_free(&sbq->sb); |
| 377 | return -ENOMEM; |
| 378 | } |
| 379 | |
| 380 | for (i = 0; i < SBQ_WAIT_QUEUES; i++) { |
| 381 | init_waitqueue_head(&sbq->ws[i].wait); |
| 382 | atomic_set(&sbq->ws[i].wait_cnt, sbq->wake_batch); |
| 383 | } |
Omar Sandoval | f4a644d | 2016-09-17 01:28:24 -0700 | [diff] [blame] | 384 | |
| 385 | sbq->round_robin = round_robin; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 386 | return 0; |
| 387 | } |
| 388 | EXPORT_SYMBOL_GPL(sbitmap_queue_init_node); |
| 389 | |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 390 | static void sbitmap_queue_update_wake_batch(struct sbitmap_queue *sbq, |
| 391 | unsigned int depth) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 392 | { |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 393 | unsigned int wake_batch = sbq_calc_wake_batch(sbq, depth); |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 394 | int i; |
| 395 | |
| 396 | if (sbq->wake_batch != wake_batch) { |
| 397 | WRITE_ONCE(sbq->wake_batch, wake_batch); |
| 398 | /* |
Ming Lei | e6fc464 | 2018-05-24 11:00:39 -0600 | [diff] [blame] | 399 | * Pairs with the memory barrier in sbitmap_queue_wake_up() |
| 400 | * to ensure that the batch size is updated before the wait |
| 401 | * counts. |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 402 | */ |
Andrea Parri | a0934fd | 2019-05-20 19:23:57 +0200 | [diff] [blame] | 403 | smp_mb(); |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 404 | for (i = 0; i < SBQ_WAIT_QUEUES; i++) |
| 405 | atomic_set(&sbq->ws[i].wait_cnt, 1); |
| 406 | } |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void sbitmap_queue_resize(struct sbitmap_queue *sbq, unsigned int depth) |
| 410 | { |
| 411 | sbitmap_queue_update_wake_batch(sbq, depth); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 412 | sbitmap_resize(&sbq->sb, depth); |
| 413 | } |
| 414 | EXPORT_SYMBOL_GPL(sbitmap_queue_resize); |
| 415 | |
Omar Sandoval | f4a644d | 2016-09-17 01:28:24 -0700 | [diff] [blame] | 416 | int __sbitmap_queue_get(struct sbitmap_queue *sbq) |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 417 | { |
Omar Sandoval | 05fd095 | 2016-09-17 01:28:26 -0700 | [diff] [blame] | 418 | unsigned int hint, depth; |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 419 | int nr; |
| 420 | |
| 421 | hint = this_cpu_read(*sbq->alloc_hint); |
Omar Sandoval | 05fd095 | 2016-09-17 01:28:26 -0700 | [diff] [blame] | 422 | depth = READ_ONCE(sbq->sb.depth); |
| 423 | if (unlikely(hint >= depth)) { |
| 424 | hint = depth ? prandom_u32() % depth : 0; |
| 425 | this_cpu_write(*sbq->alloc_hint, hint); |
| 426 | } |
Omar Sandoval | f4a644d | 2016-09-17 01:28:24 -0700 | [diff] [blame] | 427 | nr = sbitmap_get(&sbq->sb, hint, sbq->round_robin); |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 428 | |
| 429 | if (nr == -1) { |
| 430 | /* If the map is full, a hint won't do us much good. */ |
| 431 | this_cpu_write(*sbq->alloc_hint, 0); |
Omar Sandoval | f4a644d | 2016-09-17 01:28:24 -0700 | [diff] [blame] | 432 | } else if (nr == hint || unlikely(sbq->round_robin)) { |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 433 | /* Only update the hint if we used it. */ |
| 434 | hint = nr + 1; |
Omar Sandoval | 05fd095 | 2016-09-17 01:28:26 -0700 | [diff] [blame] | 435 | if (hint >= depth - 1) |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 436 | hint = 0; |
| 437 | this_cpu_write(*sbq->alloc_hint, hint); |
| 438 | } |
| 439 | |
| 440 | return nr; |
| 441 | } |
| 442 | EXPORT_SYMBOL_GPL(__sbitmap_queue_get); |
| 443 | |
Omar Sandoval | c05e667 | 2017-04-14 00:59:58 -0700 | [diff] [blame] | 444 | int __sbitmap_queue_get_shallow(struct sbitmap_queue *sbq, |
| 445 | unsigned int shallow_depth) |
| 446 | { |
| 447 | unsigned int hint, depth; |
| 448 | int nr; |
| 449 | |
Omar Sandoval | 61445b56 | 2018-05-09 17:29:24 -0700 | [diff] [blame] | 450 | WARN_ON_ONCE(shallow_depth < sbq->min_shallow_depth); |
| 451 | |
Omar Sandoval | c05e667 | 2017-04-14 00:59:58 -0700 | [diff] [blame] | 452 | hint = this_cpu_read(*sbq->alloc_hint); |
| 453 | depth = READ_ONCE(sbq->sb.depth); |
| 454 | if (unlikely(hint >= depth)) { |
| 455 | hint = depth ? prandom_u32() % depth : 0; |
| 456 | this_cpu_write(*sbq->alloc_hint, hint); |
| 457 | } |
| 458 | nr = sbitmap_get_shallow(&sbq->sb, hint, shallow_depth); |
| 459 | |
| 460 | if (nr == -1) { |
| 461 | /* If the map is full, a hint won't do us much good. */ |
| 462 | this_cpu_write(*sbq->alloc_hint, 0); |
| 463 | } else if (nr == hint || unlikely(sbq->round_robin)) { |
| 464 | /* Only update the hint if we used it. */ |
| 465 | hint = nr + 1; |
| 466 | if (hint >= depth - 1) |
| 467 | hint = 0; |
| 468 | this_cpu_write(*sbq->alloc_hint, hint); |
| 469 | } |
| 470 | |
| 471 | return nr; |
| 472 | } |
| 473 | EXPORT_SYMBOL_GPL(__sbitmap_queue_get_shallow); |
| 474 | |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 475 | void sbitmap_queue_min_shallow_depth(struct sbitmap_queue *sbq, |
| 476 | unsigned int min_shallow_depth) |
| 477 | { |
| 478 | sbq->min_shallow_depth = min_shallow_depth; |
| 479 | sbitmap_queue_update_wake_batch(sbq, sbq->sb.depth); |
| 480 | } |
| 481 | EXPORT_SYMBOL_GPL(sbitmap_queue_min_shallow_depth); |
| 482 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 483 | static struct sbq_wait_state *sbq_wake_ptr(struct sbitmap_queue *sbq) |
| 484 | { |
| 485 | int i, wake_index; |
| 486 | |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 487 | if (!atomic_read(&sbq->ws_active)) |
| 488 | return NULL; |
| 489 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 490 | wake_index = atomic_read(&sbq->wake_index); |
| 491 | for (i = 0; i < SBQ_WAIT_QUEUES; i++) { |
| 492 | struct sbq_wait_state *ws = &sbq->ws[wake_index]; |
| 493 | |
| 494 | if (waitqueue_active(&ws->wait)) { |
Pavel Begunkov | 4172328 | 2019-05-23 18:39:16 +0300 | [diff] [blame] | 495 | if (wake_index != atomic_read(&sbq->wake_index)) |
| 496 | atomic_set(&sbq->wake_index, wake_index); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 497 | return ws; |
| 498 | } |
| 499 | |
| 500 | wake_index = sbq_index_inc(wake_index); |
| 501 | } |
| 502 | |
| 503 | return NULL; |
| 504 | } |
| 505 | |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 506 | static bool __sbq_wake_up(struct sbitmap_queue *sbq) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 507 | { |
| 508 | struct sbq_wait_state *ws; |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 509 | unsigned int wake_batch; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 510 | int wait_cnt; |
| 511 | |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 512 | ws = sbq_wake_ptr(sbq); |
| 513 | if (!ws) |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 514 | return false; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 515 | |
| 516 | wait_cnt = atomic_dec_return(&ws->wait_cnt); |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 517 | if (wait_cnt <= 0) { |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 518 | int ret; |
| 519 | |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 520 | wake_batch = READ_ONCE(sbq->wake_batch); |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 521 | |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 522 | /* |
| 523 | * Pairs with the memory barrier in sbitmap_queue_resize() to |
| 524 | * ensure that we see the batch size update before the wait |
| 525 | * count is reset. |
| 526 | */ |
| 527 | smp_mb__before_atomic(); |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 528 | |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 529 | /* |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 530 | * For concurrent callers of this, the one that failed the |
| 531 | * atomic_cmpxhcg() race should call this function again |
| 532 | * to wakeup a new batch on a different 'ws'. |
Omar Sandoval | 6c0ca7a | 2017-01-18 11:55:22 -0800 | [diff] [blame] | 533 | */ |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 534 | ret = atomic_cmpxchg(&ws->wait_cnt, wait_cnt, wake_batch); |
| 535 | if (ret == wait_cnt) { |
| 536 | sbq_index_atomic_inc(&sbq->wake_index); |
| 537 | wake_up_nr(&ws->wait, wake_batch); |
| 538 | return false; |
| 539 | } |
| 540 | |
| 541 | return true; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 542 | } |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 543 | |
| 544 | return false; |
| 545 | } |
| 546 | |
Ming Lei | e6fc464 | 2018-05-24 11:00:39 -0600 | [diff] [blame] | 547 | void sbitmap_queue_wake_up(struct sbitmap_queue *sbq) |
Jens Axboe | c854ab5 | 2018-05-14 12:17:31 -0600 | [diff] [blame] | 548 | { |
| 549 | while (__sbq_wake_up(sbq)) |
| 550 | ; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 551 | } |
Ming Lei | e6fc464 | 2018-05-24 11:00:39 -0600 | [diff] [blame] | 552 | EXPORT_SYMBOL_GPL(sbitmap_queue_wake_up); |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 553 | |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 554 | void sbitmap_queue_clear(struct sbitmap_queue *sbq, unsigned int nr, |
Omar Sandoval | f4a644d | 2016-09-17 01:28:24 -0700 | [diff] [blame] | 555 | unsigned int cpu) |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 556 | { |
Ming Lei | e6d1fa5 | 2019-03-22 09:13:51 +0800 | [diff] [blame] | 557 | /* |
| 558 | * Once the clear bit is set, the bit may be allocated out. |
| 559 | * |
| 560 | * Orders READ/WRITE on the asssociated instance(such as request |
| 561 | * of blk_mq) by this bit for avoiding race with re-allocation, |
| 562 | * and its pair is the memory barrier implied in __sbitmap_get_word. |
| 563 | * |
| 564 | * One invariant is that the clear bit has to be zero when the bit |
| 565 | * is in use. |
| 566 | */ |
| 567 | smp_mb__before_atomic(); |
Jens Axboe | ea86ea2 | 2018-11-30 13:18:06 -0700 | [diff] [blame] | 568 | sbitmap_deferred_clear_bit(&sbq->sb, nr); |
| 569 | |
Ming Lei | e6fc464 | 2018-05-24 11:00:39 -0600 | [diff] [blame] | 570 | /* |
| 571 | * Pairs with the memory barrier in set_current_state() to ensure the |
| 572 | * proper ordering of clear_bit_unlock()/waitqueue_active() in the waker |
| 573 | * and test_and_set_bit_lock()/prepare_to_wait()/finish_wait() in the |
| 574 | * waiter. See the comment on waitqueue_active(). |
| 575 | */ |
| 576 | smp_mb__after_atomic(); |
| 577 | sbitmap_queue_wake_up(sbq); |
| 578 | |
Omar Sandoval | 5c64a8d | 2016-09-17 12:20:54 -0700 | [diff] [blame] | 579 | if (likely(!sbq->round_robin && nr < sbq->sb.depth)) |
Omar Sandoval | 40aabb6 | 2016-09-17 01:28:23 -0700 | [diff] [blame] | 580 | *per_cpu_ptr(sbq->alloc_hint, cpu) = nr; |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 581 | } |
| 582 | EXPORT_SYMBOL_GPL(sbitmap_queue_clear); |
| 583 | |
| 584 | void sbitmap_queue_wake_all(struct sbitmap_queue *sbq) |
| 585 | { |
| 586 | int i, wake_index; |
| 587 | |
| 588 | /* |
Omar Sandoval | f66227d | 2017-01-18 11:55:21 -0800 | [diff] [blame] | 589 | * Pairs with the memory barrier in set_current_state() like in |
Ming Lei | e6fc464 | 2018-05-24 11:00:39 -0600 | [diff] [blame] | 590 | * sbitmap_queue_wake_up(). |
Omar Sandoval | 8845964 | 2016-09-17 08:38:44 -0600 | [diff] [blame] | 591 | */ |
| 592 | smp_mb(); |
| 593 | wake_index = atomic_read(&sbq->wake_index); |
| 594 | for (i = 0; i < SBQ_WAIT_QUEUES; i++) { |
| 595 | struct sbq_wait_state *ws = &sbq->ws[wake_index]; |
| 596 | |
| 597 | if (waitqueue_active(&ws->wait)) |
| 598 | wake_up(&ws->wait); |
| 599 | |
| 600 | wake_index = sbq_index_inc(wake_index); |
| 601 | } |
| 602 | } |
| 603 | EXPORT_SYMBOL_GPL(sbitmap_queue_wake_all); |
Omar Sandoval | 24af1ccf | 2017-01-25 14:32:13 -0800 | [diff] [blame] | 604 | |
| 605 | void sbitmap_queue_show(struct sbitmap_queue *sbq, struct seq_file *m) |
| 606 | { |
| 607 | bool first; |
| 608 | int i; |
| 609 | |
| 610 | sbitmap_show(&sbq->sb, m); |
| 611 | |
| 612 | seq_puts(m, "alloc_hint={"); |
| 613 | first = true; |
| 614 | for_each_possible_cpu(i) { |
| 615 | if (!first) |
| 616 | seq_puts(m, ", "); |
| 617 | first = false; |
| 618 | seq_printf(m, "%u", *per_cpu_ptr(sbq->alloc_hint, i)); |
| 619 | } |
| 620 | seq_puts(m, "}\n"); |
| 621 | |
| 622 | seq_printf(m, "wake_batch=%u\n", sbq->wake_batch); |
| 623 | seq_printf(m, "wake_index=%d\n", atomic_read(&sbq->wake_index)); |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 624 | seq_printf(m, "ws_active=%d\n", atomic_read(&sbq->ws_active)); |
Omar Sandoval | 24af1ccf | 2017-01-25 14:32:13 -0800 | [diff] [blame] | 625 | |
| 626 | seq_puts(m, "ws={\n"); |
| 627 | for (i = 0; i < SBQ_WAIT_QUEUES; i++) { |
| 628 | struct sbq_wait_state *ws = &sbq->ws[i]; |
| 629 | |
| 630 | seq_printf(m, "\t{.wait_cnt=%d, .wait=%s},\n", |
| 631 | atomic_read(&ws->wait_cnt), |
| 632 | waitqueue_active(&ws->wait) ? "active" : "inactive"); |
| 633 | } |
| 634 | seq_puts(m, "}\n"); |
| 635 | |
| 636 | seq_printf(m, "round_robin=%d\n", sbq->round_robin); |
Omar Sandoval | a327553 | 2018-05-09 17:16:31 -0700 | [diff] [blame] | 637 | seq_printf(m, "min_shallow_depth=%u\n", sbq->min_shallow_depth); |
Omar Sandoval | 24af1ccf | 2017-01-25 14:32:13 -0800 | [diff] [blame] | 638 | } |
| 639 | EXPORT_SYMBOL_GPL(sbitmap_queue_show); |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 640 | |
Jens Axboe | 9f6b7ef | 2018-12-20 08:49:00 -0700 | [diff] [blame] | 641 | void sbitmap_add_wait_queue(struct sbitmap_queue *sbq, |
| 642 | struct sbq_wait_state *ws, |
| 643 | struct sbq_wait *sbq_wait) |
| 644 | { |
| 645 | if (!sbq_wait->sbq) { |
| 646 | sbq_wait->sbq = sbq; |
| 647 | atomic_inc(&sbq->ws_active); |
David Jeffery | df034c9 | 2019-12-17 11:00:24 -0500 | [diff] [blame] | 648 | add_wait_queue(&ws->wait, &sbq_wait->wait); |
Jens Axboe | 9f6b7ef | 2018-12-20 08:49:00 -0700 | [diff] [blame] | 649 | } |
Jens Axboe | 9f6b7ef | 2018-12-20 08:49:00 -0700 | [diff] [blame] | 650 | } |
| 651 | EXPORT_SYMBOL_GPL(sbitmap_add_wait_queue); |
| 652 | |
| 653 | void sbitmap_del_wait_queue(struct sbq_wait *sbq_wait) |
| 654 | { |
| 655 | list_del_init(&sbq_wait->wait.entry); |
| 656 | if (sbq_wait->sbq) { |
| 657 | atomic_dec(&sbq_wait->sbq->ws_active); |
| 658 | sbq_wait->sbq = NULL; |
| 659 | } |
| 660 | } |
| 661 | EXPORT_SYMBOL_GPL(sbitmap_del_wait_queue); |
| 662 | |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 663 | void sbitmap_prepare_to_wait(struct sbitmap_queue *sbq, |
| 664 | struct sbq_wait_state *ws, |
| 665 | struct sbq_wait *sbq_wait, int state) |
| 666 | { |
Jens Axboe | 9f6b7ef | 2018-12-20 08:49:00 -0700 | [diff] [blame] | 667 | if (!sbq_wait->sbq) { |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 668 | atomic_inc(&sbq->ws_active); |
Jens Axboe | 9f6b7ef | 2018-12-20 08:49:00 -0700 | [diff] [blame] | 669 | sbq_wait->sbq = sbq; |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 670 | } |
| 671 | prepare_to_wait_exclusive(&ws->wait, &sbq_wait->wait, state); |
| 672 | } |
| 673 | EXPORT_SYMBOL_GPL(sbitmap_prepare_to_wait); |
| 674 | |
| 675 | void sbitmap_finish_wait(struct sbitmap_queue *sbq, struct sbq_wait_state *ws, |
| 676 | struct sbq_wait *sbq_wait) |
| 677 | { |
| 678 | finish_wait(&ws->wait, &sbq_wait->wait); |
Jens Axboe | 9f6b7ef | 2018-12-20 08:49:00 -0700 | [diff] [blame] | 679 | if (sbq_wait->sbq) { |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 680 | atomic_dec(&sbq->ws_active); |
Jens Axboe | 9f6b7ef | 2018-12-20 08:49:00 -0700 | [diff] [blame] | 681 | sbq_wait->sbq = NULL; |
Jens Axboe | 5d2ee71 | 2018-11-29 17:36:41 -0700 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | EXPORT_SYMBOL_GPL(sbitmap_finish_wait); |