Commit 2f83855c authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] truncate speedup

This patch optimises the truncate of a zero-length file, which is a
sufficiently common case to justify the extra test-n-branch.

It does this by skipping the entire call into the fs if i_size is not
being altered.

The AIM9 `open_clo' test just loops, creating and unlinking a file.
This patch speeds it up 50% for ext2, 600% for reiserfs.
parent 1ecd39c2
......@@ -66,14 +66,21 @@ int inode_setattr(struct inode * inode, struct iattr * attr)
{
unsigned int ia_valid = attr->ia_valid;
int error = 0;
lock_kernel();
if (ia_valid & ATTR_SIZE) {
error = vmtruncate(inode, attr->ia_size);
if (error)
goto out;
if (attr->ia_size == inode->i_size) {
if (ia_valid == ATTR_SIZE)
goto out; /* we can skip lock_kernel() */
} else {
lock_kernel();
error = vmtruncate(inode, attr->ia_size);
unlock_kernel();
if (error)
goto out;
}
}
lock_kernel();
if (ia_valid & ATTR_UID)
inode->i_uid = attr->ia_uid;
if (ia_valid & ATTR_GID)
......@@ -90,8 +97,8 @@ int inode_setattr(struct inode * inode, struct iattr * attr)
inode->i_mode &= ~S_ISGID;
}
mark_inode_dirty(inode);
out:
unlock_kernel();
out:
return error;
}
......
......@@ -115,6 +115,9 @@ void truncate_inode_pages(struct address_space *mapping, loff_t lstart)
pgoff_t next;
int i;
if (mapping->nrpages == 0)
return;
pagevec_init(&pvec, 0);
next = start;
while (pagevec_lookup(&pvec, mapping, next, PAGEVEC_SIZE)) {
......
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