From: Andrew Morton Ben points out that: When writing files out using O_SYNC, jbd's 1 jiffy delay results in a significant drop in throughput as the disk sits idle. The patch below results in a 4-5x performance improvement (from 6.5MB/s to ~24-30MB/s on my IDE test box) when writing out files using O_SYNC. So optimise the batching code by omitting it entirely if the process which is doing a sync write is the same as the one which did the most recent sync write. If that's true, we're unlikely to get any other processes joining the transaction. Cc: "Stephen C. Tweedie" Cc: Benjamin LaHaise Signed-off-by: Andrew Morton --- fs/jbd/transaction.c | 10 +++++++++- include/linux/jbd.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff -puN fs/jbd/transaction.c~jbd-fix-transaction-batching fs/jbd/transaction.c --- devel/fs/jbd/transaction.c~jbd-fix-transaction-batching 2006-01-16 21:25:04.000000000 -0800 +++ devel-akpm/fs/jbd/transaction.c 2006-01-16 21:25:04.000000000 -0800 @@ -1308,6 +1308,7 @@ int journal_stop(handle_t *handle) transaction_t *transaction = handle->h_transaction; journal_t *journal = transaction->t_journal; int old_handle_count, err; + pid_t pid; J_ASSERT(transaction->t_updates > 0); J_ASSERT(journal_current_handle() == handle); @@ -1333,8 +1334,15 @@ int journal_stop(handle_t *handle) * It doesn't cost much - we're about to run a commit and sleep * on IO anyway. Speeds up many-threaded, many-dir operations * by 30x or more... + * + * But don't do this if this process was the most recent one to + * perform a synchronous write. We do this to detect the case where a + * single process is doing a stream of sync writes. No point in waiting + * for joiners in that case. */ - if (handle->h_sync) { + pid = current->pid; + if (handle->h_sync && journal->j_last_sync_writer != pid) { + journal->j_last_sync_writer = pid; do { old_handle_count = transaction->t_handle_count; schedule_timeout_uninterruptible(1); diff -puN include/linux/jbd.h~jbd-fix-transaction-batching include/linux/jbd.h --- devel/include/linux/jbd.h~jbd-fix-transaction-batching 2006-01-16 21:25:04.000000000 -0800 +++ devel-akpm/include/linux/jbd.h 2006-01-16 21:25:04.000000000 -0800 @@ -23,6 +23,7 @@ #define jfs_debug jbd_debug #else +#include #include #include #include @@ -618,6 +619,7 @@ struct transaction_s * @j_wbuf: array of buffer_heads for journal_commit_transaction * @j_wbufsize: maximum number of buffer_heads allowed in j_wbuf, the * number that will fit in j_blocksize + * @j_last_sync_writer: most recent pid which did a synchronous write * @j_private: An opaque pointer to fs-private information. */ @@ -807,6 +809,8 @@ struct journal_s struct buffer_head **j_wbuf; int j_wbufsize; + pid_t j_last_sync_writer; + /* * An opaque pointer to fs-private information. ext3 puts its * superblock pointer here _