Commit ff782e0a131c7f669445c07fe5c7ba91e043b7ed

Authored by Josef Bacik
Committed by Chris Mason
1 parent e3ccfa9897

Btrfs: optimize fsync for the single writer case

This patch optimizes the tree logging stuff so it doesn't always wait 1 jiffie
for new people to join the logging transaction if there is only ever 1 writer.
This helps a little bit with latency where we have something like RPM where it
will fdatasync every file it writes, and so waiting the 1 jiffie for every
fdatasync really starts to add up.

Signed-off-by: Josef Bacik <jbacik@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>

Showing 2 changed files with 13 additions and 1 deletions Side-by-side Diff

... ... @@ -1010,6 +1010,8 @@
1010 1010 atomic_t log_commit[2];
1011 1011 unsigned long log_transid;
1012 1012 unsigned long log_batch;
  1013 + pid_t log_start_pid;
  1014 + bool log_multiple_pids;
1013 1015  
1014 1016 u64 objectid;
1015 1017 u64 last_trans;
... ... @@ -137,11 +137,20 @@
137 137  
138 138 mutex_lock(&root->log_mutex);
139 139 if (root->log_root) {
  140 + if (!root->log_start_pid) {
  141 + root->log_start_pid = current->pid;
  142 + root->log_multiple_pids = false;
  143 + } else if (root->log_start_pid != current->pid) {
  144 + root->log_multiple_pids = true;
  145 + }
  146 +
140 147 root->log_batch++;
141 148 atomic_inc(&root->log_writers);
142 149 mutex_unlock(&root->log_mutex);
143 150 return 0;
144 151 }
  152 + root->log_multiple_pids = false;
  153 + root->log_start_pid = current->pid;
145 154 mutex_lock(&root->fs_info->tree_log_mutex);
146 155 if (!root->fs_info->log_root_tree) {
147 156 ret = btrfs_init_log_root_tree(trans, root->fs_info);
... ... @@ -1985,7 +1994,7 @@
1985 1994 if (atomic_read(&root->log_commit[(index1 + 1) % 2]))
1986 1995 wait_log_commit(trans, root, root->log_transid - 1);
1987 1996  
1988   - while (1) {
  1997 + while (root->log_multiple_pids) {
1989 1998 unsigned long batch = root->log_batch;
1990 1999 mutex_unlock(&root->log_mutex);
1991 2000 schedule_timeout_uninterruptible(1);
... ... @@ -2011,6 +2020,7 @@
2011 2020 root->log_batch = 0;
2012 2021 root->log_transid++;
2013 2022 log->log_transid = root->log_transid;
  2023 + root->log_start_pid = 0;
2014 2024 smp_mb();
2015 2025 /*
2016 2026 * log tree has been flushed to disk, new modifications of