Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2777197pxp; Mon, 14 Mar 2022 04:55:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnBZYnisLcWpHRSL0k+FThvsWQyZoCizcAYZVloNhlcSxPe9I/MgD2hZNA91L5WzEv2ZH9 X-Received: by 2002:a17:902:f708:b0:153:839f:bf2c with SMTP id h8-20020a170902f70800b00153839fbf2cmr2900604plo.113.1647258902501; Mon, 14 Mar 2022 04:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647258902; cv=none; d=google.com; s=arc-20160816; b=qpdHPII+Sqj0uj1HlW0x2VDHhF+o8sX699DXOxJXrlEbskhIzNGlLL3s55qSiUaAQd IOCbgoWwKrYVC0VqfBlLTyNd5+E8FNzuvVej9QxE4hawKRZm5CpBqjHlbAJvmjss3nIJ LbbG3tT0RGOlC2m9jAu68CbIHSqb666RLabODy/miowlnzrBWwSAth13n5/UbAa8mNhe 8/i1Tw4vl3WIcTcHrSBudbd5YAyPexPaLBzq7Lr35t0gArGjr+yCPNWFN9TOFkbf/Odu xQjGujzxBM918vNIP+t52bhwxXdNAatWcW9IAET+hLqEvkPHquzrFdDo0nCBAYR5Kgh7 B4XA== 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=aCPCjqF3ZmNRFkGH9dNAD8DmZ7W+JpCKkTF4OcyHfG4=; b=QDcnjx0378B6CWVK+uqLuDx3GXbge2ZXg5a/NTcnvDyyR/pOVI0he8gkw4TJEMbToi 2ZDOs8u3IdxaMTbJlryyAm+rkO6tR8sKknAT5GQUkCsfCCFXrgaIZ4fDh781kkUsseCD UZ+/rOp53Ql0kN2UBAaLeDINMHZ/Rq/Uo8w5IlCROUN5xmxm1w51vbX1b+v/0y24TQpe F176RsQ5slhGDF5j8T+5/uJolfT68F4xjyfjn85HnIyorw9W2WzLWK3Cuw8vuArj8x/7 7044+1uTKJ0ujG0tkpY0Wzi0Q56gzxVoUyU272N75fe+q3DnHIs2rPx4H3mFhx/GW6il rnfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KjbvG7WL; 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 3-20020a630003000000b0038001326b1fsi14929418pga.306.2022.03.14.04.54.49; Mon, 14 Mar 2022 04:55:02 -0700 (PDT) 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=KjbvG7WL; 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 S235118AbiCMRNW (ORCPT + 99 others); Sun, 13 Mar 2022 13:13:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235122AbiCMRNU (ORCPT ); Sun, 13 Mar 2022 13:13:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67AA713A1ED for ; Sun, 13 Mar 2022 10:12:12 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 10E5FB80CD8 for ; Sun, 13 Mar 2022 17:12:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AC2FC340EE for ; Sun, 13 Mar 2022 17:12:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647191529; bh=Z+CvJxEfkHR4Z0YDMyER2rGO+npSIUGuT5Q83OIpFVU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KjbvG7WLU8bgp+aW++M/1FLvxyIBXbOtwABBHb9buIwLxdiRYVxYXuKDbCNilG6hW fk8W4ZPm8xaOyDRBeGMXOMEgChWTvm9c841WwNuBVwSoX5wTZmwoYd0IHkVe8yoMuZ PT3mtCBQ5+lnR1CW3nxAPXET09JieDrAP1JAjOsI58uu/TgOvJZRV8tIm1T0i7gLR1 zhsyb1w2sx7fJf+lPawb2+0Si86md9jqwHxNOOqruqU3+mAtd0UO0yRQGDLl12MV6h 8bt9ok8pUCpV6ocpJUpER3ClO6qnsvUM74tA+BidPgnbnIwRl+4oUsmU4CiA8g7jOL 06lyBXg0a79eA== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v10 15/26] NFS: Don't ask for readdirplus unless it can help nfs_getattr() Date: Sun, 13 Mar 2022 13:05:46 -0400 Message-Id: <20220313170557.5940-16-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220313170557.5940-15-trondmy@kernel.org> References: <20220313170557.5940-1-trondmy@kernel.org> <20220313170557.5940-2-trondmy@kernel.org> <20220313170557.5940-3-trondmy@kernel.org> <20220313170557.5940-4-trondmy@kernel.org> <20220313170557.5940-5-trondmy@kernel.org> <20220313170557.5940-6-trondmy@kernel.org> <20220313170557.5940-7-trondmy@kernel.org> <20220313170557.5940-8-trondmy@kernel.org> <20220313170557.5940-9-trondmy@kernel.org> <20220313170557.5940-10-trondmy@kernel.org> <20220313170557.5940-11-trondmy@kernel.org> <20220313170557.5940-12-trondmy@kernel.org> <20220313170557.5940-13-trondmy@kernel.org> <20220313170557.5940-14-trondmy@kernel.org> <20220313170557.5940-15-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 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 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 | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index bbf4357ff727..e51d86707fca 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -780,26 +780,32 @@ 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); - nfs_readdir_record_entry_cache_miss(d_inode(parent)); - dput(parent); +static void nfs_readdirplus_parent_cache_miss(struct dentry *dentry) +{ + if (!IS_ROOT(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); - nfs_readdir_record_entry_cache_hit(d_inode(parent)); - dput(parent); + if (!IS_ROOT(dentry)) { + struct dentry *parent = dget_parent(dentry); + nfs_readdir_record_entry_cache_hit(d_inode(parent)); + dput(parent); + } } static u32 nfs_get_valid_attrmask(struct inode *inode) @@ -835,6 +841,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); @@ -843,7 +850,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; } @@ -893,15 +901,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