Btrfs: don't use delalloc block rsv for free space inodes
PATCH 1/1 Btrfs: don't use delalloc block rsv for free space inodes
In tracking down this "not enough space" warning with checksums, it seems that we were running out of space partly because we do not reserve space for our free space inodes. Since this is technically metadata anyway go ahead and use the global_block_rsv for our free space inodes. We shouldn't be modifying too much other metadata since this will be a preallocated extent and that was already accounted for earlier. Thanks,
--- fs/btrfs/inode.c | 32 ++++++++++++-------------------- 1 files changed, 12 insertions(+), 20 deletions(-)
fs/btrfs/inode.c +12 -20
@@ -1717,7 +1717,6 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)struct extent_state *cached_state =NULL ;int compress_type =0 ;int ret; -bool nolock; ret =btrfs_dec_test_ordered_pending (inode, &ordered_extent, start, end - start +1 );
@@ -1725,18 +1724,20 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)return 0 ;BUG_ON (!ordered_extent); - nolock =btrfs_is_free_space_inode (root, inode); +if (btrfs_is_free_space_inode (root, inode)) { + trans =btrfs_join_transaction_nolock (root); +BUG_ON (IS_ERR (trans)); + trans->block_rsv = &root->fs_info->global_block_rsv; + }else { + trans =btrfs_join_transaction (root); +BUG_ON (IS_ERR (trans)); + trans->block_rsv = &root->fs_info->delalloc_block_rsv; + }if (test_bit (BTRFS_ORDERED_NOCOW , &ordered_extent->flags)) {BUG_ON (!list_empty (&ordered_extent->list)); ret =btrfs_ordered_update_i_size (inode,0 , ordered_extent);if (!ret) { -if (nolock) - trans =btrfs_join_transaction_nolock (root); -else - trans =btrfs_join_transaction (root); -BUG_ON (IS_ERR (trans)); - trans->block_rsv = &root->fs_info->delalloc_block_rsv; ret =btrfs_update_inode (trans, root, inode);BUG_ON (ret); }
@@ -1747,13 +1748,6 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) ordered_extent->file_offset + ordered_extent->len -1 , 0, &cached_state, GFP_NOFS); -if (nolock) - trans =btrfs_join_transaction_nolock (root); -else - trans =btrfs_join_transaction (root); -BUG_ON (IS_ERR (trans)); - trans->block_rsv = &root->fs_info->delalloc_block_rsv; -if (test_bit (BTRFS_ORDERED_COMPRESSED , &ordered_extent->flags)) compress_type = ordered_extent->compress_type;if (test_bit (BTRFS_ORDERED_PREALLOC , &ordered_extent->flags)) {
@@ -1792,13 +1786,11 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) } ret =0 ; out: -if (nolock) { -if (trans) -btrfs_end_transaction_nolock (trans, root); +if (btrfs_is_free_space_inode (root, inode)) { +btrfs_end_transaction_nolock (trans, root); }else {btrfs_delalloc_release_metadata (inode, ordered_extent->len); -if (trans) -btrfs_end_transaction (trans, root); +btrfs_end_transaction (trans, root); }/* once for us */
Signature · 1 line
1.7.5.2
PATCH 1/1 Btrfs: don't use delalloc block rsv for free space inodes V2
In tracking down this "not enough space" warning with checksums, it seems that we were running out of space partly because we do not reserve space for our free space inodes. Since this is technically metadata anyway go ahead and use the global_block_rsv for our free space inodes. We shouldn't be modifying too much other metadata since this will be a preallocated extent and that was already accounted for earlier. Thanks,
---V1->V2: forgot about one case
fs/btrfs/inode.c | 56 ++++++++++++++++++++++------------------------------- 1 files changed, 23 insertions(+), 33 deletions(-)
fs/btrfs/inode.c +23 -33
@@ -1057,22 +1057,21 @@ static noinline int run_delalloc_nocow(struct inode *inode,int type;int nocow;int check_prev =1 ; -bool nolock;u64 ino =btrfs_ino (inode); path =btrfs_alloc_path ();if (!path)return -ENOMEM ; - nolock =btrfs_is_free_space_inode (root, inode); - -if (nolock) +if (btrfs_is_free_space_inode (root, inode)) { trans =btrfs_join_transaction_nolock (root); -else +BUG_ON (IS_ERR (trans)); + trans->block_rsv = &root->fs_info->global_block_rsv; + }else { trans =btrfs_join_transaction (root); - -BUG_ON (IS_ERR (trans)); - trans->block_rsv = &root->fs_info->delalloc_block_rsv; +BUG_ON (IS_ERR (trans)); + trans->block_rsv = &root->fs_info->delalloc_block_rsv; + } cow_start = (u64)-1 ; cur_offset = start;
@@ -1245,13 +1244,12 @@ out_check:BUG_ON (ret); } -if (nolock) { +if (btrfs_is_free_space_inode (root, inode)) ret =btrfs_end_transaction_nolock (trans, root); -BUG_ON (ret); - }else { +else ret =btrfs_end_transaction (trans, root); -BUG_ON (ret); - } +BUG_ON (ret); +btrfs_free_path (path);return 0 ; }
@@ -1717,7 +1715,6 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)struct extent_state *cached_state =NULL ;int compress_type =0 ;int ret; -bool nolock; ret =btrfs_dec_test_ordered_pending (inode, &ordered_extent, start, end - start +1 );
@@ -1725,18 +1722,20 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)return 0 ;BUG_ON (!ordered_extent); - nolock =btrfs_is_free_space_inode (root, inode); +if (btrfs_is_free_space_inode (root, inode)) { + trans =btrfs_join_transaction_nolock (root); +BUG_ON (IS_ERR (trans)); + trans->block_rsv = &root->fs_info->global_block_rsv; + }else { + trans =btrfs_join_transaction (root); +BUG_ON (IS_ERR (trans)); + trans->block_rsv = &root->fs_info->delalloc_block_rsv; + }if (test_bit (BTRFS_ORDERED_NOCOW , &ordered_extent->flags)) {BUG_ON (!list_empty (&ordered_extent->list)); ret =btrfs_ordered_update_i_size (inode,0 , ordered_extent);if (!ret) { -if (nolock) - trans =btrfs_join_transaction_nolock (root); -else - trans =btrfs_join_transaction (root); -BUG_ON (IS_ERR (trans)); - trans->block_rsv = &root->fs_info->delalloc_block_rsv; ret =btrfs_update_inode (trans, root, inode);BUG_ON (ret); }
@@ -1747,13 +1746,6 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) ordered_extent->file_offset + ordered_extent->len -1 , 0, &cached_state, GFP_NOFS); -if (nolock) - trans =btrfs_join_transaction_nolock (root); -else - trans =btrfs_join_transaction (root); -BUG_ON (IS_ERR (trans)); - trans->block_rsv = &root->fs_info->delalloc_block_rsv; -if (test_bit (BTRFS_ORDERED_COMPRESSED , &ordered_extent->flags)) compress_type = ordered_extent->compress_type;if (test_bit (BTRFS_ORDERED_PREALLOC , &ordered_extent->flags)) {
@@ -1792,13 +1784,11 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) } ret =0 ; out: -if (nolock) { -if (trans) -btrfs_end_transaction_nolock (trans, root); +if (btrfs_is_free_space_inode (root, inode)) { +btrfs_end_transaction_nolock (trans, root); }else {btrfs_delalloc_release_metadata (inode, ordered_extent->len); -if (trans) -btrfs_end_transaction (trans, root); +btrfs_end_transaction (trans, root); }/* once for us */
Signature · 1 line
1.7.5.2
Quoted 7 lines · Josef Bacik
In tracking down this "not enough space" warning with checksums, it seems that we were running out of space partly because we do not reserve space for our free space inodes. Since this is technically metadata anyway go ahead and use the
global_block_rsvfor our free space inodes. We shouldn't be modifying too much other metadata since this will be a preallocated extent and that was already accounted for earlier. Thanks,
Ignore these, they cause other problems, I'll fix it a different way. Thanks,
Josef