aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-04-26 20:55:15 -0400
committerDavid Sterba <dsterba@suse.com>2016-05-10 03:46:11 -0400
commitf77dd0d6b2f0f2cf290cacbd48f5eee18586e52b (patch)
tree07b4e749c8d70ed68fbe2b5ec5e7930af2abb687
parent6ac10a6ac2b11ada24580cc76dcd0c182061c576 (diff)
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 <dsterba@suse.com>
-rw-r--r--fs/btrfs/compression.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 4d5cd9624bb3..38c058bcf359 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -761,10 +761,26 @@ void __init btrfs_init_compress(void)
761 int i; 761 int i;
762 762
763 for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) { 763 for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) {
764 struct list_head *workspace;
765
764 INIT_LIST_HEAD(&btrfs_comp_ws[i].idle_ws); 766 INIT_LIST_HEAD(&btrfs_comp_ws[i].idle_ws);
765 spin_lock_init(&btrfs_comp_ws[i].ws_lock); 767 spin_lock_init(&btrfs_comp_ws[i].ws_lock);
766 atomic_set(&btrfs_comp_ws[i].total_ws, 0); 768 atomic_set(&btrfs_comp_ws[i].total_ws, 0);
767 init_waitqueue_head(&btrfs_comp_ws[i].ws_wait); 769 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 }
768 } 784 }
769} 785}
770 786