Btrfs: fix the allocator loop logic
I was testing with empty_cluster = 0 to try and reproduce a problem and kept hitting early enospc panics. This was because our loop logic was a little confused. So this is what I did 1) Make the loop variable the ultimate decider on wether we should loop again isntead of checking to see if we had an uncached bg, empty size or empty cluster. 2) Increment loop before checking to see what we are on to make the loop definitions make more sense. 3) If we are on the chunk alloc loop don't set empty_size/empty_cluster to 0 unless we didn't actually allocate a chunk. If we did allocate a chunk we should be able to easily setup a new cluster so clearing empty_size/empty_cluster makes us less efficient. This kept me from hitting panics while trying to reproduce the other problem. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
This commit is contained in:
parent
2cdc342c20
commit
723bda2083
|
@ -5218,9 +5218,7 @@ loop:
|
||||||
* LOOP_NO_EMPTY_SIZE, set empty_size and empty_cluster to 0 and try
|
* LOOP_NO_EMPTY_SIZE, set empty_size and empty_cluster to 0 and try
|
||||||
* again
|
* again
|
||||||
*/
|
*/
|
||||||
if (!ins->objectid && loop < LOOP_NO_EMPTY_SIZE &&
|
if (!ins->objectid && loop < LOOP_NO_EMPTY_SIZE) {
|
||||||
(found_uncached_bg || empty_size || empty_cluster ||
|
|
||||||
allowed_chunk_alloc)) {
|
|
||||||
index = 0;
|
index = 0;
|
||||||
if (loop == LOOP_FIND_IDEAL && found_uncached_bg) {
|
if (loop == LOOP_FIND_IDEAL && found_uncached_bg) {
|
||||||
found_uncached_bg = false;
|
found_uncached_bg = false;
|
||||||
|
@ -5260,32 +5258,36 @@ loop:
|
||||||
goto search;
|
goto search;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loop < LOOP_CACHING_WAIT) {
|
|
||||||
loop++;
|
loop++;
|
||||||
goto search;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loop == LOOP_ALLOC_CHUNK) {
|
if (loop == LOOP_ALLOC_CHUNK) {
|
||||||
empty_size = 0;
|
|
||||||
empty_cluster = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (allowed_chunk_alloc) {
|
if (allowed_chunk_alloc) {
|
||||||
ret = do_chunk_alloc(trans, root, num_bytes +
|
ret = do_chunk_alloc(trans, root, num_bytes +
|
||||||
2 * 1024 * 1024, data,
|
2 * 1024 * 1024, data,
|
||||||
CHUNK_ALLOC_LIMITED);
|
CHUNK_ALLOC_LIMITED);
|
||||||
allowed_chunk_alloc = 0;
|
allowed_chunk_alloc = 0;
|
||||||
|
if (ret == 1)
|
||||||
done_chunk_alloc = 1;
|
done_chunk_alloc = 1;
|
||||||
} else if (!done_chunk_alloc &&
|
} else if (!done_chunk_alloc &&
|
||||||
space_info->force_alloc == CHUNK_ALLOC_NO_FORCE) {
|
space_info->force_alloc ==
|
||||||
|
CHUNK_ALLOC_NO_FORCE) {
|
||||||
space_info->force_alloc = CHUNK_ALLOC_LIMITED;
|
space_info->force_alloc = CHUNK_ALLOC_LIMITED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loop < LOOP_NO_EMPTY_SIZE) {
|
/*
|
||||||
loop++;
|
* We didn't allocate a chunk, go ahead and drop the
|
||||||
goto search;
|
* empty size and loop again.
|
||||||
|
*/
|
||||||
|
if (!done_chunk_alloc)
|
||||||
|
loop = LOOP_NO_EMPTY_SIZE;
|
||||||
}
|
}
|
||||||
ret = -ENOSPC;
|
|
||||||
|
if (loop == LOOP_NO_EMPTY_SIZE) {
|
||||||
|
empty_size = 0;
|
||||||
|
empty_cluster = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto search;
|
||||||
} else if (!ins->objectid) {
|
} else if (!ins->objectid) {
|
||||||
ret = -ENOSPC;
|
ret = -ENOSPC;
|
||||||
} else if (ins->objectid) {
|
} else if (ins->objectid) {
|
||||||
|
|
Loading…
Reference in a new issue