sys_copyfile
Quoted 1 line
With warm cache,
copyfile()is about 10% faster
Over the network it would be a lot more than that.
With cifs vfs, I would expect that copyfile of files located on the same server share would be much faster than that perhaps 5 to 10 times faster due to the huge reduction in network bandwidth usage and latency - since for the case of cifs the protocol already defines a single network operation for copy file that could be then used (although it would be preceeded by a couple of cheap cifs calls for the directory name lookup, although the target mode complicates things for cifs - there would be a minor change needed at the end to set the mode if the copy succeeds which makes the copy error paths over the ). For the CIFS Unix Extensions version 2 would could add a trivial change to Samba to take the mode as part of copy network parms.
in do_copyfile all I would need would be an op that looks a bit like rename (the cifs vfs part of the changes, to fs/cifs/cifssmb.c mostly, would be trivial) e.g.:
int do_copyfile(struct nameidata *old_nd, struct nameidata *new_nd,
struct dentry *new_dentry, umode_t mode)
{
- int ret;
+ int ret = 0;
if (!old_nd->dentry->d_inode)
return -ENOENT;
if (!S_ISREG(old_nd->dentry->d_inode->i_mode))
return -EINVAL;
/* FIXME: replace with proper permission check */
if (new_dentry->d_inode)
return -EEXIST;+ if(old_nd->dentry->d_inode->i_op->copy) {
+ ret = old_dir->i_op->copy(old_nd->dentry,
+ mode, new_dentry);
+ }
if(!ret)
return ret;
else
ret = vfs_create(new_nd->dentry->d_inode,
new_dentry, mode, new_nd);
if (ret)
return ret;
ret = copy_data(old_nd->dentry, old_nd->mnt, new_dentry,
new_nd->mnt);
if (ret) {
int error = vfs_unlink(new_nd->dentry->d_inode,
new_dentry);
BUG_ON(error);
/* FIXME: not sure if there are return value we
should not BUG()
* on */
}
return ret;
}Quoted 4 lines · Steve French
Quoted 2 lines
With warm cache,
copyfile()is about 10% fasterOver the network it would be a lot more than that.
True, if network traffic is saved as well.
Quoted 12 lines
in
do_copyfileall I would need would be an op that looks a bit like rename (the cifs vfs part of the changes, tofs/cifs/cifssmb.cmostly, would be trivial) e.g.:int do_copyfile(struct nameidata
*old_nd, struct nameidata*new_nd,
struct dentry*new_dentry,umode_tmode)
{(quoted diff) +1
-1- int ret; + int ret = 0; if (!old_nd->dentry->d_inode) return -ENOENT;
Review
Quoted 10 lines
(quoted diff) +4
-0if (!S_ISREG(old_nd->dentry->d_inode->i_mode)) return -EINVAL; /* FIXME: replace with proper permission check */ if (new_dentry->d_inode) return -EEXIST; + if(old_nd->dentry->d_inode->i_op->copy) { + ret = old_dir->i_op->copy(old_nd->dentry, + mode, new_dentry); + }
Shouldn't it be rather
if (old_nd->dentry->d_inode->i_op->copy) return old_nd->dentry->d_inode->i_op->copy(old_nd->dentry, mode, new_dentry);
or something similar? The copy() effectively replaces the complete create/sendfile/possibly-unlink series.
Quoted 14 lines
if(!ret)
return ret;
else
ret = vfs_create(new_nd->dentry->d_inode,
new_dentry, mode, new_nd);
if (ret)
return ret;
ret = copy_data(old_nd->dentry, old_nd->mnt, new_dentry,
new_nd->mnt);
if (ret) {
int error = vfs_unlink(new_nd->dentry->d_inode,Quoted 9 lines
new_dentry);
BUG_ON(error);
/* FIXME: not sure if there are return value we
should not BUG()
* on */
}
return ret;
}Jörn
Signature · 3 lines
The grand essentials of happiness are: something to do, something to love, and something to hope for. -- Allan K. Chalmers
Quoted 9 lines · Jörn Engel
Shouldn't it be rather
if (old_nd->dentry->d_inode->i_op->copy) return old_nd->dentry->d_inode->i_op->copy(old_nd->dentry, mode, new_dentry);or something similar? The
copy()effectively replaces the complete create/sendfile/possibly-unlink series.
In some network protocols the client does not know whether the server wants to support copy operation or not (perhaps if the files were on different server partitions the server might return an error e.g), in those cases the filesystem client could return error not supported or equivalent and the remainder of your function is executed doing the copy the harder way (open/read/close create/write/close) but still faster a few percent faster than before your patch.
Quoted 11 lines · Steve French
Quoted 8 lines · Jörn Engel
Shouldn't it be rather
if (old_nd->dentry->d_inode->i_op->copy) return old_nd->dentry->d_inode->i_op->copy(old_nd->dentry, mode, new_dentry);or something similar? The
copy()effectively replaces the complete create/sendfile/possibly-unlink series.
Quoted 7 lines
In some network protocols the client does not know whether the server wants to support copy operation or not (perhaps if the files were on different server partitions the server might return an error e.g), in those cases the filesystem client could return error not supported or equivalent and the remainder of your function is executed doing the copy the harder way (open/read/close create/write/close) but still faster a few percent faster than before your patch.
Makes sense. Then something like
if (old_nd->dentry->d_inode->i_op->copy) {
ret = old_nd->dentry->d_inode->i_op->copy(old_nd->dentry,
mode, new_dentry);
if (ret != -ENOSYS)
return ret;
}Also, would it be possible to do essentially the same with sendfile()? That should bring roughly the same speedup for disk based filesystems, and would be a bit more general.
Jörn
Signature · 2 lines
Don't patch bad code, rewrite it. -- Kernigham and Pike, according to Rusty