Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2549409pxm; Mon, 28 Feb 2022 01:03:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgU09jtlIys8imODdMtGPG113f261vG2Cz8/nHRtWmztluELGo0nulwYCPeMFAehy92qtO X-Received: by 2002:a17:902:bc83:b0:14f:d9b7:ab3 with SMTP id bb3-20020a170902bc8300b0014fd9b70ab3mr18948215plb.23.1646038993604; Mon, 28 Feb 2022 01:03:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646038993; cv=none; d=google.com; s=arc-20160816; b=DNHsBJo+xeL1rFQnnWfiVlCNJvsHusDTo9InTbh/FxHlRceE/qSgsEtXVOxINnm+Kh 79VO5cDIViEQGpuAnWQTJMQc4VIwj+E+L+3yNSqsrb1ANxBFBAj15NkG6x2Dj5MrczUm jaRqOPIsHFi698v030PnlLYLIHKR5pP9a66lJqfDFI/Ja3CFURiDt2vKJXSRKtOFt4uT zdaWluye3wnfBkqJHWQsPJJZZG5puLzXe72xiOjPq2TXF2qkd3fYObPLc9aM0pFvPCZ2 /1sw/dJzDlaYrK5nc1i8BWjCfvD9kVxpKiva1LsUIkZo/SDhb+EwELBMZHNV+Hw0i5yy XOnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=P0AiW6jmW6a3L3FYa4KgnnjvYHOeGw3uEmV1scwZ1UQ=; b=c2sJMStX/MLfWWcF6SruS5o43m9Bv0V/QjxpwQ3hI6yT/zZkSfHM1UDJ7+akL3wpzE RxGY+SdAKIkm+KtRGIFUFih2/Xe4yQYbySLothNseTOL3TwGpAcNj8PzXEnDrzdyjypP 1hReRmhKFFocuOZrQC/3FGQdPm5jy2vHTvHqgIXIOjcG011xsvYJoEnYQc1RuoAlH8TP /rh2RrKtbm3C0wWYVQDGMQplVGRaIRgr7P8A6A0Q/MEISNB9vS41skz8B18HZe63+fZ8 jyHjM9yMq+8Eh/ihIbNzb2PIlc/93hnQ5+NVk9LkAn1ODsz2ip7wxCt/UhSoMLPzAHHX h7Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MGSwP2WY; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k14-20020a63ab4e000000b00365948e287asi8672325pgp.471.2022.02.28.01.02.58; Mon, 28 Feb 2022 01:03:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MGSwP2WY; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232192AbiB0XTR (ORCPT + 99 others); Sun, 27 Feb 2022 18:19:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232193AbiB0XTQ (ORCPT ); Sun, 27 Feb 2022 18:19:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4D922252B for ; Sun, 27 Feb 2022 15:18:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 36893611D8 for ; Sun, 27 Feb 2022 23:18:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1DF3C340EE for ; Sun, 27 Feb 2022 23:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646003917; bh=UR+8yHtSOydvD9ZfjQSQNJsFHiKjdEUQbnYo80Hg5Ro=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MGSwP2WYSyvmAe/LmkWGwYiqZGDGHcAz/2qsYCwdszRX31Wd+23JRF5Wo1pvxY0iU iJLZIM2qnztbg7EoYzG+xXTYD9djyrbQbkz/Xxgdvr/g1sLNX/UOgpQRU41ntn39ho BYZujxIAnOl8h+8b03gufF80Rw+mSmLo4krynA1HDyBNVLR+i5idKOcZ2CXN11fTNI geKJVVqWJkks/3SdXfyQ2l/AC40lHSpD4s78I6KPNlwqlFU1bwfqa7OJB17IiEw0Rv bXQHYWmiY+Pejwaho60bCP7gZxzY60halvxYtYZJi+t8i2GepRtZMRciz5rnO+NFzv c0qWmjLpMyaAQ== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v9 08/27] NFS: Don't re-read the entire page cache to find the next cookie Date: Sun, 27 Feb 2022 18:12:08 -0500 Message-Id: <20220227231227.9038-9-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220227231227.9038-8-trondmy@kernel.org> References: <20220227231227.9038-1-trondmy@kernel.org> <20220227231227.9038-2-trondmy@kernel.org> <20220227231227.9038-3-trondmy@kernel.org> <20220227231227.9038-4-trondmy@kernel.org> <20220227231227.9038-5-trondmy@kernel.org> <20220227231227.9038-6-trondmy@kernel.org> <20220227231227.9038-7-trondmy@kernel.org> <20220227231227.9038-8-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If the page cache entry that was last read gets invalidated for some reason, then make sure we can re-create it on the next call to readdir. This, combined with the cache page validation, allows us to reuse the cached value of page-index on successive calls to nfs_readdir. Credit is due to Benjamin Coddington for showing that the concept works, and that it allows for improved cache sharing between processes even in the case where pages are lost due to LRU or active invalidation. Suggested-by: Benjamin Coddington Signed-off-by: Trond Myklebust --- fs/nfs/dir.c | 10 +++++++--- include/linux/nfs_fs.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index bfb553c57274..37f78b0ebc40 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1120,6 +1120,8 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) desc->dup_cookie = dir_ctx->dup_cookie; desc->duped = dir_ctx->duped; page_index = dir_ctx->page_index; + desc->page_index = page_index; + desc->last_cookie = dir_ctx->last_cookie; desc->attr_gencount = dir_ctx->attr_gencount; desc->eof = dir_ctx->eof; memcpy(desc->verf, dir_ctx->verf, sizeof(desc->verf)); @@ -1168,6 +1170,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) spin_lock(&file->f_lock); dir_ctx->dir_cookie = desc->dir_cookie; dir_ctx->dup_cookie = desc->dup_cookie; + dir_ctx->last_cookie = desc->last_cookie; dir_ctx->duped = desc->duped; dir_ctx->attr_gencount = desc->attr_gencount; dir_ctx->page_index = desc->page_index; @@ -1209,10 +1212,11 @@ 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; - else + if (!nfs_readdir_use_cookie(filp)) { dir_ctx->dir_cookie = 0; + dir_ctx->page_index = 0; + } else + dir_ctx->dir_cookie = offset; 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 6e10725887d1..1c533f2c1f36 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -105,6 +105,7 @@ struct nfs_open_dir_context { __be32 verf[NFS_DIR_VERIFIER_SIZE]; __u64 dir_cookie; __u64 dup_cookie; + __u64 last_cookie; pgoff_t page_index; signed char duped; bool eof; -- 2.35.1