From patchwork Wed Jan 20 16:59:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032945 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D270C433E9 for ; Wed, 20 Jan 2021 17:05:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6007A22CE3 for ; Wed, 20 Jan 2021 17:05:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391623AbhATRFU (ORCPT ); Wed, 20 Jan 2021 12:05:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60175 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391303AbhATRBe (ORCPT ); Wed, 20 Jan 2021 12:01:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I3SFxsb7at1NLkvLBwhkWtXDZDEHXS6qkMyuJFUQUcA=; b=aGr9MutRrf/hSn6vB/DP3aWfPQ6tLRUiqKj7gnDrN/gwJVAjfuKMQU5ftxhkO7QAbSCBLF sb72/6BcNdqTa1rngDBEUF5foiSIaC/AcPnc5SR0XjtzT8dIlVAIDXRe24FFRMsWuGhhHo axF/Vgv+zwCqMqk0BJZok1R787IfOTo= 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-502-JKJMqBr3PMeouaemXeFrRw-1; Wed, 20 Jan 2021 11:59:55 -0500 X-MC-Unique: JKJMqBr3PMeouaemXeFrRw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0642F8735C2 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1B735D9C2 for ; Wed, 20 Jan 2021 16:59:54 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id 6EE2F10E3EE7; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 01/10] NFS: save the directory's change attribute on pagecache pages Date: Wed, 20 Jan 2021 11:59:45 -0500 Message-Id: <628bd528d5b2e8e714e9c0eeb9d891713fc885b6.1611160120.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org After a pagecache page has been filled with entries, set PagePrivate and the directory's change attribute on the page. This will help us perform per-page invalidations in a later patch. Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index ef827ae193d2..ade73ca42a52 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -53,6 +53,9 @@ static int nfs_closedir(struct inode *, struct file *); static int nfs_readdir(struct file *, struct dir_context *); static int nfs_fsync_dir(struct file *, loff_t, loff_t, int); static loff_t nfs_llseek_dir(struct file *, loff_t, int); +static void nfs_readdir_invalidatepage(struct page *, + unsigned int, unsigned int); +static int nfs_readdir_clear_page(struct page*, gfp_t); static void nfs_readdir_clear_array(struct page*); const struct file_operations nfs_dir_operations = { @@ -65,6 +68,8 @@ const struct file_operations nfs_dir_operations = { }; const struct address_space_operations nfs_dir_aops = { + .invalidatepage = nfs_readdir_invalidatepage, + .releasepage = nfs_readdir_clear_page, .freepage = nfs_readdir_clear_array, }; @@ -181,6 +186,27 @@ static void nfs_readdir_page_init_array(struct page *page, u64 last_cookie) array->last_cookie = last_cookie; array->cookies_are_ordered = 1; kunmap_atomic(array); + set_page_private(page, 0); +} + +static int +nfs_readdir_clear_page(struct page *page, gfp_t gfp_mask) +{ + detach_page_private(page); + return 1; +} + +static void +nfs_readdir_invalidatepage(struct page *page, unsigned int offset, + unsigned int length) +{ + nfs_readdir_clear_page(page, GFP_KERNEL); +} + +static void +nfs_readdir_set_page_verifier(struct page *page, unsigned long verf) +{ + attach_page_private(page, (void *)verf); } /* @@ -744,6 +770,8 @@ static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc, if (status != -ENOSPC) continue; + nfs_readdir_set_page_verifier(page, desc->dir_verifier); + if (page->mapping != mapping) { if (!--narrays) break; @@ -770,10 +798,13 @@ static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc, case -EBADCOOKIE: if (entry->eof) { nfs_readdir_page_set_eof(page); + nfs_readdir_set_page_verifier(page, desc->dir_verifier); status = 0; } break; case -ENOSPC: + nfs_readdir_set_page_verifier(page, desc->dir_verifier); + fallthrough; case -EAGAIN: status = 0; break; From patchwork Wed Jan 20 16:59:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 800FBC433DB for ; Wed, 20 Jan 2021 17:04:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49127233E2 for ; Wed, 20 Jan 2021 17:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391610AbhATRDU (ORCPT ); Wed, 20 Jan 2021 12:03:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22712 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391591AbhATRBf (ORCPT ); Wed, 20 Jan 2021 12:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CKFsOhTznFM6N9AwV6ZGfLquZjyVley8z2wFoVGINKM=; b=KLN+x2jvoQ5fwtoK6tKpopWZe5SNFlQ5T2Ug53tK0sANRQXT7NYRHvtfd1p+Q1oFJ0sTCC NOvOWJucp6WalgjsHfywYiQSF3vkHIEd8JJ2Bu+rjP4FO6Pd00V1dVqrBBDx4TnLoYAMEH v6X9joE0sK1m8TAAh3iXRi7tV3Tk5is= 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-dzEqNj69OLOavYZZU8Hh3Q-1; Wed, 20 Jan 2021 11:59:55 -0500 X-MC-Unique: dzEqNj69OLOavYZZU8Hh3Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 196FD8030A2 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id E053E5D6DC for ; Wed, 20 Jan 2021 16:59:54 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id 7982710E3EEB; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 02/10] NFSv4: Send GETATTR with READDIR Date: Wed, 20 Jan 2021 11:59:46 -0500 Message-Id: <2c57b6f0405c48e4789e9afc56b12f1f64b796b1.1611160120.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org For each batch of entries, track whether the directory has changed. We can use this information to better manage the cache when reading long directories. Signed-off-by: Benjamin Coddington --- fs/nfs/nfs42proc.c | 2 +- fs/nfs/nfs4proc.c | 27 +++++++++++++++++++-------- fs/nfs/nfs4xdr.c | 6 ++++++ include/linux/nfs_fs_sb.h | 5 +++++ include/linux/nfs_xdr.h | 2 ++ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c index f3fd935620fc..576296728889 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -1011,7 +1011,7 @@ static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f, .src_offset = src_offset, .dst_offset = dst_offset, .count = count, - .dst_bitmask = server->cache_consistency_bitmask, + .dst_bitmask = server->cache_consistency_bitmask_nl, }; struct nfs42_clone_res res = { .server = server, diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 2f4679a62712..5a2ea98dc1a6 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3654,7 +3654,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) if (calldata->arg.fmode == 0 || calldata->arg.fmode == FMODE_READ) { /* Close-to-open cache consistency revalidation */ if (!nfs4_have_delegation(inode, FMODE_READ)) { - calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask; + calldata->arg.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask_nl; nfs4_bitmask_adjust(calldata->arg.bitmask, inode, NFS_SERVER(inode), NULL); } else calldata->arg.bitmask = NULL; @@ -3882,7 +3882,10 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; - server->cache_consistency_bitmask[2] = 0; + server->cache_consistency_bitmask[2] = res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL; + + memcpy(server->cache_consistency_bitmask_nl, server->cache_consistency_bitmask, sizeof(server->cache_consistency_bitmask)); + server->cache_consistency_bitmask_nl[2] = 0; /* Avoid a regression due to buggy server */ for (i = 0; i < ARRAY_SIZE(res.exclcreat_bitmask); i++) @@ -4451,7 +4454,7 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry res.fattr = nfs_alloc_fattr(); if (res.fattr == NULL) return -ENOMEM; - args.bitmask = server->cache_consistency_bitmask; + args.bitmask = server->cache_consistency_bitmask_nl; } status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); if (!status) { @@ -4980,14 +4983,19 @@ static int _nfs4_proc_readdir(struct nfs_readdir_arg *nr_arg, .rpc_resp = &res, .rpc_cred = nr_arg->cred, }; - int status; + int status = -ENOMEM; dprintk("%s: dentry = %pd2, cookie = %llu\n", __func__, nr_arg->dentry, (unsigned long long)nr_arg->cookie); if (!(server->caps & NFS_CAP_SECURITY_LABEL)) - args.bitmask = server->attr_bitmask_nl; + args.bitmask = server->cache_consistency_bitmask_nl; else - args.bitmask = server->attr_bitmask; + args.bitmask = server->cache_consistency_bitmask; + + res.dir_attr = nfs_alloc_fattr(); + if (res.dir_attr == NULL) + goto out; + res.server = NFS_SERVER(dir); nfs4_setup_readdir(nr_arg->cookie, nr_arg->verf, nr_arg->dentry, &args); res.pgbase = args.pgbase; @@ -5000,6 +5008,9 @@ static int _nfs4_proc_readdir(struct nfs_readdir_arg *nr_arg, nfs_invalidate_atime(dir); + nfs_refresh_inode(dir, res.dir_attr); + nfs_free_fattr(res.dir_attr); +out: dprintk("%s: returns %d\n", __func__, status); return status; } @@ -5465,7 +5476,7 @@ static void nfs4_proc_write_setup(struct nfs_pgio_header *hdr, hdr->args.bitmask = NULL; hdr->res.fattr = NULL; } else { - hdr->args.bitmask = server->cache_consistency_bitmask; + hdr->args.bitmask = server->cache_consistency_bitmask_nl; nfs4_bitmask_adjust(hdr->args.bitmask, hdr->inode, server, NULL); } @@ -6505,7 +6516,7 @@ static int _nfs4_proc_delegreturn(struct inode *inode, const struct cred *cred, data->args.fhandle = &data->fh; data->args.stateid = &data->stateid; - data->args.bitmask = server->cache_consistency_bitmask; + data->args.bitmask = server->cache_consistency_bitmask_nl; nfs4_bitmask_adjust(data->args.bitmask, inode, server, NULL); nfs_copy_fh(&data->fh, NFS_FH(inode)); nfs4_stateid_copy(&data->stateid, stateid); diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index ac6b79ee9355..02a3df42d61d 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -459,10 +459,12 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req, #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \ encode_sequence_maxsz + \ encode_putfh_maxsz + \ + encode_getattr_maxsz + \ encode_readdir_maxsz) #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \ decode_sequence_maxsz + \ decode_putfh_maxsz + \ + decode_getattr_maxsz + \ decode_readdir_maxsz) #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \ encode_sequence_maxsz + \ @@ -2519,6 +2521,7 @@ static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, encode_compound_hdr(xdr, req, &hdr); encode_sequence(xdr, &args->seq_args, &hdr); encode_putfh(xdr, args->fh, &hdr); + encode_getfattr(xdr, args->bitmask, &hdr); encode_readdir(xdr, args, req, &hdr); rpc_prepare_reply_pages(req, args->pages, args->pgbase, @@ -6703,6 +6706,9 @@ static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, if (status) goto out; status = decode_putfh(xdr); + if (status) + goto out; + status = decode_getfattr(xdr, res->dir_attr, res->server); if (status) goto out; status = decode_readdir(xdr, rqstp, res); diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index 38e60ec742df..8b20ff42c22d 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -211,6 +211,11 @@ struct nfs_server { of change attribute, size, ctime and mtime attributes supported by the server */ + u32 cache_consistency_bitmask_nl[3]; + /* V4 bitmask representing the subset + of change attribute, size, ctime + and mtime attributes supported by + the server excluding label support */ u32 acl_bitmask; /* V4 bitmask representing the ACEs that are supported on this filesystem */ diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index 3327239fa2f9..de12053ed4d3 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h @@ -1139,6 +1139,8 @@ struct nfs4_readdir_res { struct nfs4_sequence_res seq_res; nfs4_verifier verifier; unsigned int pgbase; + struct nfs_fattr *dir_attr; + const struct nfs_server *server; }; struct nfs4_readlink { From patchwork Wed Jan 20 16:59:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 763EAC433DB for ; Wed, 20 Jan 2021 17:03:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4172C2137B for ; Wed, 20 Jan 2021 17:03:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391718AbhATRCw (ORCPT ); Wed, 20 Jan 2021 12:02:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22727 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391570AbhATRBf (ORCPT ); Wed, 20 Jan 2021 12:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hrYfo5cLa5+fzVKRk2737HUhIfYeK9iKxnyK0YA++cU=; b=OuOdndnnrwZ2uBb99t6J4FNqad/S6+rQHf/8L3GdRoZT0L0ZP+mDqoc4AhkotENI7FB1mF yZXeBOSAhde8lYToYVOWHQeMKW+COvxan0wUH+fWyRYnewJVgVexn+CqKEVv+JZq3kmY8K jWpVfW24K5YHBBbZk10HkA2gMuLE9X4= 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-355-q2OSQLxGMayz6iMCbA698A-1; Wed, 20 Jan 2021 11:59:56 -0500 X-MC-Unique: q2OSQLxGMayz6iMCbA698A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 338478030A5 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02CD210023B9 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id 92A1910E3EF2; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 03/10] NFS: Add a struct to track readdir pagecache location Date: Wed, 20 Jan 2021 11:59:47 -0500 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Directory entries in the NFS readdir pagecache are referenced by their cookie value and offset. By defining a structure to group these values, we'll simplify changes to validate pagecache pages in patches that follow. Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 34 +++++++++++++++++----------------- include/linux/nfs_fs.h | 6 ++++++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index ade73ca42a52..6626aff9f54d 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -154,10 +154,9 @@ struct nfs_readdir_descriptor { struct file *file; struct page *page; struct dir_context *ctx; - pgoff_t page_index; u64 dir_cookie; - u64 last_cookie; u64 dup_cookie; + struct nfs_dir_page_cursor pgc; loff_t current_index; loff_t prev_index; @@ -166,7 +165,6 @@ struct nfs_readdir_descriptor { unsigned long timestamp; unsigned long gencount; unsigned long attr_gencount; - unsigned int cache_entry_index; signed char duped; bool plus; bool eof; @@ -426,7 +424,7 @@ static int nfs_readdir_search_for_pos(struct nfs_cache_array *array, index = (unsigned int)diff; desc->dir_cookie = array->array[index].cookie; - desc->cache_entry_index = index; + desc->pgc.entry_index = index; return 0; out_eof: desc->eof = true; @@ -494,7 +492,7 @@ static int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, else desc->ctx->pos = new_pos; desc->prev_index = new_pos; - desc->cache_entry_index = i; + desc->pgc.entry_index = i; return 0; } } @@ -521,9 +519,9 @@ static int nfs_readdir_search_array(struct nfs_readdir_descriptor *desc) status = nfs_readdir_search_for_cookie(array, desc); if (status == -EAGAIN) { - desc->last_cookie = array->last_cookie; + desc->pgc.index_cookie = array->last_cookie; desc->current_index += array->size; - desc->page_index++; + desc->pgc.page_index++; } kunmap_atomic(array); return status; @@ -927,8 +925,8 @@ static struct page * nfs_readdir_page_get_cached(struct nfs_readdir_descriptor *desc) { return nfs_readdir_page_get_locked(desc->file->f_mapping, - desc->page_index, - desc->last_cookie); + desc->pgc.page_index, + desc->pgc.index_cookie); } /* @@ -952,7 +950,7 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc) nfs_readdir_page_unlock_and_put_cached(desc); if (res == -EBADCOOKIE || res == -ENOTSYNC) { invalidate_inode_pages2(desc->file->f_mapping); - desc->page_index = 0; + desc->pgc.page_index = 0; return -EAGAIN; } return res; @@ -961,7 +959,7 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc) } res = nfs_readdir_search_array(desc); if (res == 0) { - nfsi->page_index = desc->page_index; + nfsi->page_index = desc->pgc.page_index; return 0; } nfs_readdir_page_unlock_and_put_cached(desc); @@ -991,10 +989,10 @@ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc) return -EBADCOOKIE; do { - if (desc->page_index == 0) { + if (desc->pgc.page_index == 0) { desc->current_index = 0; desc->prev_index = 0; - desc->last_cookie = 0; + desc->pgc.index_cookie = 0; } res = find_and_lock_cache_page(desc); } while (res == -EAGAIN); @@ -1012,7 +1010,7 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc) unsigned int i = 0; array = kmap(desc->page); - for (i = desc->cache_entry_index; i < array->size; i++) { + for (i = desc->pgc.entry_index; i < array->size; i++) { struct nfs_cache_array_entry *ent; ent = &array->array[i]; @@ -1070,8 +1068,10 @@ static int uncached_readdir(struct nfs_readdir_descriptor *desc) if (!arrays[0]) goto out; - desc->page_index = 0; - desc->last_cookie = desc->dir_cookie; + /* These values aren't referenced until we return, move/remove? */ + desc->pgc.page_index = 0; + desc->pgc.index_cookie = desc->dir_cookie; + desc->duped = 0; status = nfs_readdir_xdr_to_array(desc, desc->verf, verf, arrays, sz); @@ -1154,7 +1154,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) if (res == -ETOOSMALL && desc->plus) { clear_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags); nfs_zap_caches(inode); - desc->page_index = 0; + desc->pgc.page_index = 0; desc->plus = false; desc->eof = false; continue; diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 681ed98e4ba8..557e54b7d555 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -91,6 +91,12 @@ struct nfs_open_context { struct rcu_head rcu_head; }; +struct nfs_dir_page_cursor { + __u64 index_cookie; + pgoff_t page_index; + unsigned int entry_index; +}; + struct nfs_open_dir_context { struct list_head list; unsigned long attr_gencount; From patchwork Wed Jan 20 16:59:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E507DC433E0 for ; Wed, 20 Jan 2021 17:05:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7E6422CE3 for ; Wed, 20 Jan 2021 17:05:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391250AbhATRFT (ORCPT ); Wed, 20 Jan 2021 12:05:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50016 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391641AbhATRBf (ORCPT ); Wed, 20 Jan 2021 12:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OtOrA4Ys6J1Bm2BQBSBbJM8oiwkdvUMixkAPEQdoyU8=; b=LVo+HrhkW4+adRoLBSWxDt56udxlpD2nI5zzGJ1/2m/O0in+Cjoan1e2/jXtxQQP0nIdFD trrZLEBG8I7yqsXhw0v1BsYxq3sQuYapkVTiQN2pWu/dQ9iqWwHdP2cXPBsb8B1lf2THgP /HbxGk2Mz92V5fEtSPcJE2qkFxPadwk= 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-482-5HBUKXXdOwuanCod0c_NVA-1; Wed, 20 Jan 2021 11:59:56 -0500 X-MC-Unique: 5HBUKXXdOwuanCod0c_NVA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 398838735C3 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BC5560D11 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id A09E810E3EF8; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 04/10] NFS: Keep the readdir pagecache cursor updated Date: Wed, 20 Jan 2021 11:59:48 -0500 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Whenever we successfully locate our dir_cookie within the pagecache, or finish emitting entries to userspace, update the pagecache cursor. These updates provide marker points to validate pagecache pages in a future patch. Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 6626aff9f54d..7f6c84c8a412 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -150,6 +150,10 @@ struct nfs_cache_array { struct nfs_cache_array_entry array[]; }; +static const int cache_entries_per_page = + (PAGE_SIZE - sizeof(struct nfs_cache_array)) / + sizeof(struct nfs_cache_array_entry); + struct nfs_readdir_descriptor { struct file *file; struct page *page; @@ -251,6 +255,21 @@ static bool nfs_readdir_array_is_full(struct nfs_cache_array *array) return array->page_full; } +static void nfs_readdir_set_cursor(struct nfs_readdir_descriptor *desc, int index) +{ + desc->pgc.entry_index = index; + desc->pgc.index_cookie = desc->dir_cookie; +} + +static void nfs_readdir_cursor_next(struct nfs_dir_page_cursor *pgc, u64 cookie) +{ + pgc->index_cookie = cookie; + if (++pgc->entry_index == cache_entries_per_page) { + pgc->entry_index = 0; + pgc->page_index++; + } +} + /* * the caller is responsible for freeing qstr.name * when called by nfs_readdir_add_to_array, the strings will be freed in @@ -424,7 +443,7 @@ static int nfs_readdir_search_for_pos(struct nfs_cache_array *array, index = (unsigned int)diff; desc->dir_cookie = array->array[index].cookie; - desc->pgc.entry_index = index; + nfs_readdir_set_cursor(desc, index); return 0; out_eof: desc->eof = true; @@ -492,7 +511,7 @@ static int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, else desc->ctx->pos = new_pos; desc->prev_index = new_pos; - desc->pgc.entry_index = i; + nfs_readdir_set_cursor(desc, i); return 0; } } @@ -519,9 +538,9 @@ static int nfs_readdir_search_array(struct nfs_readdir_descriptor *desc) status = nfs_readdir_search_for_cookie(array, desc); if (status == -EAGAIN) { - desc->pgc.index_cookie = array->last_cookie; + desc->pgc.entry_index = array->size - 1; + nfs_readdir_cursor_next(&desc->pgc, array->last_cookie); desc->current_index += array->size; - desc->pgc.page_index++; } kunmap_atomic(array); return status; @@ -1035,6 +1054,8 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc) desc->eof = true; kunmap(desc->page); + desc->pgc.entry_index = i-1; + nfs_readdir_cursor_next(&desc->pgc, desc->dir_cookie); dfprintk(DIRCACHE, "NFS: nfs_do_filldir() filling ended @ cookie %llu\n", (unsigned long long)desc->dir_cookie); } From patchwork Wed Jan 20 16:59:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 548F4C433E9 for ; Wed, 20 Jan 2021 17:05:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29E07233ED for ; Wed, 20 Jan 2021 17:05:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390516AbhATRFR (ORCPT ); Wed, 20 Jan 2021 12:05:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31225 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391640AbhATRBf (ORCPT ); Wed, 20 Jan 2021 12:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GL8zcAAOe0LOWtBilVqSl72jNLzxzlhtqp7dMQVcB9E=; b=Prhb4AY8TFCJZcwOk3111Bb8PjHzsTxLSVkXgY9ZibKUV3xIRsi80BQYGRy/2F4Gepvx8K wSECTf7wg/beZGNxOM7lo7+e4I5QQAvG5Y9uiOHXTDQfjgcyKYoqbFpWpS6vllhCt10xMT B+wwGA30iTcUZ+q0W4q8FBzZ1UOdpZA= 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-86-sA0O7YooOLWUi1ARmmSdzQ-1; Wed, 20 Jan 2021 11:59:56 -0500 X-MC-Unique: sA0O7YooOLWUi1ARmmSdzQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F7908735C6 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CBAF5D9C2 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id AC16810E3EFE; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 05/10] NFS: readdir per-page cache validation Date: Wed, 20 Jan 2021 11:59:49 -0500 Message-Id: <885cd036b5400bd637b41003cdcae30ef28018fa.1611160121.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The current implementation of the readdir page cache requires that all pages contain entries ordered such that the cookie references lead to the first entry as represented by cookie 0. The invalidation of the cache truncates either the entire cache or every page beyond a known good page. A process that wants to emit directory entries near the end of a directory must first fill in any entries missing in the cache near the beginning of the directory in order that the entries decoded from READDIR XDR are appropriately page-aligned for any readers thay may come later (and for some error handling). However, if we're careful to check the alignment of directory entries on each page when the page is read, then it should be permissable to allow "disconnected" filling of the pagecache. Rather than requiring pagecache data to always be positionally aligned, we can instead validate that each page is properly aligned to the reading process' directory context. If it doesn't match our alignment, we'll refresh the entries in the page so that it does. This patch implements a check for validity for each page as it is obtained from the pagecache. A page is valid if it was filled within the client's current version of the directory and if the entries are aligned with the current reader's directory context. Invalid pages are re-filled by READDIR operations before being used to emit entries for the current reader. Signed-off-by: Benjamin Coddington Reported-by: kernel test robot --- fs/nfs/dir.c | 71 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 7f6c84c8a412..5fc22d97054a 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -188,13 +188,16 @@ static void nfs_readdir_page_init_array(struct page *page, u64 last_cookie) array->last_cookie = last_cookie; array->cookies_are_ordered = 1; kunmap_atomic(array); - set_page_private(page, 0); + if (page->mapping) + set_page_private(page, nfs_save_change_attribute(page->mapping->host)); + SetPageUptodate(page); } static int nfs_readdir_clear_page(struct page *page, gfp_t gfp_mask) { - detach_page_private(page); + unsigned long change_attr; + change_attr = (unsigned long)detach_page_private(page); return 1; } @@ -225,6 +228,15 @@ void nfs_readdir_clear_array(struct page *page) kfree(array->array[i].name); nfs_readdir_array_init(array); kunmap_atomic(array); + ClearPageUptodate(page); +} + +static void +nfs_readdir_recycle_page(struct page *page, u64 last_cookie) +{ + nfs_readdir_clear_array(page); + nfs_readdir_invalidatepage(page, 0, 0); + nfs_readdir_page_init_array(page, last_cookie); } static struct page * @@ -341,18 +353,47 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page) return ret; } +static bool +nfs_readdir_page_valid(struct page *page, unsigned int entry_index, u64 index_cookie) +{ + bool ret = false; + struct nfs_cache_array *array; + + if (page_private(page) != nfs_save_change_attribute(page->mapping->host)) + goto out; + + ret = true; + array = kmap_atomic(page); + + if (array->size == 0 && array->last_cookie == index_cookie) + goto out_unmap; + + if (array->size > entry_index && + array->array[entry_index].cookie == index_cookie) + goto out_unmap; + + ret = false; +out_unmap: + kunmap_atomic(array); +out: + return ret; +} + static struct page *nfs_readdir_page_get_locked(struct address_space *mapping, - pgoff_t index, u64 last_cookie) + struct nfs_dir_page_cursor *pgc) { struct page *page; - page = grab_cache_page(mapping, index); - if (page && !PageUptodate(page)) { - nfs_readdir_page_init_array(page, last_cookie); - if (invalidate_inode_pages2_range(mapping, index + 1, -1) < 0) - nfs_zap_mapping(mapping->host, mapping); - SetPageUptodate(page); - } + page = grab_cache_page(mapping, pgc->page_index); + + if (!page) + return page; + + if (!PageUptodate(page)) + nfs_readdir_page_init_array(page, pgc->index_cookie); + + if (!nfs_readdir_page_valid(page, pgc->entry_index, pgc->index_cookie)) + nfs_readdir_recycle_page(page, pgc->index_cookie); return page; } @@ -398,8 +439,12 @@ static struct page *nfs_readdir_page_get_next(struct address_space *mapping, pgoff_t index, u64 cookie) { struct page *page; + struct nfs_dir_page_cursor pgc = { + .page_index = index, + .index_cookie = cookie, + }; - page = nfs_readdir_page_get_locked(mapping, index, cookie); + page = nfs_readdir_page_get_locked(mapping, &pgc); if (page) { if (nfs_readdir_page_last_cookie(page) == cookie) return page; @@ -943,9 +988,7 @@ nfs_readdir_page_unlock_and_put_cached(struct nfs_readdir_descriptor *desc) static struct page * nfs_readdir_page_get_cached(struct nfs_readdir_descriptor *desc) { - return nfs_readdir_page_get_locked(desc->file->f_mapping, - desc->pgc.page_index, - desc->pgc.index_cookie); + return nfs_readdir_page_get_locked(desc->file->f_mapping, &desc->pgc); } /* From patchwork Wed Jan 20 16:59:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9DBAC433E0 for ; Wed, 20 Jan 2021 17:05:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A24B5233ED for ; Wed, 20 Jan 2021 17:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391612AbhATRFQ (ORCPT ); Wed, 20 Jan 2021 12:05:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22916 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391623AbhATRBf (ORCPT ); Wed, 20 Jan 2021 12:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xgc4giKWv6c746qHQMzY1X+v3rzPUg34NpKkwQbpZuU=; b=FQFWMGpokjc8vzQt72bc/RIXHy8OajB6S6DcRCkC+/VT9aLl17uraZNrVenYfMpnNBPRmS U7GeBo7IE8VdADr/dhi8lCqOOe/apmw2/J5vxSRzyHkle0hzyIMfVfPHtjf+Q0oCvFHOly trlQvw2359W8W/SaSuT8xK97r7Vsgto= 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-421-2pSIUINSN1mM_8kVR_1ToQ-1; Wed, 20 Jan 2021 11:59:56 -0500 X-MC-Unique: 2pSIUINSN1mM_8kVR_1ToQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9FE6A192CC42 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CB2B5D6DC for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id B98D210E5BC8; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 06/10] NFS: stash the readdir pagecache cursor on the open directory context Date: Wed, 20 Jan 2021 11:59:50 -0500 Message-Id: <27179777ef614728c54d76f6588567598eaf4057.1611160121.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Now that we have per-page cache validation, we can allow filling of the pagecache from arbitrary offsets. Store the pagecache cursor on the open directory context so it can be used to validate our entries the next time we enter nfs_readdir() without having to fill the pagecache from the beginning. The open_directory_context's dir_cookie and index_cookie will store the same value between calls to nfs_readdir(), so we can save a little room in the struct by dropping dir_cookie. Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 15 ++++++++------- include/linux/nfs_fs.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 5fc22d97054a..4e21b21c75d0 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -81,7 +81,7 @@ static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir if (ctx != NULL) { ctx->duped = 0; ctx->attr_gencount = nfsi->attr_gencount; - ctx->dir_cookie = 0; + memset(&ctx->pgc, 0, sizeof(struct nfs_dir_page_cursor)); ctx->dup_cookie = 0; spin_lock(&dir->i_lock); if (list_empty(&nfsi->open_files) && @@ -365,7 +365,8 @@ nfs_readdir_page_valid(struct page *page, unsigned int entry_index, u64 index_co ret = true; array = kmap_atomic(page); - if (array->size == 0 && array->last_cookie == index_cookie) + if ((array->size == 0 || array->size == entry_index) + && array->last_cookie == index_cookie) goto out_unmap; if (array->size > entry_index && @@ -1054,7 +1055,6 @@ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc) if (desc->pgc.page_index == 0) { desc->current_index = 0; desc->prev_index = 0; - desc->pgc.index_cookie = 0; } res = find_and_lock_cache_page(desc); } while (res == -EAGAIN); @@ -1192,7 +1192,8 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) desc->plus = nfs_use_readdirplus(inode, ctx); spin_lock(&file->f_lock); - desc->dir_cookie = dir_ctx->dir_cookie; + desc->dir_cookie = dir_ctx->pgc.index_cookie; + desc->pgc = dir_ctx->pgc; desc->dup_cookie = dir_ctx->dup_cookie; desc->duped = dir_ctx->duped; desc->attr_gencount = dir_ctx->attr_gencount; @@ -1231,7 +1232,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) } while (!desc->eof); spin_lock(&file->f_lock); - dir_ctx->dir_cookie = desc->dir_cookie; + dir_ctx->pgc = desc->pgc; dir_ctx->dup_cookie = desc->dup_cookie; dir_ctx->duped = desc->duped; dir_ctx->attr_gencount = desc->attr_gencount; @@ -1273,9 +1274,9 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence) if (offset != filp->f_pos) { filp->f_pos = offset; if (nfs_readdir_use_cookie(filp)) - dir_ctx->dir_cookie = offset; + dir_ctx->pgc.index_cookie = offset; else - dir_ctx->dir_cookie = 0; + dir_ctx->pgc.index_cookie = 0; if (offset == 0) memset(dir_ctx->verf, 0, sizeof(dir_ctx->verf)); dir_ctx->duped = 0; diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 557e54b7d555..cd35137a935b 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -101,7 +101,7 @@ struct nfs_open_dir_context { struct list_head list; unsigned long attr_gencount; __be32 verf[NFS_DIR_VERIFIER_SIZE]; - __u64 dir_cookie; + struct nfs_dir_page_cursor pgc; __u64 dup_cookie; signed char duped; }; From patchwork Wed Jan 20 16:59:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A141C433E0 for ; Wed, 20 Jan 2021 17:03:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3D2722CE3 for ; Wed, 20 Jan 2021 17:03:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391243AbhATRDQ (ORCPT ); Wed, 20 Jan 2021 12:03:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39949 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391610AbhATRBf (ORCPT ); Wed, 20 Jan 2021 12:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t125QmRUZ6lWveNo9xy4Ip66ayIlsdPL9LtMwbw8Qvw=; b=Ow9lSxZzUoIURNjnfYy+/KW8M6e3jsZPoqEYASG56upTLjhfuhEiKp4g3J4U/CnLuGcaZM QKZnTrXkHmz4XIBdMGi5oB2anUXBTgu+TC1DiKahn/9TsXmEpFx56aBaj9mLr3SycRyykm zLjd+D6nzXULxvYchcGo7LG+vr0jOJk= 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-86-usLKWE44OYCBa53xXoCVeA-1; Wed, 20 Jan 2021 11:59:56 -0500 X-MC-Unique: usLKWE44OYCBa53xXoCVeA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A436E100C602 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 704C55D767 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id C6B1310E5BCF; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 07/10] NFS: Support headless readdir pagecache pages Date: Wed, 20 Jan 2021 11:59:51 -0500 Message-Id: <7394b4d348d0c92b64cd0fb4fbf74bfa6e676d24.1611160121.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org It is now possible that a reader will resume a directory listing after an invalidation and fill the rest of the pages with the offset left over from the last partially-filled page. These pages will then be recycled and refilled by the next reader since their alignment is incorrect. Add an index to the nfs_cache_array that will indicate where the next entry should be filled. This allows partially-filled pages to have the best alignment possible. They are more likely to be useful to readers that follow. This optimization targets the case when there are multiple processes listing the directory simultaneously. Often the processes will collect and block on the same page waiting for a READDIR call to fill the pagecache. If the pagecache is invalidated, a partially-filled page will usually result. This partially-filled page can immediately be used by all processes to emit entries rather than having to discard and refill it for every process. The addition of another integer to struct nfs_cache_array increases its size to 24 bytes. We do not lose the original capacity of 127 entries per page. Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 4e21b21c75d0..d6101e45fd66 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -143,6 +143,7 @@ struct nfs_cache_array_entry { struct nfs_cache_array { u64 last_cookie; + unsigned int index; unsigned int size; unsigned char page_full : 1, page_is_eof : 1, @@ -179,13 +180,15 @@ static void nfs_readdir_array_init(struct nfs_cache_array *array) memset(array, 0, sizeof(struct nfs_cache_array)); } -static void nfs_readdir_page_init_array(struct page *page, u64 last_cookie) +static void +nfs_readdir_page_init_array(struct page *page, struct nfs_dir_page_cursor *pgc) { struct nfs_cache_array *array; array = kmap_atomic(page); nfs_readdir_array_init(array); - array->last_cookie = last_cookie; + array->last_cookie = pgc->index_cookie; + array->index = pgc->entry_index; array->cookies_are_ordered = 1; kunmap_atomic(array); if (page->mapping) @@ -224,7 +227,7 @@ void nfs_readdir_clear_array(struct page *page) int i; array = kmap_atomic(page); - for (i = 0; i < array->size; i++) + for (i = array->index - array->size; i < array->size; i++) kfree(array->array[i].name); nfs_readdir_array_init(array); kunmap_atomic(array); @@ -232,19 +235,20 @@ void nfs_readdir_clear_array(struct page *page) } static void -nfs_readdir_recycle_page(struct page *page, u64 last_cookie) +nfs_readdir_recycle_page(struct page *page, struct nfs_dir_page_cursor *pgc) { nfs_readdir_clear_array(page); nfs_readdir_invalidatepage(page, 0, 0); - nfs_readdir_page_init_array(page, last_cookie); + nfs_readdir_page_init_array(page, pgc); } static struct page * nfs_readdir_page_array_alloc(u64 last_cookie, gfp_t gfp_flags) { struct page *page = alloc_page(gfp_flags); + struct nfs_dir_page_cursor pgc = { .index_cookie = last_cookie }; if (page) - nfs_readdir_page_init_array(page, last_cookie); + nfs_readdir_page_init_array(page, &pgc); return page; } @@ -309,7 +313,7 @@ static int nfs_readdir_array_can_expand(struct nfs_cache_array *array) if (array->page_full) return -ENOSPC; - cache_entry = &array->array[array->size + 1]; + cache_entry = &array->array[array->index + 1]; if ((char *)cache_entry - (char *)array > PAGE_SIZE) { array->page_full = 1; return -ENOSPC; @@ -336,7 +340,7 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page) goto out; } - cache_entry = &array->array[array->size]; + cache_entry = &array->array[array->index]; cache_entry->cookie = entry->prev_cookie; cache_entry->ino = entry->ino; cache_entry->d_type = entry->d_type; @@ -345,6 +349,7 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page) array->last_cookie = entry->cookie; if (array->last_cookie <= cache_entry->cookie) array->cookies_are_ordered = 0; + array->index++; array->size++; if (entry->eof != 0) nfs_readdir_array_set_eof(array); @@ -365,13 +370,15 @@ nfs_readdir_page_valid(struct page *page, unsigned int entry_index, u64 index_co ret = true; array = kmap_atomic(page); - if ((array->size == 0 || array->size == entry_index) - && array->last_cookie == index_cookie) - goto out_unmap; + if (entry_index >= array->index - array->size) { + if ((array->size == 0 || array->size == entry_index) + && array->last_cookie == index_cookie) + goto out_unmap; - if (array->size > entry_index && - array->array[entry_index].cookie == index_cookie) - goto out_unmap; + if (array->size > entry_index && + array->array[entry_index].cookie == index_cookie) + goto out_unmap; + } ret = false; out_unmap: @@ -391,10 +398,10 @@ static struct page *nfs_readdir_page_get_locked(struct address_space *mapping, return page; if (!PageUptodate(page)) - nfs_readdir_page_init_array(page, pgc->index_cookie); + nfs_readdir_page_init_array(page, pgc); if (!nfs_readdir_page_valid(page, pgc->entry_index, pgc->index_cookie)) - nfs_readdir_recycle_page(page, pgc->index_cookie); + nfs_readdir_recycle_page(page, pgc); return page; } @@ -513,7 +520,7 @@ static bool nfs_readdir_array_cookie_in_range(struct nfs_cache_array *array, /* Optimisation for monotonically increasing cookies */ if (cookie >= array->last_cookie) return false; - if (array->size && cookie < array->array[0].cookie) + if (array->size && cookie < array->array[array->index - array->size].cookie) return false; return true; } @@ -528,7 +535,7 @@ static int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, if (!nfs_readdir_array_cookie_in_range(array, desc->dir_cookie)) goto check_eof; - for (i = 0; i < array->size; i++) { + for (i = array->index - array->size; i < array->index; i++) { if (array->array[i].cookie == desc->dir_cookie) { struct nfs_inode *nfsi = NFS_I(file_inode(desc->file)); @@ -1072,7 +1079,7 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc) unsigned int i = 0; array = kmap(desc->page); - for (i = desc->pgc.entry_index; i < array->size; i++) { + for (i = desc->pgc.entry_index; i < array->index; i++) { struct nfs_cache_array_entry *ent; ent = &array->array[i]; From patchwork Wed Jan 20 16:59:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032947 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0786CC433DB for ; Wed, 20 Jan 2021 17:05:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CEA1822CE3 for ; Wed, 20 Jan 2021 17:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391303AbhATRFW (ORCPT ); Wed, 20 Jan 2021 12:05:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50455 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391595AbhATRBe (ORCPT ); Wed, 20 Jan 2021 12:01:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qzrRtz5V8A4NaYeaCtWq+mw9BQEKROnYxMUcqfY3/Es=; b=UJrgX1v1sD9/uoj8Fy82wWBidXkXOvf496SgcwazDwKlZBKhxXADbS+VJWYeeusaKAc340 0Uqa5kfPE86ZNP1dzIOhzeHPv+7HIPNfITkE4roFfDAaGYpP5jbdCt1PAV2IaBkHc5Ta7Q Tndaf5nA04fqRwFAl7rIzOwNp3u4Ogk= 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-405-gSxLPl3QPCqcA01liJzGog-1; Wed, 20 Jan 2021 11:59:56 -0500 X-MC-Unique: gSxLPl3QPCqcA01liJzGog-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 875F4192CC41 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D6C35D74A for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id D684210E5BE2; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 08/10] NFS: Reset pagecache cursor on llseek Date: Wed, 20 Jan 2021 11:59:52 -0500 Message-Id: <24014d0e4f7119c76193eda5c5104a69bcaa30dd.1611160121.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Unless we reset the cursor, a series of lseek() getdents() calls will continue filling the pagecache indefinitely. Instead, reset the cursor so that we always start filling at the beginning of the pagecache. Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index d6101e45fd66..7ca79d4b25ec 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1284,6 +1284,8 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence) dir_ctx->pgc.index_cookie = offset; else dir_ctx->pgc.index_cookie = 0; + dir_ctx->pgc.page_index = 0; + dir_ctx->pgc.entry_index = 0; if (offset == 0) memset(dir_ctx->verf, 0, sizeof(dir_ctx->verf)); dir_ctx->duped = 0; From patchwork Wed Jan 20 16:59:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65A6DC433E0 for ; Wed, 20 Jan 2021 17:05:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2841E233ED for ; Wed, 20 Jan 2021 17:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391722AbhATRFF (ORCPT ); Wed, 20 Jan 2021 12:05:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46424 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391597AbhATRBf (ORCPT ); Wed, 20 Jan 2021 12:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lEnzzn2Hgl9Ay5ghThhbcNflPzdpaCrMRx+VWv5YTe4=; b=OMdvi1fcpjxsYL46Qc65b1RPu/U9iTIH1WfBQPClTeRdKpj/CU+aodMFcjSG1xAnTtFrlR sCh3PmwfrZ3zMu47kyiIDyd6Y765tK6E8V4F0fvNGQC07WEIJOMve6nnc0IgH9XCPz84CJ FXh5rhb4VWXX9ww2fey1bB8diu1Mf94= 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-196-XcRtagvjPsKWioqQ8PMCiQ-1; Wed, 20 Jan 2021 11:59:56 -0500 X-MC-Unique: XcRtagvjPsKWioqQ8PMCiQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A29518030A7 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B2685D76F for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id E276110E5BF8; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 09/10] NFS: Remove nfs_readdir_dont_search_cache() Date: Wed, 20 Jan 2021 11:59:53 -0500 Message-Id: <1ebc4a7d527775b03efc21f39d04072e4d118516.1611160121.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Since we can now fill the pagecache at arbitrary offsets, we no longer need this optimization. Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 7ca79d4b25ec..fc9e72341220 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1036,28 +1036,11 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc) return res; } -static bool nfs_readdir_dont_search_cache(struct nfs_readdir_descriptor *desc) -{ - struct address_space *mapping = desc->file->f_mapping; - struct inode *dir = file_inode(desc->file); - unsigned int dtsize = NFS_SERVER(dir)->dtsize; - loff_t size = i_size_read(dir); - - /* - * Default to uncached readdir if the page cache is empty, and - * we're looking for a non-zero cookie in a large directory. - */ - return desc->dir_cookie != 0 && mapping->nrpages == 0 && size > dtsize; -} - /* Search for desc->dir_cookie from the beginning of the page cache */ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc) { int res; - if (nfs_readdir_dont_search_cache(desc)) - return -EBADCOOKIE; - do { if (desc->pgc.page_index == 0) { desc->current_index = 0; From patchwork Wed Jan 20 16:59:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Coddington X-Patchwork-Id: 12032935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9662C433DB for ; Wed, 20 Jan 2021 17:05:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FA71233ED for ; Wed, 20 Jan 2021 17:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390641AbhATRFO (ORCPT ); Wed, 20 Jan 2021 12:05:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21280 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391612AbhATRBf (ORCPT ); Wed, 20 Jan 2021 12:01:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611161998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=12Eg8CvR+Ni0Oe8ekqduRsnlP5+EIgifm7UScIeUTpM=; b=E7rHnyniYBMmeWQ7h9Ec57QO70mRUlCSKXz/imf+/us3e7DiTVfqxLVGzDJRncIcD1PVyU kqB0rLN9EzvMVSsPf//6BjxSfhHlthfD2EwnjONk9Pkuq507Mi9N6eoVUep32JP0/kao/w Rz6B+F2blqRQ77a8q0vjXsoEV3wPDhY= 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-224-zYrIYeRLNm2JzzjbuiRriw-1; Wed, 20 Jan 2021 11:59:56 -0500 X-MC-Unique: zYrIYeRLNm2JzzjbuiRriw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7DDF107ACE8 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: from bcodding.csb (ovpn-64-66.rdu2.redhat.com [10.10.64.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A5291001281 for ; Wed, 20 Jan 2021 16:59:55 +0000 (UTC) Received: by bcodding.csb (Postfix, from userid 24008) id ED9B910E5BFF; Wed, 20 Jan 2021 11:59:54 -0500 (EST) From: Benjamin Coddington To: linux-nfs@vger.kernel.org Subject: [PATCH v1 10/10] NFS: Revalidate the directory pagecache on every nfs_readdir() Date: Wed, 20 Jan 2021 11:59:54 -0500 Message-Id: <3e1c54f1a5e50fdeeb814c4067d1462da3f36dfd.1611160121.git.bcodding@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Since there's no longer a significant performance penalty for dropping the pagecache, and because we want to ensure that the directory's change attribute is accurate before validating pagecache pages, revalidate the directory's mapping on every call to nfs_readdir(). Signed-off-by: Benjamin Coddington --- fs/nfs/dir.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index fc9e72341220..842412454e3d 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1167,11 +1167,9 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) * to either find the entry with the appropriate number or * revalidate the cookie. */ - if (ctx->pos == 0 || nfs_attribute_cache_expired(inode)) { - res = nfs_revalidate_mapping(inode, file->f_mapping); - if (res < 0) - goto out; - } + res = nfs_revalidate_mapping(inode, file->f_mapping); + if (res < 0) + goto out; res = -ENOMEM; desc = kzalloc(sizeof(*desc), GFP_KERNEL);