Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp956270pxp; Wed, 16 Mar 2022 22:35:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdqSCLY4kPMmW4yYlIFtZ71RaguUkJXAA+q17c5xyQmSPor5T+WXI6rjslNn2WJKTRPeRi X-Received: by 2002:a17:90b:1e47:b0:1bf:6d84:ca1d with SMTP id pi7-20020a17090b1e4700b001bf6d84ca1dmr3434948pjb.94.1647495305191; Wed, 16 Mar 2022 22:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647495305; cv=none; d=google.com; s=arc-20160816; b=LU6jk8wV6EW/xC7HiTTHs0gwrpYcVKnx6rLbYV/J0rW9ICrVPUO5oPR83GpGD8Kukc 1sRNCff7xoh22fTqXea+NaHjbMBm2RDQwYTD/FG/gfe04V7QpTjXSWIFPDneFi3nr82h jA8X0RSY7Dl9KTRBfqniuJiucx19XLz5ZFmf4YY5j8V3Zg3lwhcvgEZqk8zT0CGj5FgI PXpjm8ZPQlbY0qxaWZyvp5yh/D3gdB/2z5WWCZAgUhpIVW/Ry2lHGy9aAiMcruRDqvA9 xvCxK/EvrjJs/rC7jM8+v6edvrGGeNWB5U+L+OFxi8eA8odMj3EYF2pMWsjceyUn0l+t su3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZdEbzQFGgUC2obpBVOgXRw+BcVyqauFPV0jnUPzvYFI=; b=xrP5mK/4yHfl5wJVnTuqozd6KooSFZyPbRRlGuGaUCuy0jH87uerPpUsU8KP7hAqVz OKwe2/7+Gvu7nyS0uw+9Y+jdHaoPJGTWlf/2J+ep2J2vWyPuhyE+BSGGN2ovvcKPHXRx 9Uc1rUiPRHS22UMKynOZjSnlG1yElc8aUkPp6xtvLEnfnEWvhAodOkvIfld0G3aQsT/s 7WSWq2hDpEJC7eQzaWUxIWx0iJ8B9eS/NwgkzWD3Jp2CSMudlzgiXDt5H0SjmFHSgeLV 11Bp7239exYBxKMY22EVIVJCMKMxH2GcXTCa+sAVFW1pPmFn9wD0LenrmbvbGC6rkrqC Z3MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umich.edu header.s=google-2016-06-03 header.b=osTezEdT; 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=umich.edu Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k24-20020a170902ba9800b0015369243dd2si3491131pls.28.2022.03.16.22.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:35:05 -0700 (PDT) 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=@umich.edu header.s=google-2016-06-03 header.b=osTezEdT; 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=umich.edu Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A864619B06C; Wed, 16 Mar 2022 21:36:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbiCPW0k (ORCPT + 99 others); Wed, 16 Mar 2022 18:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229828AbiCPW0j (ORCPT ); Wed, 16 Mar 2022 18:26:39 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96025AE5B for ; Wed, 16 Mar 2022 15:25:23 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id bg10so7114319ejb.4 for ; Wed, 16 Mar 2022 15:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=google-2016-06-03; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZdEbzQFGgUC2obpBVOgXRw+BcVyqauFPV0jnUPzvYFI=; b=osTezEdTfcolwrZRRD7Q6ZtCvkkQyAZ/2TJuzfrUxzOTPvvLWiRsHGdSlHqTWWGz+p 5YcK86r9aKZbr9ptpsXmvhb+3T57cwvpVZdRPvKWnnsjI+t1EFB7qD+arxqeNP6CCf2M eDX5YEEWEAbLKJxUPy0nz0ualaSuHdEbV44pNEwMs6j2NPNOwLr9nnbCQBOdF3N7upFF pWp/uu5OU8ztJILmtFKjRJFdzMNvoL7iMT/jMPf1DOPzdQOCGlmZsIuwErOkmEupMGtQ jkclzld2587nINbonQGV0IhmkrdfaXo016eiIiK/cvlNWrWpPq8sEL0EOA0/JdmE2nJB A7eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZdEbzQFGgUC2obpBVOgXRw+BcVyqauFPV0jnUPzvYFI=; b=ljiGDM/577i7WuM65J8Aho+//vxlJwFxk7NlGOPNtf0riu97BognOfPmyeAxGtg6Ab 7pLEHS4jn7zGm/XFY1qv59FLmpxoQoXqQjPiZmnMfuyD7F2500d/+fomLMRLA61k1aZ8 Mem59K+4WRKcOHR/66I9lDtbfJufBLr+Ybreaye8i9ZmkNIjEJSWQ35tHK8H22N/rKDu qJOgvCi70barVidy+qRqMmziV4Fwdjg3Okm6oqmEhg6r/yLWJ7n+m3Q/vBeXMcDN2ToZ 3OXZA7fhRaaG+Oq1y6SZZGfzAWbb0ow9IF8x6s6WayDwfWs5LKcAQdN1r8jbSV36v21V EAOA== X-Gm-Message-State: AOAM532tTx5OlyJv5pbWMXnF2KV2ssJZ8c7CJgNoxLOAtxmhDImIyVd0 b8RVxbB4HmqeVCmMSAhNlwwtpjW07ECogBT3jxg= X-Received: by 2002:a17:907:1b0e:b0:6da:81ae:a798 with SMTP id mp14-20020a1709071b0e00b006da81aea798mr1681460ejc.699.1647469521995; Wed, 16 Mar 2022 15:25:21 -0700 (PDT) MIME-Version: 1.0 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> <20220227231227.9038-9-trondmy@kernel.org> <20220227231227.9038-10-trondmy@kernel.org> <20220227231227.9038-11-trondmy@kernel.org> <20220227231227.9038-12-trondmy@kernel.org> <20220227231227.9038-13-trondmy@kernel.org> <20220227231227.9038-14-trondmy@kernel.org> <20220227231227.9038-15-trondmy@kernel.org> <88cb6a4d7a074fd4c4c6b59076df766c7de54105.1646922313.git.bcodding@redhat.com> In-Reply-To: <88cb6a4d7a074fd4c4c6b59076df766c7de54105.1646922313.git.bcodding@redhat.com> From: Olga Kornievskaia Date: Wed, 16 Mar 2022 18:25:10 -0400 Message-ID: Subject: Re: [PATCH] NFS: Trigger "ls -l" readdir heuristic sooner To: Benjamin Coddington Cc: trondmy@kernel.org, linux-nfs Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Fri, Mar 11, 2022 at 9:40 AM Benjamin Coddington wrote: > > .. Something like this does the trick in my testing, but yes will have an > impact on regular workloads: > > 8<------------------------------------------------------------------------ > > Since commit 1a34c8c9a49e ("NFS: Support larger readdir buffers") has > updated dtsize and recent improvements to the READDIRPLUS helper heuristic, > the heuristic may not trigger until many dentries are emitted to userspace, > which may cause many thousands of GETATTR calls for "ls -l" when the > directory's pagecache has already been populated. This typically manifests > as a much slower total runtime for a _second_ invocation of "ls -l" within > the directory attribute cache timeouts. > > Fix this by emitting only 17 entries for any first pass through the NFS > directory's ->iterate_shared(), which will allow userpace to prime the > counters for the heuristic. Here's for what it's worth. An experiment between linux to linux where the linux server had a "small" directory structure of 57274 directories, 5727390 files in total where each directory had ~100 files each. With this patch: date; time tree vol1 > tree.out && date; time tree vol1 > tree.out Wed Mar 16 12:21:30 EDT 2022 real 11m7.923s user 0m20.507s sys 0m39.683s Wed Mar 16 12:32:38 EDT 2022 real 40m1.751s user 0m23.477s sys 0m45.663s Without the patch: date; time tree vol1 > tree.out && date; time tree vol1 > tree.out Wed Mar 16 13:49:12 EDT 2022 real 10m52.909s user 0m21.342s sys 0m39.198s Wed Mar 16 14:00:05 EDT 2022 real 222m56.990s user 0m30.392s sys 2m25.202s > > Signed-off-by: Benjamin Coddington > --- > fs/nfs/dir.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c > index 7e12102b29e7..dc5fc9ba2c49 100644 > --- a/fs/nfs/dir.c > +++ b/fs/nfs/dir.c > @@ -1060,6 +1060,8 @@ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc) > return res; > } > > +#define NFS_READDIR_CACHE_MISS_THRESHOLD (16UL) > + > /* > * Once we've found the start of the dirent within a page: fill 'er up... > */ > @@ -1069,6 +1071,7 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc, > struct file *file = desc->file; > struct nfs_cache_array *array; > unsigned int i; > + bool first_emit = !desc->dir_cookie; > > array = kmap(desc->page); > for (i = desc->cache_entry_index; i < array->size; i++) { > @@ -1092,6 +1095,10 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc, > desc->ctx->pos = desc->dir_cookie; > else > desc->ctx->pos++; > + if (first_emit && i > NFS_READDIR_CACHE_MISS_THRESHOLD + 1) { > + desc->eob = true; > + break; > + } > } > if (array->page_is_eof) > desc->eof = !desc->eob; > @@ -1173,8 +1180,6 @@ static int uncached_readdir(struct nfs_readdir_descriptor *desc) > return status; > } > > -#define NFS_READDIR_CACHE_MISS_THRESHOLD (16UL) > - > static bool nfs_readdir_handle_cache_misses(struct inode *inode, > struct nfs_readdir_descriptor *desc, > unsigned int cache_misses, > -- > 2.31.1 >