NFS: Optimise the default readahead size
authorTrond Myklebust <trondmy@gmail.com>
Sun, 22 Sep 2019 19:07:49 +0000 (15:07 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Tue, 24 Sep 2019 19:58:20 +0000 (15:58 -0400)
In the years since the max readahead size was fixed in NFS, a number of
things have happened:
- Users can now set the value directly using /sys/class/bdi
- NFS max supported block sizes have increased by several orders of
  magnitude from 64K to 1MB.
- Disk access latencies are orders of magnitude faster due to SSD + NVME.

In particular note that if the server is advertising 1MB as the optimal
read size, as that will set the readahead size to 15MB.
Let's therefore adjust down, and try to default to VM_READAHEAD_PAGES.
However let's inform the VM about our preferred block size so that it
can choose to round up in cases where that makes sense.

Reported-by: Alkis Georgopoulos <alkisg@gmail.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/internal.h
fs/nfs/super.c

index a2346a2f8361d56c0608af517adf5c74a7d52404..4b946e6a052f3ec3fe9e0af78f3a1877e17a6050 100644 (file)
@@ -16,14 +16,6 @@ extern const struct export_operations nfs_export_ops;
 
 struct nfs_string;
 
-/* Maximum number of readahead requests
- * FIXME: this should really be a sysctl so that users may tune it to suit
- *        their needs. People that do NFS over a slow network, might for
- *        instance want to reduce it to something closer to 1 for improved
- *        interactive response.
- */
-#define NFS_MAX_READAHEAD      (RPC_DEF_SLOT_TABLE - 1)
-
 static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
 {
        if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
index 703f595dce90c1bfb8dfad1ca589221cc7f6f0b5..c96194e286924e3956e8b10ffb8ea3fa205a3f2a 100644 (file)
@@ -2627,6 +2627,13 @@ int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,
 }
 EXPORT_SYMBOL_GPL(nfs_clone_sb_security);
 
+static void nfs_set_readahead(struct backing_dev_info *bdi,
+                             unsigned long iomax_pages)
+{
+       bdi->ra_pages = VM_READAHEAD_PAGES;
+       bdi->io_pages = iomax_pages;
+}
+
 struct dentry *nfs_fs_mount_common(struct nfs_server *server,
                                   int flags, const char *dev_name,
                                   struct nfs_mount_info *mount_info,
@@ -2669,7 +2676,7 @@ struct dentry *nfs_fs_mount_common(struct nfs_server *server,
                        mntroot = ERR_PTR(error);
                        goto error_splat_super;
                }
-               s->s_bdi->ra_pages = server->rpages * NFS_MAX_READAHEAD;
+               nfs_set_readahead(s->s_bdi, server->rpages);
                server->super = s;
        }