sbitmap.c (98d95416dbfaf4910caadfb4ddc75e4aacbdff8c) sbitmap.c (05fd095d53b979878f016c3a7080d3683cc89d72)
1/*
2 * Copyright (C) 2016 Facebook
3 * Copyright (C) 2013-2014 Jens Axboe
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License v2 as published by the Free Software Foundation.
8 *

--- 232 unchanged lines hidden (view full) ---

241{
242 sbq->wake_batch = sbq_calc_wake_batch(depth);
243 sbitmap_resize(&sbq->sb, depth);
244}
245EXPORT_SYMBOL_GPL(sbitmap_queue_resize);
246
247int __sbitmap_queue_get(struct sbitmap_queue *sbq)
248{
1/*
2 * Copyright (C) 2016 Facebook
3 * Copyright (C) 2013-2014 Jens Axboe
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License v2 as published by the Free Software Foundation.
8 *

--- 232 unchanged lines hidden (view full) ---

241{
242 sbq->wake_batch = sbq_calc_wake_batch(depth);
243 sbitmap_resize(&sbq->sb, depth);
244}
245EXPORT_SYMBOL_GPL(sbitmap_queue_resize);
246
247int __sbitmap_queue_get(struct sbitmap_queue *sbq)
248{
249 unsigned int hint;
249 unsigned int hint, depth;
250 int nr;
251
252 hint = this_cpu_read(*sbq->alloc_hint);
250 int nr;
251
252 hint = this_cpu_read(*sbq->alloc_hint);
253 depth = READ_ONCE(sbq->sb.depth);
254 if (unlikely(hint >= depth)) {
255 hint = depth ? prandom_u32() % depth : 0;
256 this_cpu_write(*sbq->alloc_hint, hint);
257 }
253 nr = sbitmap_get(&sbq->sb, hint, sbq->round_robin);
254
255 if (nr == -1) {
256 /* If the map is full, a hint won't do us much good. */
257 this_cpu_write(*sbq->alloc_hint, 0);
258 } else if (nr == hint || unlikely(sbq->round_robin)) {
259 /* Only update the hint if we used it. */
260 hint = nr + 1;
258 nr = sbitmap_get(&sbq->sb, hint, sbq->round_robin);
259
260 if (nr == -1) {
261 /* If the map is full, a hint won't do us much good. */
262 this_cpu_write(*sbq->alloc_hint, 0);
263 } else if (nr == hint || unlikely(sbq->round_robin)) {
264 /* Only update the hint if we used it. */
265 hint = nr + 1;
261 if (hint >= sbq->sb.depth - 1)
266 if (hint >= depth - 1)
262 hint = 0;
263 this_cpu_write(*sbq->alloc_hint, hint);
264 }
265
266 return nr;
267}
268EXPORT_SYMBOL_GPL(__sbitmap_queue_get);
269

--- 73 unchanged lines hidden ---
267 hint = 0;
268 this_cpu_write(*sbq->alloc_hint, hint);
269 }
270
271 return nr;
272}
273EXPORT_SYMBOL_GPL(__sbitmap_queue_get);
274

--- 73 unchanged lines hidden ---