Commit 18c41b37 authored by Ryusuke Konishi's avatar Ryusuke Konishi Committed by Linus Torvalds

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: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4e9e63a6
...@@ -335,39 +335,33 @@ void *nilfs_palloc_block_get_entry(const struct inode *inode, __u64 nr, ...@@ -335,39 +335,33 @@ void *nilfs_palloc_block_get_entry(const struct inode *inode, __u64 nr,
*/ */
static int nilfs_palloc_find_available_slot(unsigned char *bitmap, static int nilfs_palloc_find_available_slot(unsigned char *bitmap,
unsigned long target, unsigned long target,
int bsize, unsigned bsize,
spinlock_t *lock) spinlock_t *lock)
{ {
int curr, pos, end, i; int pos, end = bsize;
if (target > 0) { if (likely(target < bsize)) {
end = (target + BITS_PER_LONG - 1) & ~(BITS_PER_LONG - 1); pos = target;
if (end > bsize) do {
end = bsize; pos = nilfs_find_next_zero_bit(bitmap, end, pos);
pos = nilfs_find_next_zero_bit(bitmap, end, target); if (pos >= end)
if (pos < end && !nilfs_set_bit_atomic(lock, pos, bitmap)) break;
return pos; if (!nilfs_set_bit_atomic(lock, pos, bitmap))
} else { return pos;
end = 0; } while (++pos < end);
end = target;
} }
for (i = 0, curr = end; /* wrap around */
i < bsize; for (pos = 0; pos < end; pos++) {
i += BITS_PER_LONG, curr += BITS_PER_LONG) { pos = nilfs_find_next_zero_bit(bitmap, end, pos);
/* wrap around */ if (pos >= end)
if (curr >= bsize) break;
curr = 0; if (!nilfs_set_bit_atomic(lock, pos, bitmap))
while (*((unsigned long *)bitmap + curr / BITS_PER_LONG) return pos;
!= ~0UL) {
end = curr + BITS_PER_LONG;
if (end > bsize)
end = bsize;
pos = nilfs_find_next_zero_bit(bitmap, end, curr);
if (pos < end &&
!nilfs_set_bit_atomic(lock, pos, bitmap))
return pos;
}
} }
return -ENOSPC; return -ENOSPC;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment