Commit 51040fa7 authored by Andrew Morton's avatar Andrew Morton Committed by Jeff Garzik

[PATCH] ext3: speed up O_SYNC writes

This is a forward-port of a 2.4 change from Stephen.  The (old) 2.5 code is
forcing a commit on every write by artificially dirtying the inode.

But generic_file_aio_write() has called generic_osync_inode() for us, which
has synced the file data.  There is no need to force the extra commit.
parent b1bd98a3
...@@ -55,29 +55,61 @@ static int ext3_open_file (struct inode * inode, struct file * filp) ...@@ -55,29 +55,61 @@ static int ext3_open_file (struct inode * inode, struct file * filp)
return 0; return 0;
} }
/*
* ext3_file_write().
*
* Most things are done in ext3_prepare_write() and ext3_commit_write().
*/
static ssize_t static ssize_t
ext3_file_write(struct kiocb *iocb, const char *buf, size_t count, loff_t pos) ext3_file_write(struct kiocb *iocb, const char *buf, size_t count, loff_t pos)
{ {
struct file *file = iocb->ki_filp; struct file *file = iocb->ki_filp;
struct inode *inode = file->f_dentry->d_inode; struct inode *inode = file->f_dentry->d_inode;
int ret, err;
ret = generic_file_aio_write(iocb, buf, count, pos);
/* /*
* Nasty: if the file is subject to synchronous writes then we need * Skip flushing if there was an error, or if nothing was written.
* to force generic_osync_inode() to call ext3_write_inode(). */
* We do that by marking the inode dirty. This adds much more if (ret <= 0)
* computational expense than we need, but we're going to sync return ret;
* anyway.
/*
* If the inode is IS_SYNC, or is O_SYNC and we are doing data
* journalling then we need to make sure that we force the transaction
* to disk to keep all metadata uptodate synchronously.
*/ */
if (IS_SYNC(inode) || (file->f_flags & O_SYNC)) if (file->f_flags & O_SYNC) {
mark_inode_dirty(inode); /*
* If we are non-data-journaled, then the dirty data has
* already been flushed to backing store by generic_osync_inode,
* and the inode has been flushed too if there have been any
* modifications other than mere timestamp updates.
*
* Open question --- do we care about flushing timestamps too
* if the inode is IS_SYNC?
*/
if (!ext3_should_journal_data(inode))
return ret;
goto force_commit;
}
return generic_file_aio_write(iocb, buf, count, pos); /*
* So we know that there has been no forced data flush. If the inode
* is marked IS_SYNC, we need to force one ourselves.
*/
if (!IS_SYNC(inode))
return ret;
/*
* Open question #2 --- should we force data to disk here too? If we
* don't, the only impact is that data=writeback filesystems won't
* flush data to disk automatically on IS_SYNC, only metadata (but
* historically, that is what ext2 has done.)
*/
force_commit:
err = ext3_force_commit(inode->i_sb);
if (err)
return err;
return ret;
} }
struct file_operations ext3_file_operations = { struct file_operations ext3_file_operations = {
......
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