Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1081788pxm; Wed, 23 Feb 2022 17:39:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzVN7OSDCKdVJeFsmtIsrSRjEh8rkqkopWIPUv+9RjW0JT5icNIb3IEsOO2hB/Df8lYCAh X-Received: by 2002:a17:902:a60d:b0:14f:b781:ccd7 with SMTP id u13-20020a170902a60d00b0014fb781ccd7mr591176plq.2.1645666746773; Wed, 23 Feb 2022 17:39:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645666746; cv=none; d=google.com; s=arc-20160816; b=eMsDNGpJzoaiU6VHsZfcJPwASJ9J6Fn+vV4eduRfUjRzj/kqpKkSxKZvkcN6QhIHUc N6hBy/+e5tLcAIJGX/G5+htMzwxKCEeYnZ4e1j+niXls+vS4goXaK2VfhIQlArK9h2jJ uEZqw+xv616x9lAsJbqQCdxblT4es+5LSJb9Sw/NPJ4Xvtdsxk3cQuf7lB70zFeyCNIc jn6J5QoFV69S0PbkxNO0ydTApIWufE6oT+B5V39za4CLOVK8v9FWzGkShgbDQLoiwN06 j/Pprq3Vsr+iEZsO8lZVMlCENQCcQYkCJOs+6mcCXa4a/bbnjiIFTfxnpjbplr1ruzN7 sUGw== 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=e77gKON0f87PJ5E1+vialUwslEyeojv2EzP0Svy5SyY=; b=dlUrv4B+agVUsKOiZ57A83oFW2BIR80ysfue9Scqf3emju0XeytdN8cVakRHwfZ/SC VIrzNawveOCURbdAgaVBMw4YKl0M6I9d2L+AVtm0BmjNJH2kbNjCuu/cCV7Uy4iovMFT owZPb5hKMoW5OAjJaC8qtqwBnyy7gU4NjZ9V3GVTTeDxOMNMopfG52bjzSD3e1a7c2j7 tZJIxM7/yDQM7ONBBwLPPhCB0tVZklbzW+prSP1UBswin1u9NIDTt5Hqj/bKOwS2T16w PfwLlP8/lP7YWu91PliRWbYm6VckVzS9K3Ot94+dZnn2rYIzjFYCFBnezSX01q7JBt4j on2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hW9uTyYl; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 131si1160802pgg.325.2022.02.23.17.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 17:39:06 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hW9uTyYl; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6C0F17587B; Wed, 23 Feb 2022 17:16:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242466AbiBWVWd (ORCPT + 99 others); Wed, 23 Feb 2022 16:22:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242426AbiBWVUG (ORCPT ); Wed, 23 Feb 2022 16:20:06 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED16B4ECD3 for ; Wed, 23 Feb 2022 13:19: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 sin.source.kernel.org (Postfix) with ESMTPS id 5C645CE1C54 for ; Wed, 23 Feb 2022 21:19:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73F24C340E7 for ; Wed, 23 Feb 2022 21:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645651174; bh=f4lIwUURxJwQZqENszJpvs17hM46N6azJSGI1p3XJpU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hW9uTyYl3ceWYz+lMqTWBs4s6/OF/Y/2hPP96zUqQ/VtVcTJWIueAlheKSwojl7Li hjNOln/4yQckINW7QTqehNXG4kLcdHclBSxS41gj03SWH3hTQnWMrA0XSsJdcDII1d 1aWu2rH/qjvOsyVeDs+kr/WNPOS4PTPL/ezB4x14X+IvIt76/f2xu56069bG07IWNs XUCR/jQMMB+xXfVgSWw9w7uZo43VZf2ddYqBUhAEBQES0e33l/w3sdLsfgf77rbWtc QnLnLTP3vGiAOeeU+FBajDlB8u9TG+hROITgCuNdkhH5o/MnUQqZHjAc0zDR9JeWig 7lOSzUgbZ0BgQ== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v7 07/21] NFS: Don't re-read the entire page cache to find the next cookie Date: Wed, 23 Feb 2022 16:12:51 -0500 Message-Id: <20220223211305.296816-8-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223211305.296816-7-trondmy@kernel.org> References: <20220223211305.296816-1-trondmy@kernel.org> <20220223211305.296816-2-trondmy@kernel.org> <20220223211305.296816-3-trondmy@kernel.org> <20220223211305.296816-4-trondmy@kernel.org> <20220223211305.296816-5-trondmy@kernel.org> <20220223211305.296816-6-trondmy@kernel.org> <20220223211305.296816-7-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 7932d474ce00..70c0db877815 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1124,6 +1124,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)); @@ -1172,6 +1174,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; @@ -1213,10 +1216,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