diff options
author | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2015-11-06 19:31:48 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-11-06 20:50:42 -0500 |
commit | 18c41b37f0f16a0d6e5b1a73563d0c1333e7ef70 (patch) | |
tree | 361af81ca044b6acaecfc58a83f0375abda7653b /fs/nilfs2 | |
parent | 4e9e63a671fbe13f448fb2e69dfdbb6c2a008368 (diff) |
nilfs2: refactor nilfs_palloc_find_available_slot()
The current implementation of nilfs_palloc_find_available_slot() function
is overkill. The underlying bit search routine is well optimized, so this
uses it more simply in nilfs_palloc_find_available_slot().
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/nilfs2')
-rw-r--r-- | fs/nilfs2/alloc.c | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c index ff0d62ce165b..b15daf871f99 100644 --- a/fs/nilfs2/alloc.c +++ b/fs/nilfs2/alloc.c | |||
@@ -335,39 +335,33 @@ void *nilfs_palloc_block_get_entry(const struct inode *inode, __u64 nr, | |||
335 | */ | 335 | */ |
336 | static int nilfs_palloc_find_available_slot(unsigned char *bitmap, | 336 | static int nilfs_palloc_find_available_slot(unsigned char *bitmap, |
337 | unsigned long target, | 337 | unsigned long target, |
338 | int bsize, | 338 | unsigned bsize, |
339 | spinlock_t *lock) | 339 | spinlock_t *lock) |
340 | { | 340 | { |
341 | int curr, pos, end, i; | 341 | int pos, end = bsize; |
342 | 342 | ||
343 | if (target > 0) { | 343 | if (likely(target < bsize)) { |
344 | end = (target + BITS_PER_LONG - 1) & ~(BITS_PER_LONG - 1); | 344 | pos = target; |
345 | if (end > bsize) | 345 | do { |
346 | end = bsize; | 346 | pos = nilfs_find_next_zero_bit(bitmap, end, pos); |
347 | pos = nilfs_find_next_zero_bit(bitmap, end, target); | 347 | if (pos >= end) |
348 | if (pos < end && !nilfs_set_bit_atomic(lock, pos, bitmap)) | 348 | break; |
349 | return pos; | 349 | if (!nilfs_set_bit_atomic(lock, pos, bitmap)) |
350 | } else { | 350 | return pos; |
351 | end = 0; | 351 | } while (++pos < end); |
352 | |||
353 | end = target; | ||
352 | } | 354 | } |
353 | 355 | ||
354 | for (i = 0, curr = end; | 356 | /* wrap around */ |
355 | i < bsize; | 357 | for (pos = 0; pos < end; pos++) { |
356 | i += BITS_PER_LONG, curr += BITS_PER_LONG) { | 358 | pos = nilfs_find_next_zero_bit(bitmap, end, pos); |
357 | /* wrap around */ | 359 | if (pos >= end) |
358 | if (curr >= bsize) | 360 | break; |
359 | curr = 0; | 361 | if (!nilfs_set_bit_atomic(lock, pos, bitmap)) |
360 | while (*((unsigned long *)bitmap + curr / BITS_PER_LONG) | 362 | return pos; |
361 | != ~0UL) { | ||
362 | end = curr + BITS_PER_LONG; | ||
363 | if (end > bsize) | ||
364 | end = bsize; | ||
365 | pos = nilfs_find_next_zero_bit(bitmap, end, curr); | ||
366 | if (pos < end && | ||
367 | !nilfs_set_bit_atomic(lock, pos, bitmap)) | ||
368 | return pos; | ||
369 | } | ||
370 | } | 363 | } |
364 | |||
371 | return -ENOSPC; | 365 | return -ENOSPC; |
372 | } | 366 | } |
373 | 367 | ||