Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4406800pxb; Mon, 21 Feb 2022 20:34:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2MHLZTCJNza81+QfP6igdXIE26fGYQUyb0ZuGvoZYsgPKelxcNXTbhzUytUmkMlJF2hL9 X-Received: by 2002:a63:1d4b:0:b0:373:adab:c9a1 with SMTP id d11-20020a631d4b000000b00373adabc9a1mr17408573pgm.49.1645504453854; Mon, 21 Feb 2022 20:34:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645504453; cv=none; d=google.com; s=arc-20160816; b=dOtlm97BYgfbjiyCGncaqNi9HZfUoR8HeFXA/+Ffm9l2JoHzVFZ+msfX/AJb925PAC vl8iBwIKvLUVP23U5E7pjGpBK2gXY0oVXV3GZl3AiLxKk3W9AOI+dK7xHe6Ho+M3SFFt pZSZBg9oJTR3RVKhrXGfFeeT1XI09/CvDqBPU0/v38jx1IzOyJDw1b3f5bTH661wsa13 qeA3ODrm9l3aok7Kv/wlllqVxOfrKHl/vHzMd5NaeVp+1v17nIqXlNpr54mKNnXmyGdK ctObuL+D9kFFH97avrJG62vj0c95cLoTltNv9cHuxIiMkFD0nmL3wwj0YKyWc8+WzKg9 vV4w== 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=bWajgR1t6VC8HzDua3e7SEt0eKJ8om5RB415PTgRaaQ=; b=ZU1UCw3SWT+Cx4xofPrEbIqsUPFuHdJs0KGAiwUcM2ejRFehUZmKkFXbJ++KIEloSR 5yBjJzsQkL8rWHgNVgQfw9O/4aiolr4NVpIHOotfCdO6egL0yzLX/i9LkCLNDVHtySUN MrKWcuqVqAkWN7O6uJeBYvdOFT6z2fNnaAS+oQg/qdnx68JWN0ILZJiYkgUhPVXkfKFL qzj053Nw6ZnZ6Ugxc1VHPqQRVPG/dVlytodTAepHoqU9fu/2MC7FBpZ5w8au2axBECGC HL+z51RhuhWzWsYYF1ojvczREhN7RPXuzMkvUUJiUNo08REzc7S1HSSCv0ZmwB1GY83n 29hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C0cw1GpT; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n12-20020a17090aab8c00b001b9fffaf02asi1046072pjq.165.2022.02.21.20.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:34:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C0cw1GpT; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D89C82AC3; Mon, 21 Feb 2022 20:22:45 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379991AbiBUQP2 (ORCPT + 99 others); Mon, 21 Feb 2022 11:15:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379986AbiBUQPZ (ORCPT ); Mon, 21 Feb 2022 11:15:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8F5027B09 for ; Mon, 21 Feb 2022 08:15:02 -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 7064D612A3 for ; Mon, 21 Feb 2022 16:15:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18203C340F1 for ; Mon, 21 Feb 2022 16:15:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645460102; bh=KmywsLUD8y02FPy3fCK28yoWL5oPPleON/q3PmiX2QY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=C0cw1GpTo2ZOa8TIvI9vGhgXLMXRtfKJRwQLT+pnbF+L0om6U3xcxWNk+Kc3kcIVx H5EDXZDhRUNk8bNHob1MF3RHaWTz1KWvOdoEi70Vql12t2BxGF5NIeLp5faxe2SNwB +JyWK17E6nVXxllWSsEcDZNnqGeTa5YCYwrkizj4h3H1J39Xj5JyTa1gFMy/o9d6G9 9ys6DWt02rA3B2IztL1vDrFmfAspa+u0Lm45U3Y0mRwjaxGAurh046hfXAtfG+EZRU sqdMcptzf7yKFXBa8GFSp7sDUxuKEh3GNG0eOsERqzirb6po2gRxdUuNbFzTWcoeG3 nU4FTC4Kk2L4Q== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v6 07/13] NFS: Don't ask for readdirplus unless it can help nfs_getattr() Date: Mon, 21 Feb 2022 11:08:45 -0500 Message-Id: <20220221160851.15508-8-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221160851.15508-7-trondmy@kernel.org> References: <20220221160851.15508-1-trondmy@kernel.org> <20220221160851.15508-2-trondmy@kernel.org> <20220221160851.15508-3-trondmy@kernel.org> <20220221160851.15508-4-trondmy@kernel.org> <20220221160851.15508-5-trondmy@kernel.org> <20220221160851.15508-6-trondmy@kernel.org> <20220221160851.15508-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 attribute caching is turned off, then use of readdirplus is not going to help stat() performance. Readdirplus also doesn't help if a file is being written to, since we will have to flush those writes in order to sync the mtime/ctime. Signed-off-by: Trond Myklebust --- fs/nfs/inode.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 1bef81f5373a..9d2af9887715 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -782,24 +782,26 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr, } EXPORT_SYMBOL_GPL(nfs_setattr_update_inode); -static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry) +/* + * Don't request help from readdirplus if the file is being written to, + * or if attribute caching is turned off + */ +static bool nfs_getattr_readdirplus_enable(const struct inode *inode) { - struct dentry *parent; + return nfs_server_capable(inode, NFS_CAP_READDIRPLUS) && + !nfs_have_writebacks(inode) && NFS_MAXATTRTIMEO(inode) > 5 * HZ; +} - if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS)) - return; - parent = dget_parent(dentry); +static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry) +{ + struct dentry *parent = dget_parent(dentry); nfs_readdir_record_entry_cache_miss(d_inode(parent)); dput(parent); } static void nfs_readdirplus_parent_cache_hit(struct dentry *dentry) { - struct dentry *parent; - - if (!nfs_server_capable(d_inode(dentry), NFS_CAP_READDIRPLUS)) - return; - parent = dget_parent(dentry); + struct dentry *parent = dget_parent(dentry); nfs_readdir_record_entry_cache_hit(d_inode(parent)); dput(parent); } @@ -837,6 +839,7 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path, int err = 0; bool force_sync = query_flags & AT_STATX_FORCE_SYNC; bool do_update = false; + bool readdirplus_enabled = nfs_getattr_readdirplus_enable(inode); trace_nfs_getattr_enter(inode); @@ -845,7 +848,8 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path, STATX_INO | STATX_SIZE | STATX_BLOCKS; if ((query_flags & AT_STATX_DONT_SYNC) && !force_sync) { - nfs_readdirplus_parent_cache_hit(path->dentry); + if (readdirplus_enabled) + nfs_readdirplus_parent_cache_hit(path->dentry); goto out_no_revalidate; } @@ -895,15 +899,12 @@ int nfs_getattr(struct user_namespace *mnt_userns, const struct path *path, do_update |= cache_validity & NFS_INO_INVALID_BLOCKS; if (do_update) { - /* Update the attribute cache */ - if (!(server->flags & NFS_MOUNT_NOAC)) + if (readdirplus_enabled) nfs_readdirplus_parent_cache_miss(path->dentry); - else - nfs_readdirplus_parent_cache_hit(path->dentry); err = __nfs_revalidate_inode(server, inode); if (err) goto out; - } else + } else if (readdirplus_enabled) nfs_readdirplus_parent_cache_hit(path->dentry); out_no_revalidate: /* Only return attributes that were revalidated. */ -- 2.35.1