Commit 5a813276 authored by David Howells's avatar David Howells

afs: Do better accretion of small writes on newly created content

Processes like ld that do lots of small writes that aren't necessarily
contiguous result in a lot of small StoreData operations to the server, the
idea being that if someone else changes the data on the server, we only
write our changes over that and not the space between.  Further, we don't
want to write back empty space if we can avoid it to make it easier for the
server to do sparse files.

However, making lots of tiny RPC ops is a lot less efficient for the server
than one big one because each op requires allocation of resources and the
taking of locks, so we want to compromise a bit.

Reduce the load by the following:

 (1) If a file is just created locally or has just been truncated with
     O_TRUNC locally, allow subsequent writes to the file to be merged with
     intervening space if that space doesn't cross an entire intervening
     page.

 (2) Don't flush the file on ->flush() but rather on ->release() if the
     file was open for writing.

Just linking vmlinux.o, without this patch, looking in /proc/fs/afs/stats:

	file-wr : n=441 nb=513581204

and after the patch:

	file-wr : n=62 nb=513668555

there were 379 fewer StoreData RPC operations at the expense of an extra
87K being written.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 76a5cb6f
...@@ -130,6 +130,7 @@ void afs_break_callback(struct afs_vnode *vnode) ...@@ -130,6 +130,7 @@ void afs_break_callback(struct afs_vnode *vnode)
write_seqlock(&vnode->cb_lock); write_seqlock(&vnode->cb_lock);
clear_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { if (test_and_clear_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
vnode->cb_break++; vnode->cb_break++;
afs_clear_permits(vnode); afs_clear_permits(vnode);
......
...@@ -1092,6 +1092,7 @@ static void afs_vnode_new_inode(struct afs_fs_cursor *fc, ...@@ -1092,6 +1092,7 @@ static void afs_vnode_new_inode(struct afs_fs_cursor *fc,
struct afs_file_status *newstatus, struct afs_file_status *newstatus,
struct afs_callback *newcb) struct afs_callback *newcb)
{ {
struct afs_vnode *vnode;
struct inode *inode; struct inode *inode;
if (fc->ac.error < 0) if (fc->ac.error < 0)
...@@ -1109,6 +1110,8 @@ static void afs_vnode_new_inode(struct afs_fs_cursor *fc, ...@@ -1109,6 +1110,8 @@ static void afs_vnode_new_inode(struct afs_fs_cursor *fc,
return; return;
} }
vnode = AFS_FS_I(inode);
set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
d_add(new_dentry, inode); d_add(new_dentry, inode);
} }
......
...@@ -30,7 +30,6 @@ static int afs_readpages(struct file *filp, struct address_space *mapping, ...@@ -30,7 +30,6 @@ static int afs_readpages(struct file *filp, struct address_space *mapping,
const struct file_operations afs_file_operations = { const struct file_operations afs_file_operations = {
.open = afs_open, .open = afs_open,
.flush = afs_flush,
.release = afs_release, .release = afs_release,
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.read_iter = generic_file_read_iter, .read_iter = generic_file_read_iter,
...@@ -146,6 +145,9 @@ int afs_open(struct inode *inode, struct file *file) ...@@ -146,6 +145,9 @@ int afs_open(struct inode *inode, struct file *file)
if (ret < 0) if (ret < 0)
goto error_af; goto error_af;
} }
if (file->f_flags & O_TRUNC)
set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
file->private_data = af; file->private_data = af;
_leave(" = 0"); _leave(" = 0");
...@@ -170,6 +172,9 @@ int afs_release(struct inode *inode, struct file *file) ...@@ -170,6 +172,9 @@ int afs_release(struct inode *inode, struct file *file)
_enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode); _enter("{%x:%u},", vnode->fid.vid, vnode->fid.vnode);
if ((file->f_mode & FMODE_WRITE))
return vfs_fsync(file, 0);
file->private_data = NULL; file->private_data = NULL;
if (af->wb) if (af->wb)
afs_put_wb_key(af->wb); afs_put_wb_key(af->wb);
......
...@@ -506,6 +506,7 @@ struct afs_vnode { ...@@ -506,6 +506,7 @@ struct afs_vnode {
#define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */ #define AFS_VNODE_MOUNTPOINT 5 /* set if vnode is a mountpoint symlink */
#define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */ #define AFS_VNODE_AUTOCELL 6 /* set if Vnode is an auto mount point */
#define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */ #define AFS_VNODE_PSEUDODIR 7 /* set if Vnode is a pseudo directory */
#define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
struct list_head wb_keys; /* List of keys available for writeback */ struct list_head wb_keys; /* List of keys available for writeback */
struct list_head pending_locks; /* locks waiting to be granted */ struct list_head pending_locks; /* locks waiting to be granted */
...@@ -1026,7 +1027,6 @@ extern int afs_writepage(struct page *, struct writeback_control *); ...@@ -1026,7 +1027,6 @@ extern int afs_writepage(struct page *, struct writeback_control *);
extern int afs_writepages(struct address_space *, struct writeback_control *); extern int afs_writepages(struct address_space *, struct writeback_control *);
extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *); extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
extern int afs_flush(struct file *, fl_owner_t);
extern int afs_fsync(struct file *, loff_t, loff_t, int); extern int afs_fsync(struct file *, loff_t, loff_t, int);
extern int afs_page_mkwrite(struct vm_fault *); extern int afs_page_mkwrite(struct vm_fault *);
extern void afs_prune_wb_keys(struct afs_vnode *); extern void afs_prune_wb_keys(struct afs_vnode *);
......
...@@ -125,7 +125,12 @@ int afs_write_begin(struct file *file, struct address_space *mapping, ...@@ -125,7 +125,12 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
page->index, priv); page->index, priv);
goto flush_conflicting_write; goto flush_conflicting_write;
} }
if (to < f || from > t) /* If the file is being filled locally, allow inter-write
* spaces to be merged into writes. If it's not, only write
* back what the user gives us.
*/
if (!test_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags) &&
(to < f || from > t))
goto flush_conflicting_write; goto flush_conflicting_write;
if (from < f) if (from < f)
f = from; f = from;
...@@ -419,7 +424,8 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, ...@@ -419,7 +424,8 @@ static int afs_write_back_from_locked_page(struct address_space *mapping,
trace_afs_page_dirty(vnode, tracepoint_string("WARN"), trace_afs_page_dirty(vnode, tracepoint_string("WARN"),
primary_page->index, priv); primary_page->index, priv);
if (start >= final_page || to < PAGE_SIZE) if (start >= final_page ||
(to < PAGE_SIZE && !test_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags)))
goto no_more; goto no_more;
start++; start++;
...@@ -440,9 +446,10 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, ...@@ -440,9 +446,10 @@ static int afs_write_back_from_locked_page(struct address_space *mapping,
} }
for (loop = 0; loop < n; loop++) { for (loop = 0; loop < n; loop++) {
if (to != PAGE_SIZE)
break;
page = pages[loop]; page = pages[loop];
if (to != PAGE_SIZE &&
!test_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags))
break;
if (page->index > final_page) if (page->index > final_page)
break; break;
if (!trylock_page(page)) if (!trylock_page(page))
...@@ -455,7 +462,8 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, ...@@ -455,7 +462,8 @@ static int afs_write_back_from_locked_page(struct address_space *mapping,
priv = page_private(page); priv = page_private(page);
f = priv & AFS_PRIV_MAX; f = priv & AFS_PRIV_MAX;
t = priv >> AFS_PRIV_SHIFT; t = priv >> AFS_PRIV_SHIFT;
if (f != 0) { if (f != 0 &&
!test_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags)) {
unlock_page(page); unlock_page(page);
break; break;
} }
...@@ -740,20 +748,6 @@ int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -740,20 +748,6 @@ int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
return file_write_and_wait_range(file, start, end); return file_write_and_wait_range(file, start, end);
} }
/*
* Flush out all outstanding writes on a file opened for writing when it is
* closed.
*/
int afs_flush(struct file *file, fl_owner_t id)
{
_enter("");
if ((file->f_mode & FMODE_WRITE) == 0)
return 0;
return vfs_fsync(file, 0);
}
/* /*
* notification that a previously read-only page is about to become writable * notification that a previously read-only page is about to become writable
* - if it returns an error, the caller will deliver a bus error signal * - if it returns an error, the caller will deliver a bus error signal
......
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