Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp641866pxb; Wed, 29 Sep 2021 06:51:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySQ2IPAeqOsIgD0BpQyYgXP/HsbHqZwGlPqyBhF65FZr7jVo0ASFqw9icTwOWK5IibNhVN X-Received: by 2002:a65:6499:: with SMTP id e25mr110725pgv.146.1632923461447; Wed, 29 Sep 2021 06:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632923461; cv=none; d=google.com; s=arc-20160816; b=wNHE9pOtvP81G4vyN5Nfn+R6Uzmc7r0PNYlIicpkycIteJ0v+HPJ5gpCDQAS5lEfup Hvy58cob9g5+4mQRzrn6poZuyp4wyHV3Pp1Mf2Axpyv5ew5PiuPUenYDDRdslSkWskxO eBVMGN/bK+LM8wzELA+4b0iOA16K1QJRDk/4QTnmJhPh00mXfVUZg/4/pZBBJyqgEN4c MGITJGuGfwEI5VJEFkfpBLfkT7Lx3aRX8eLrRXF74rT8RTj1VeA0nYBAKn5rbTxGKW0V kZLFw6XFxsMkezQKzGV2hKTBliaSSMuvOjNyNNY3Mqm58KFkAYTGmJKDoxDwE8Qw9cx1 fmDQ== 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=PQONsNOcUET8vF6v5ByGyandt5JNMAbJB0DTyS/yfRg=; b=IGc/GioEzxXfoEvyYKgfvfnTlxydr3vrN01Tp2q2+0ed6o7dxoQzYINnETB5C3EyNv Tqcc2/C0ZO5R/47OTN+7leuZGAS0V2MgQjBmt2pHKxK4tDQ17OsMMGi/5gVwFCz12/AO y1snoU6G71Kg6JQ6QaS6pPXOYZqDDDSByjDkPiVzfFNEhfGx3MV+dElsvgXsEIjY8aBH pS8VF4fwDIoonq8jM6JEkNbZX+qkW4V8bKj98UP6wr0y17HkM/cYBN3RFJoczkrH6wVQ RryyTSEHo42mW9nI1COd0EAKY2TCaj21/tq1LlwkTVMXvvZPtXjTtc8HD0ER4+E/poXu YO1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FVIdhViW; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si3078634pgu.404.2021.09.29.06.50.47; Wed, 29 Sep 2021 06:51:01 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=FVIdhViW; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344316AbhI2Nv2 (ORCPT + 99 others); Wed, 29 Sep 2021 09:51:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:36052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344318AbhI2Nv2 (ORCPT ); Wed, 29 Sep 2021 09:51:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0F27B60551 for ; Wed, 29 Sep 2021 13:49:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632923387; bh=vIOq9W1Rsx3gdspMHf+PbQXGe8mt80iF3KdwiSArgV0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FVIdhViWYmWqxvF0llppMlOCn2MA0raUtESQPZSVAFjigwUP6MMpYx6CkHjjtT+dr ByNKrMzLIEM3gKxVWqfDlae6GS0jPay1EJu3JrtcNXhQdWbpCEGw72VFpO54wZwei4 b8sKtS19GKfAHiWoctWG/4nEDD+bXnrVCO5LyLe13QxBsAAOUSkY2+RuAdRUKbYDT8 Xjs+L+eluNboI/056AqjkLwqi//YDCcMQfKofCWyeEAHgFGflhMGJtcD4OgB1LW4mW SycHS/B85e+KrGKHbTbJ2t0H1OqDEjjlSYL941zgeMb7nkm4f8YXR7eO2A25g9ZN5K HmCiYbwePszMw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 4/5] NFS: Further optimisations for 'ls -l' Date: Wed, 29 Sep 2021 09:49:43 -0400 Message-Id: <20210929134944.632844-4-trondmy@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210929134944.632844-3-trondmy@kernel.org> References: <20210929134944.632844-1-trondmy@kernel.org> <20210929134944.632844-2-trondmy@kernel.org> <20210929134944.632844-3-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If a user is doing 'ls -l', we have a heuristic in GETATTR that tells the readdir code to try to use READDIRPLUS in order to refresh the inode attributes. In certain cirumstances, we also try to invalidate the remaining directory entries in order to ensure this refresh. If there are multiple readers of the directory, we probably should avoid invalidating the page cache, since the heuristic breaks down in that situation anyway. Signed-off-by: Trond Myklebust --- fs/nfs/dir.c | 16 +++++++++++----- include/linux/nfs_fs.h | 5 ++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index fa4d33687d2b..358033aea235 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -78,6 +78,7 @@ static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir ctx->attr_gencount = nfsi->attr_gencount; ctx->dir_cookie = 0; ctx->dup_cookie = 0; + ctx->page_index = 0; spin_lock(&dir->i_lock); if (list_empty(&nfsi->open_files) && (nfsi->cache_validity & NFS_INO_DATA_INVAL_DEFER)) @@ -85,6 +86,7 @@ static struct nfs_open_dir_context *alloc_nfs_open_dir_context(struct inode *dir NFS_INO_INVALID_DATA | NFS_INO_REVAL_FORCED); list_add(&ctx->list, &nfsi->open_files); + clear_bit(NFS_INO_FORCE_READDIR, &nfsi->flags); spin_unlock(&dir->i_lock); return ctx; } @@ -627,8 +629,7 @@ void nfs_force_use_readdirplus(struct inode *dir) if (nfs_server_capable(dir, NFS_CAP_READDIRPLUS) && !list_empty(&nfsi->open_files)) { set_bit(NFS_INO_ADVISE_RDPLUS, &nfsi->flags); - invalidate_mapping_pages(dir->i_mapping, - nfsi->page_index + 1, -1); + set_bit(NFS_INO_FORCE_READDIR, &nfsi->flags); } } @@ -938,10 +939,8 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc) sizeof(nfsi->cookieverf)); } res = nfs_readdir_search_array(desc); - if (res == 0) { - nfsi->page_index = desc->page_index; + if (res == 0) return 0; - } nfs_readdir_page_unlock_and_put_cached(desc); return res; } @@ -1080,6 +1079,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) struct nfs_inode *nfsi = NFS_I(inode); struct nfs_open_dir_context *dir_ctx = file->private_data; struct nfs_readdir_descriptor *desc; + pgoff_t page_index; int res; dfprintk(FILE, "NFS: readdir(%pD2) starting at cookie %llu\n", @@ -1110,10 +1110,15 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) desc->dir_cookie = dir_ctx->dir_cookie; desc->dup_cookie = dir_ctx->dup_cookie; desc->duped = dir_ctx->duped; + page_index = dir_ctx->page_index; desc->attr_gencount = dir_ctx->attr_gencount; memcpy(desc->verf, dir_ctx->verf, sizeof(desc->verf)); spin_unlock(&file->f_lock); + if (test_and_clear_bit(NFS_INO_FORCE_READDIR, &nfsi->flags) && + list_is_singular(&nfsi->open_files)) + invalidate_mapping_pages(inode->i_mapping, page_index, -1); + do { res = readdir_search_pagecache(desc); @@ -1150,6 +1155,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) dir_ctx->dup_cookie = desc->dup_cookie; dir_ctx->duped = desc->duped; dir_ctx->attr_gencount = desc->attr_gencount; + dir_ctx->page_index = desc->page_index; memcpy(dir_ctx->verf, desc->verf, sizeof(dir_ctx->verf)); spin_unlock(&file->f_lock); diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 9b75448ce0df..ca547cc5458c 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -103,6 +103,7 @@ struct nfs_open_dir_context { __be32 verf[NFS_DIR_VERIFIER_SIZE]; __u64 dir_cookie; __u64 dup_cookie; + pgoff_t page_index; signed char duped; }; @@ -181,9 +182,6 @@ struct nfs_inode { struct rw_semaphore rmdir_sem; struct mutex commit_mutex; - /* track last access to cached pages */ - unsigned long page_index; - #if IS_ENABLED(CONFIG_NFS_V4) struct nfs4_cached_acl *nfs4_acl; /* NFSv4 state */ @@ -272,6 +270,7 @@ struct nfs4_copy_state { #define NFS_INO_INVALIDATING (3) /* inode is being invalidated */ #define NFS_INO_FSCACHE (5) /* inode can be cached by FS-Cache */ #define NFS_INO_FSCACHE_LOCK (6) /* FS-Cache cookie management lock */ +#define NFS_INO_FORCE_READDIR (7) /* force readdirplus */ #define NFS_INO_LAYOUTCOMMIT (9) /* layoutcommit required */ #define NFS_INO_LAYOUTCOMMITTING (10) /* layoutcommit inflight */ #define NFS_INO_LAYOUTSTATS (11) /* layoutstats inflight */ -- 2.31.1