Skip to content

Commit 3853368

Browse files
committed
btrfs: preallocate compression workspaces
Preallocate one workspace for each compression type so we can guarantee forward progress in the worst case. A failure cannot be a hard error as we might not use compression at all on the filesystem. If we can't allocate the workspaces later when need them, it might actually deadlock, but in such situation the system has effectively not enough memory to operate properly. Signed-off-by: David Sterba <[email protected]>
1 parent b7bde41 commit 3853368

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

fs/btrfs/compression.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,26 @@ void __init btrfs_init_compress(void)
761761
int i;
762762

763763
for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) {
764+
struct list_head *workspace;
765+
764766
INIT_LIST_HEAD(&btrfs_comp_ws[i].idle_ws);
765767
spin_lock_init(&btrfs_comp_ws[i].ws_lock);
766768
atomic_set(&btrfs_comp_ws[i].total_ws, 0);
767769
init_waitqueue_head(&btrfs_comp_ws[i].ws_wait);
770+
771+
/*
772+
* Preallocate one workspace for each compression type so
773+
* we can guarantee forward progress in the worst case
774+
*/
775+
workspace = btrfs_compress_op[i]->alloc_workspace();
776+
if (IS_ERR(workspace)) {
777+
printk(KERN_WARNING
778+
"BTRFS: cannot preallocate compression workspace, will try later");
779+
} else {
780+
atomic_set(&btrfs_comp_ws[i].total_ws, 1);
781+
btrfs_comp_ws[i].free_ws = 1;
782+
list_add(workspace, &btrfs_comp_ws[i].idle_ws);
783+
}
768784
}
769785
}
770786

0 commit comments

Comments
 (0)