Btrfs: flush delayed inodes if we're short on space
PATCH 1/1 Btrfs: flush delayed inodes if we're short on space
Those crazy gentoo guys have been complaining about ENOSPC errors on their portage volumes. This is because doing things like untar tends to create lots of new files which will soak up all the reservation space in the delayed inodes. Usually this gets papered over by the fact that we will try and commit the transaction, however if this happens in the wrong spot or we choose not to commit the transaction you will be screwed. So add the ability to expclitly flush delayed inodes to free up space. Please test this out guys to make sure it works since as usual I cannot reproduce. Thanks,
--- fs/btrfs/delayed-inode.c | 22 ++++++++++-- fs/btrfs/delayed-inode.h | 2 + fs/btrfs/extent-tree.c | 91 ++++++++++++++++++++++++++++------------------ 3 files changed, 76 insertions(+), 39 deletions(-)
fs/btrfs/delayed-inode.c +19 -3
@@ -1113,8 +1113,8 @@ static int btrfs_update_delayed_inode(struct btrfs_trans_handle *trans,* Returns < 0 on error and returns with an aborted transaction with any * outstanding delayed items cleaned up. */ -int btrfs_run_delayed_items (struct btrfs_trans_handle *trans, -struct btrfs_root *root) +static int __btrfs_run_delayed_items (struct btrfs_trans_handle *trans, +struct btrfs_root *root,int nr) {struct btrfs_root *curr_root = root;struct btrfs_delayed_root *delayed_root;
@@ -1122,6 +1122,7 @@ int btrfs_run_delayed_items(struct btrfs_trans_handle *trans,struct btrfs_path *path;struct btrfs_block_rsv *block_rsv;int ret =0 ; +bool count = (nr >0 );if (trans->aborted)return -EIO ;
@@ -1137,7 +1138,7 @@ int btrfs_run_delayed_items(struct btrfs_trans_handle *trans, delayed_root =btrfs_get_delayed_root (root); curr_node =btrfs_first_delayed_node (delayed_root); -while (curr_node) { +while (curr_node && (!count || (count && nr--))) { curr_root = curr_node->root; ret =btrfs_insert_delayed_items (trans, path, curr_root, curr_node);
@@ -1149,6 +1150,7 @@ int btrfs_run_delayed_items(struct btrfs_trans_handle *trans, path, curr_node);if (ret) {btrfs_release_delayed_node (curr_node); + curr_node =NULL ;btrfs_abort_transaction (trans, root, ret);break ; }
@@ -1158,12 +1160,26 @@ int btrfs_run_delayed_items(struct btrfs_trans_handle *trans,btrfs_release_delayed_node (prev_node); } +if (curr_node) +btrfs_release_delayed_node (curr_node);btrfs_free_path (path); trans->block_rsv = block_rsv;return ret; } +int btrfs_run_delayed_items (struct btrfs_trans_handle *trans, +struct btrfs_root *root) +{ +return __btrfs_run_delayed_items (trans, root,-1 ); +} + +int btrfs_run_delayed_items_nr (struct btrfs_trans_handle *trans, +struct btrfs_root *root,int nr) +{ +return __btrfs_run_delayed_items (trans, root, nr); +} +static int __btrfs_commit_inode_delayed_items (struct btrfs_trans_handle *trans,struct btrfs_delayed_node *node) {
fs/btrfs/delayed-inode.h +2 -0
@@ -107,6 +107,8 @@ int btrfs_inode_delayed_dir_index_count(struct inode *inode);int btrfs_run_delayed_items (struct btrfs_trans_handle *trans,struct btrfs_root *root); +int btrfs_run_delayed_items_nr (struct btrfs_trans_handle *trans, +struct btrfs_root *root,int nr);void btrfs_balance_delayed_items (struct btrfs_root *root);
fs/btrfs/extent-tree.c +55 -36
125 lines not on this page · raw message
Signature · 1 line
1.7.7.6
fs/btrfs/extent-tree.c commit: · line 3757
Quoted 4 lines
fs/btrfs/extent-tree.c +3
-0+case FLUSH_DELAYED_ITEMS_NR : +case FLUSH_DELAYED_ITEMS : + nr = (*state ==FLUSH_DELAYED_ITEMS_NR ) ?10 :-1 ;
This 10 seemed awfully magical so I read a bit more.
It appears to be an attempt to pop back up into reserve_metadata_bytes() to see if the caller has been satisfied before continuing on to apply all the delayed items.
The magic number seems awfully clumsy. It'll either do too much work or will blow through all the delayed items, depending on the load. Is it too hard to have btrfs_run_delayed_items() check for the callers reservation and return if there's a chance that it'll be satisfied?
Am I missing something? Over-thinking a rare path as the initial steps will tend to free up space most of the time?
- z
Quoted 11 lines · Zach Brown
fs/btrfs/extent-tree.c commit: · line 3757
Quoted 4 lines
fs/btrfs/extent-tree.c +3
-0+case FLUSH_DELAYED_ITEMS_NR : +case FLUSH_DELAYED_ITEMS : + nr = (*state ==FLUSH_DELAYED_ITEMS_NR ) ?10 :-1 ;This 10 seemed awfully magical so I read a bit more.
It appears to be an attempt to pop back up into
reserve_metadata_bytes()to see if the caller has been satisfied before continuing on to apply all the delayed items.
Quoted 8 lines
The magic number seems awfully clumsy. It'll either do too much work or will blow through all the delayed items, depending on the load. Is it too hard to have
btrfs_run_delayed_items()check for the callers reservation and return if there's a chance that it'll be satisfied?Am I missing something? Over-thinking a rare path as the initial steps will tend to free up space most of the time?
Ugh sorry I just dug this patch out from last week and forgot I had just picked an arbitrary number to make sure it was working. You are correct, what I _meant_ to do (and will do after I respond) was calculate how much we wanted to flush and then divide that by how much the delayed inodes reserve and then multiply it by 2 for good measure. Does that sound more reasonable? Thanks,
Josef
Quoted 6 lines
Ugh sorry I just dug this patch out from last week and forgot I had just picked an arbitrary number to make sure it was working. You are correct, what I _meant_ to do (and will do after I respond) was calculate how much we wanted to flush and then divide that by how much the delayed inodes reserve and then multiply it by 2 for good measure.
I guess that's as good a place as any to start :)
It'd be nice to see some data on how often this actually stops the full run. If it doesn't, just pitch the whole _NR path entirely?
- z