NFS based on file size issue sync copy or fallback to generic copy offload
authorOlga Kornievskaia <kolga@netapp.com>
Wed, 3 Jul 2019 14:38:02 +0000 (10:38 -0400)
committerOlga Kornievskaia <olga.kornievskaia@gmail.com>
Wed, 9 Oct 2019 16:06:22 +0000 (12:06 -0400)
For small file sizes, it make sense to issue a synchronous copy (and
save an RPC callback operation). Also, for the inter copy offload,
copy len must be larger than the cost of doing a mount between the
destination and source server (14RPCs are sent during 4.x mount).

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
fs/nfs/nfs42.h
fs/nfs/nfs42proc.c
fs/nfs/nfs4file.c

index 02e3810cd889b30d31c5e2a627b00f6a0d48857b..c891af949886f81bbaeab700b7fe473aa00add55 100644 (file)
@@ -16,7 +16,7 @@
 #ifdef CONFIG_NFS_V4_2
 int nfs42_proc_allocate(struct file *, loff_t, loff_t);
 ssize_t nfs42_proc_copy(struct file *, loff_t, struct file *, loff_t, size_t,
-                       struct nl4_server *, nfs4_stateid *);
+                       struct nl4_server *, nfs4_stateid *, bool);
 int nfs42_proc_deallocate(struct file *, loff_t, loff_t);
 loff_t nfs42_proc_llseek(struct file *, loff_t, int);
 int nfs42_proc_layoutstats_generic(struct nfs_server *,
index 9c7feacb03581a0c11c4ccfa40421ff4ca078c9e..aab6b7b6a24a4ce1efe073c94f36399519e6c55a 100644 (file)
@@ -357,7 +357,7 @@ out:
 ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src,
                        struct file *dst, loff_t pos_dst, size_t count,
                        struct nl4_server *nss,
-                       nfs4_stateid *cnr_stateid)
+                       nfs4_stateid *cnr_stateid, bool sync)
 {
        struct nfs_server *server = NFS_SERVER(file_inode(dst));
        struct nfs_lock_context *src_lock;
@@ -368,7 +368,7 @@ ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src,
                .dst_fh         = NFS_FH(file_inode(dst)),
                .dst_pos        = pos_dst,
                .count          = count,
-               .sync           = false,
+               .sync           = sync,
        };
        struct nfs42_copy_res res;
        struct nfs4_exception src_exception = {
index 2af30b7f5bfd0ec53970abd5c2d38e681ccd2c07..8978325649231ffbdf0bca7031562d5bf7300afd 100644 (file)
@@ -138,6 +138,7 @@ static ssize_t __nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
        struct nl4_server *nss = NULL;
        nfs4_stateid *cnrs = NULL;
        ssize_t ret;
+       bool sync = false;
 
        /* Only offload copy if superblock is the same */
        if (file_inode(file_in)->i_sb != file_inode(file_out)->i_sb)
@@ -146,8 +147,21 @@ static ssize_t __nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
                return -EOPNOTSUPP;
        if (file_inode(file_in) == file_inode(file_out))
                return -EOPNOTSUPP;
+       /* if the copy size if smaller than 2 RPC payloads, make it
+        * synchronous
+        */
+       if (count <= 2 * NFS_SERVER(file_inode(file_in))->rsize)
+               sync = true;
 retry:
        if (!nfs42_files_from_same_server(file_in, file_out)) {
+               /* for inter copy, if copy size if smaller than 12 RPC
+                * payloads, fallback to traditional copy. There are
+                * 14 RPCs during an NFSv4.x mount between source/dest
+                * servers.
+                */
+               if (sync ||
+                       count <= 14 * NFS_SERVER(file_inode(file_in))->rsize)
+                       return -EOPNOTSUPP;
                cn_resp = kzalloc(sizeof(struct nfs42_copy_notify_res),
                                GFP_NOFS);
                if (unlikely(cn_resp == NULL))
@@ -162,7 +176,7 @@ retry:
                cnrs = &cn_resp->cnr_stateid;
        }
        ret = nfs42_proc_copy(file_in, pos_in, file_out, pos_out, count,
-                               nss, cnrs);
+                               nss, cnrs, sync);
 out:
        kfree(cn_resp);
        if (ret == -EAGAIN)