Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1998784pxb; Sat, 21 Nov 2020 05:32:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcAMiSqSUruPV/7gEaonFvExkkEzX6kpF7zgBh64LBl8QUahPemvJI+x6Q7LU0UksZywbk X-Received: by 2002:a17:906:e285:: with SMTP id gg5mr37784424ejb.7.1605965532516; Sat, 21 Nov 2020 05:32:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605965532; cv=none; d=google.com; s=arc-20160816; b=TWlr/RDhtloydc6MEGwsnZ1CmdxussCayEGYrHWmLnTxyZo6EqVeEW6jUkg4qHIc+O azoRIxusomGg6b/wTkL61X55Vy0yjCAGLppgRLDifsscHyeAh9sqTpJy1icO5Z+dQtAE b3ZpqIkYhgs2nfjDFLwL7OxwF4T5fZG5i/SFPacxfn7Zo+F9hK9Ns83rqAxmnUL5mXCH ZnwpoFkDWBW9fcPMnXGh8yN1qSOfwDb16HXTGnBX7+VWGtYUoVKhM7Vav5MUpoGHrJWt bFdFbSIyr4BHALdMdj/HZFtpxm32DJRvNGw9DQoabcoPgRV3WlRblutkwanT1kNlJfmK n8NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=vDVsgFCkq6y36btUrg7x7SEJfP+WOeJycmq/AhpKb8E=; b=G4A3UXR/ghyFVanEKSG+uNBy0NUQaNZoXudw3SNwCHzcnsfkkLh1XpkR7yfiL5Wfot wzt5/QWVPbGSXRkDmfcKWwF9Gpj06b00go/EJXMwNxE2s/gejA+jlarmX2F9pdsOUmSF EXj6WtHC7sI/z0FuG2xzZrgXkw+rRJkOSbxC4r7HOWpYjjjB3M7rYbX5dxrxhC4Fjewl e+2y9fjD1rOi2GxsSs7C1QeUfsHFB3uWO1WcJkNvuLiJoftQZP9RU250DNTn+AhNR/Mh kW1yOdfJmAx8V4UNxGK7mqB+Stuu1ZT3jRc0kAklzXZnRLQ4lQlwjN8NEoFRYHKpYxw4 P9Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EL16YtIv; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n11si3894668ejg.660.2020.11.21.05.31.49; Sat, 21 Nov 2020 05:32:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EL16YtIv; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727837AbgKUN3r (ORCPT + 99 others); Sat, 21 Nov 2020 08:29:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:53776 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726175AbgKUN3r (ORCPT ); Sat, 21 Nov 2020 08:29:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605965385; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=vDVsgFCkq6y36btUrg7x7SEJfP+WOeJycmq/AhpKb8E=; b=EL16YtIvGwImMY1tED91uV1LCXpQGCuOtJdQBRV/cd3EDFkcN1PIkTsOfiNcjmmmGFbl4b 6Smtu9YoOFZOR0ILjeXAt3arYXH38qzTzwILAMVjiRdra47vn8sIOUd/i/mnUJGAWcMIl3 szHUim2yD8+qyimOftihoL70DgIknjs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-40-Fjed01rPO7Ciw_fDX-0ySw-1; Sat, 21 Nov 2020 08:29:43 -0500 X-MC-Unique: Fjed01rPO7Ciw_fDX-0ySw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DF541005D69; Sat, 21 Nov 2020 13:29:42 +0000 (UTC) Received: from dwysocha.rdu.csb (ovpn-112-41.rdu2.redhat.com [10.10.112.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C5E55C224; Sat, 21 Nov 2020 13:29:40 +0000 (UTC) From: Dave Wysochanski To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org, dhowells@redhat.com Subject: [PATCH v1 11/13] NFS: Convert readpage to readahead and use netfs_readahead for fscache Date: Sat, 21 Nov 2020 08:29:33 -0500 Message-Id: <1605965373-24850-1-git-send-email-dwysocha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The new FS-Cache API does not have a readpages equivalent function, and instead of fscache_read_or_alloc_pages() it implements a readahead function, netfs_readahead(). Call netfs_readahead() if fscache is enabled, and if not, utilize readahead_page() to run through the pages needed calling readpage_async_filler(). Signed-off-by: Dave Wysochanski --- fs/nfs/file.c | 2 +- fs/nfs/fscache.c | 49 ++++++++-------------------------------------- fs/nfs/fscache.h | 25 +++++++++-------------- fs/nfs/read.c | 32 +++++++++++++++--------------- include/linux/nfs_fs.h | 3 +-- include/linux/nfs_iostat.h | 2 +- 6 files changed, 36 insertions(+), 77 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index ba988e639037..ed3d6fbed8d1 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -519,7 +519,7 @@ static void nfs_swap_deactivate(struct file *file) const struct address_space_operations nfs_file_aops = { .readpage = nfs_readpage, - .readpages = nfs_readpages, + .readahead = nfs_readahead, .set_page_dirty = __set_page_dirty_nobuffers, .writepage = nfs_writepage, .writepages = nfs_writepages, diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c index 782ef2a8733b..917b92f5461b 100644 --- a/fs/nfs/fscache.c +++ b/fs/nfs/fscache.c @@ -450,51 +450,18 @@ int __nfs_readpage_from_fscache(struct file *filp, /* * Retrieve a set of pages from fscache */ -int __nfs_readpages_from_fscache(struct nfs_open_context *ctx, - struct inode *inode, - struct address_space *mapping, - struct list_head *pages, - unsigned *nr_pages) +int __nfs_readahead_from_fscache(struct nfs_readdesc *desc, + struct readahead_control *rac) { - unsigned npages = *nr_pages; - int ret; + struct inode *inode = rac->mapping->host; - dfprintk(FSCACHE, "NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n", - nfs_i_fscache(inode), npages, inode); - - ret = fscache_read_or_alloc_pages(nfs_i_fscache(inode), - mapping, pages, nr_pages, - nfs_readpage_from_fscache_complete, - ctx, - mapping_gfp_mask(mapping)); - if (*nr_pages < npages) - nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_OK, - npages); - if (*nr_pages > 0) - nfs_add_fscache_stats(inode, NFSIOS_FSCACHE_PAGES_READ_FAIL, - *nr_pages); + dfprintk(FSCACHE, "NFS: nfs_readahead_from_fscache (0x%p/0x%p)\n", + nfs_i_fscache(inode), inode); - switch (ret) { - case 0: /* read submitted to the cache for all pages */ - BUG_ON(!list_empty(pages)); - BUG_ON(*nr_pages != 0); - dfprintk(FSCACHE, - "NFS: nfs_getpages_from_fscache: submitted\n"); + netfs_readahead(rac, &nfs_fscache_req_ops, desc); - return ret; - - case -ENOBUFS: /* some pages aren't cached and can't be */ - case -ENODATA: /* some pages aren't cached */ - dfprintk(FSCACHE, - "NFS: nfs_getpages_from_fscache: no page: %d\n", ret); - return 1; - - default: - dfprintk(FSCACHE, - "NFS: nfs_getpages_from_fscache: ret %d\n", ret); - } - - return ret; + /* FIXME: NFSIOS_NFSIOS_FSCACHE_ stats */ + return 0; } /* diff --git a/fs/nfs/fscache.h b/fs/nfs/fscache.h index 93747bcd4399..446a889433a8 100644 --- a/fs/nfs/fscache.h +++ b/fs/nfs/fscache.h @@ -94,11 +94,11 @@ struct nfs_fscache_inode_auxdata { extern int __nfs_readpage_from_fscache(struct file *filp, struct page *page, struct nfs_readdesc *desc); -extern int __nfs_readpages_from_fscache(struct nfs_open_context *, - struct inode *, struct address_space *, - struct list_head *, unsigned *); +extern int __nfs_readahead_from_fscache(struct nfs_readdesc *desc, + struct readahead_control *rac); extern void __nfs_read_completion_to_fscache(struct nfs_pgio_header *hdr, unsigned long bytes); + /* * Retrieve a page from an inode data storage object. */ @@ -114,15 +114,11 @@ static inline int nfs_readpage_from_fscache(struct file *filp, /* * Retrieve a set of pages from an inode data storage object. */ -static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx, - struct inode *inode, - struct address_space *mapping, - struct list_head *pages, - unsigned *nr_pages) +static inline int nfs_readahead_from_fscache(struct nfs_readdesc *desc, + struct readahead_control *rac) { - if (NFS_I(inode)->fscache) - return __nfs_readpages_from_fscache(ctx, inode, mapping, pages, - nr_pages); + if (NFS_I(rac->mapping->host)->fscache) + return __nfs_readahead_from_fscache(desc, rac); return -ENOBUFS; } @@ -195,11 +191,8 @@ static inline int nfs_readpage_from_fscache(struct file *filp, { return -ENOBUFS; } -static inline int nfs_readpages_from_fscache(struct nfs_open_context *ctx, - struct inode *inode, - struct address_space *mapping, - struct list_head *pages, - unsigned *nr_pages) +static inline int nfs_readahead_from_fscache(struct nfs_readdesc *desc, + struct readahead_control *rac) { return -ENOBUFS; } diff --git a/fs/nfs/read.c b/fs/nfs/read.c index 7a76ab474fe0..da44ce68488c 100644 --- a/fs/nfs/read.c +++ b/fs/nfs/read.c @@ -390,50 +390,50 @@ int nfs_readpage(struct file *filp, struct page *page) return ret; } -int nfs_readpages(struct file *filp, struct address_space *mapping, - struct list_head *pages, unsigned nr_pages) +void nfs_readahead(struct readahead_control *rac) { struct nfs_readdesc desc; - struct inode *inode = mapping->host; + struct inode *inode = rac->mapping->host; + struct page *page; int ret; - dprintk("NFS: nfs_readpages (%s/%Lu %d)\n", - inode->i_sb->s_id, - (unsigned long long)NFS_FILEID(inode), - nr_pages); + dprintk("NFS: %s (%s/%llu %lld)\n", __func__, + inode->i_sb->s_id, + (unsigned long long)NFS_FILEID(inode), + readahead_length(rac)); nfs_inc_stats(inode, NFSIOS_VFSREADPAGES); ret = -ESTALE; if (NFS_STALE(inode)) - goto out; + return; - if (filp == NULL) { + if (rac->file == NULL) { ret = -EBADF; desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ); if (desc.ctx == NULL) - goto out; + return; } else - desc.ctx = get_nfs_open_context(nfs_file_open_context(filp)); + desc.ctx = get_nfs_open_context(nfs_file_open_context(rac->file)); /* attempt to read as many of the pages as possible from the cache * - this returns -ENOBUFS immediately if the cookie is negative */ - ret = nfs_readpages_from_fscache(desc.ctx, inode, mapping, - pages, &nr_pages); + ret = nfs_readahead_from_fscache(&desc, rac); if (ret == 0) goto read_complete; /* all pages were read */ nfs_pageio_init_read(&desc.pgio, inode, false, &nfs_async_read_completion_ops); - ret = read_cache_pages(mapping, pages, readpage_async_filler, &desc); + while ((page = readahead_page(rac))) { + ret = readpage_async_filler(&desc, page); + put_page(page); + } nfs_pageio_complete_read(&desc.pgio, inode); read_complete: put_nfs_open_context(desc.ctx); -out: - return ret; } int __init nfs_init_readpagecache(void) diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index abe6416236c9..217900eaf456 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -563,8 +563,7 @@ extern int nfs_access_get_cached(struct inode *inode, const struct cred *cred, s * linux/fs/nfs/read.c */ extern int nfs_readpage(struct file *, struct page *); -extern int nfs_readpages(struct file *, struct address_space *, - struct list_head *, unsigned); +extern void nfs_readahead(struct readahead_control *rac); /* * inline functions diff --git a/include/linux/nfs_iostat.h b/include/linux/nfs_iostat.h index 027874c36c88..8baf8fb7551d 100644 --- a/include/linux/nfs_iostat.h +++ b/include/linux/nfs_iostat.h @@ -53,7 +53,7 @@ * NFS page counters * * These count the number of pages read or written via nfs_readpage(), - * nfs_readpages(), or their write equivalents. + * nfs_readahead(), or their write equivalents. * * NB: When adding new byte counters, please include the measured * units in the name of each byte counter to help users of this -- 1.8.3.1