int allowed_chunk_alloc = 0;
struct list_head *head = NULL, *cur = NULL;
int loop = 0;
+ int extra_loop = 0;
struct btrfs_space_info *space_info;
WARN_ON(num_bytes < root->sectorsize);
free_space = btrfs_find_free_space(block_group, search_start,
total_needed);
+ if (empty_size)
+ extra_loop = 1;
+
if (free_space) {
u64 start = block_group->key.objectid;
u64 end = block_group->key.objectid +
new_group:
mutex_unlock(&block_group->alloc_mutex);
new_group_no_lock:
+ /* don't try to compare new allocations against the
+ * last allocation any more
+ */
last_wanted = 0;
- if (!allowed_chunk_alloc) {
- total_needed -= empty_size;
- empty_size = 0;
- }
+
/*
* Here's how this works.
* loop == 0: we were searching a block group via a hint
cur = head->next;
loop++;
} else if (loop == 1 && cur == head) {
-
+ int keep_going;
+
+ /* at this point we give up on the empty_size
+ * allocations and just try to allocate the min
+ * space.
+ *
+ * The extra_loop field was set if an empty_size
+ * allocation was attempted above, and if this
+ * is try we need to try the loop again without
+ * the additional empty_size.
+ */
total_needed -= empty_size;
empty_size = 0;
+ keep_going = extra_loop;
+ loop++;
if (allowed_chunk_alloc && !chunk_alloc_done) {
up_read(&space_info->groups_sem);
if (ret < 0)
break;
down_read(&space_info->groups_sem);
- loop++;
head = &space_info->block_groups;
- cur = head->next;
+ /*
+ * we've allocated a new chunk, keep
+ * trying
+ */
+ keep_going = 1;
chunk_alloc_done = 1;
} else if (!allowed_chunk_alloc) {
space_info->force_alloc = 1;
- break;
+ }
+ if (keep_going) {
+ cur = head->next;
+ extra_loop = 0;
} else {
break;
}