Commit 5039eddc authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: make fsync latency less sucky

Looking into some performance related issues with large amounts of metadata
revealed that we can have some pretty huge swings in fsync() performance.  If we
have a lot of delayed refs backed up (as you will tend to do with lots of
metadata) fsync() will wander off and try to run some of those delayed refs
which can result in reading from disk and such.  Since the actual act of fsync()
doesn't create any delayed refs there is no need to make it throttle on delayed
ref stuff, that will be handled by other people.  With this patch we get much
smoother fsync performance with large amounts of metadata.  Thanks,
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 63541927
...@@ -1928,12 +1928,24 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -1928,12 +1928,24 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
if (file->private_data) if (file->private_data)
btrfs_ioctl_trans_end(file); btrfs_ioctl_trans_end(file);
/*
* We use start here because we will need to wait on the IO to complete
* in btrfs_sync_log, which could require joining a transaction (for
* example checking cross references in the nocow path). If we use join
* here we could get into a situation where we're waiting on IO to
* happen that is blocked on a transaction trying to commit. With start
* we inc the extwriter counter, so we wait for all extwriters to exit
* before we start blocking join'ers. This comment is to keep somebody
* from thinking they are super smart and changing this to
* btrfs_join_transaction *cough*Josef*cough*.
*/
trans = btrfs_start_transaction(root, 0); trans = btrfs_start_transaction(root, 0);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
goto out; goto out;
} }
trans->sync = true;
ret = btrfs_log_dentry_safe(trans, root, dentry); ret = btrfs_log_dentry_safe(trans, root, dentry);
if (ret < 0) { if (ret < 0) {
......
...@@ -474,6 +474,7 @@ start_transaction(struct btrfs_root *root, u64 num_items, unsigned int type, ...@@ -474,6 +474,7 @@ start_transaction(struct btrfs_root *root, u64 num_items, unsigned int type,
h->type = type; h->type = type;
h->allocating_chunk = false; h->allocating_chunk = false;
h->reloc_reserved = false; h->reloc_reserved = false;
h->sync = false;
INIT_LIST_HEAD(&h->qgroup_ref_list); INIT_LIST_HEAD(&h->qgroup_ref_list);
INIT_LIST_HEAD(&h->new_bgs); INIT_LIST_HEAD(&h->new_bgs);
...@@ -713,7 +714,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, ...@@ -713,7 +714,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
btrfs_create_pending_block_groups(trans, root); btrfs_create_pending_block_groups(trans, root);
trans->delayed_ref_updates = 0; trans->delayed_ref_updates = 0;
if (btrfs_should_throttle_delayed_refs(trans, root)) { if (!trans->sync && btrfs_should_throttle_delayed_refs(trans, root)) {
cur = max_t(unsigned long, cur, 1); cur = max_t(unsigned long, cur, 1);
trans->delayed_ref_updates = 0; trans->delayed_ref_updates = 0;
btrfs_run_delayed_refs(trans, root, cur); btrfs_run_delayed_refs(trans, root, cur);
......
...@@ -93,6 +93,7 @@ struct btrfs_trans_handle { ...@@ -93,6 +93,7 @@ struct btrfs_trans_handle {
short adding_csums; short adding_csums;
bool allocating_chunk; bool allocating_chunk;
bool reloc_reserved; bool reloc_reserved;
bool sync;
unsigned int type; unsigned int type;
/* /*
* this root is only needed to validate that the root passed to * this root is only needed to validate that the root passed to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment