Commit 7e7382fd authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] speed up writes

Speeds up generic_file_write() by not calling mark_inode_dirty() when
the mtime and ctime didn't change.

There may be concerns over the fact that this restricts mtime and ctime
updates to one-second resolution.  But the interface doesn't support
that anyway - all the filesystem knows is that its dirty_inode()
superop was called.  It doesn't know why.

So filesystems which support high-resolution timestamps already need to
make their own arrangements.  We need an update_mtime i_op to support
those properly.

time to write a one megabyte file one-byte-at-a-time:

Before:
	ext3:		24.8 seconds
	ext2:		 4.9 seconds
	reiserfs:	17.0 seconds
After:
	ext3:		22.5 seconds
	ext2:		4.8  seconds
	reiserfs:	11.6 seconds

Not much improvement because we're also calling expensive
mark_inode_dirty() functions when i_size is expanded.  So compare the
overwrite case:

time dd if=/dev/zero of=foo bs=1 count=1M conv=notrunc

ext3 before:	20.0 seconds
ext3 after:	9.7  seconds
parent 02eaba7f
...@@ -2098,6 +2098,7 @@ generic_file_write(struct file *file, const char *buf, ...@@ -2098,6 +2098,7 @@ generic_file_write(struct file *file, const char *buf,
ssize_t written; ssize_t written;
int err; int err;
unsigned bytes; unsigned bytes;
time_t time_now;
if (unlikely((ssize_t) count < 0)) if (unlikely((ssize_t) count < 0))
return -EINVAL; return -EINVAL;
...@@ -2195,9 +2196,12 @@ generic_file_write(struct file *file, const char *buf, ...@@ -2195,9 +2196,12 @@ generic_file_write(struct file *file, const char *buf,
goto out; goto out;
remove_suid(file->f_dentry); remove_suid(file->f_dentry);
inode->i_ctime = CURRENT_TIME; time_now = CURRENT_TIME;
inode->i_mtime = CURRENT_TIME; if (inode->i_ctime != time_now || inode->i_mtime != time_now) {
inode->i_ctime = time_now;
inode->i_mtime = time_now;
mark_inode_dirty_sync(inode); mark_inode_dirty_sync(inode);
}
if (unlikely(file->f_flags & O_DIRECT)) { if (unlikely(file->f_flags & O_DIRECT)) {
written = generic_file_direct_IO(WRITE, file, written = generic_file_direct_IO(WRITE, file,
......
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