From patchwork Sat Nov 19 16:54:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9438269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5818B60469 for ; Sat, 19 Nov 2016 16:55:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49186292E7 for ; Sat, 19 Nov 2016 16:55:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DA74292E8; Sat, 19 Nov 2016 16:55:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA98F292F0 for ; Sat, 19 Nov 2016 16:55:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752859AbcKSQzD (ORCPT ); Sat, 19 Nov 2016 11:55:03 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:35109 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752520AbcKSQzC (ORCPT ); Sat, 19 Nov 2016 11:55:02 -0500 Received: by mail-io0-f195.google.com with SMTP id h133so619091ioe.2 for ; Sat, 19 Nov 2016 08:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=FMaPllMiJbLMp9uQUDXuSCuStYS+fGnHBG5AqB6inOU=; b=pkcg2A2tjV/WnB1XkMPzEuJWUugTTz/pWPdr9wqRdftKKx7k2QG5mpEWu1AN6XQSN8 zL3DyI+b6LH2IegU/eJ9M6L25LFklp7zLaiCD0Cao6ep/mMLpgd3eaAMbNEtSG0lP8bm hHUSKzwpnOVKqc3W+X8us+MclvQND3DogUkzPkvEiDNRDOCM7TDVxnHnWof0juWhO9GA QCMywbYFkyBfNsUxgj3AqOlmNgzM6/y8/I0LFBGFFpKeU/Qu3TqXskaZ7hGt8sP6rkW+ 0JCpRni4NY+mN5ma8ucQTFPNKqODZ/HR9D06VVlO4zGLS88qcsT4Uoyfoq6otMmqBkOQ cAdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=FMaPllMiJbLMp9uQUDXuSCuStYS+fGnHBG5AqB6inOU=; b=Ik6mp3+wuGZIE+BRZxqXvyKwGBxc+RQnROxVc6tXPMnVkepsfjLoBKYLWLTDHMexSr oUn/5NSYQ53mHfgdWIpsDC2MKCnPat3HsR5kMZAUJ0Mo8s2uH7OcFN1GCKPhlDdN+vcG 5wyHP0n+KK7LBW1wtbMNqEJsWFTqtJuUAUQejoA/iU6Cjhf1HpKP21sNbJaR+g3k0kR9 wRgMB4xfhuJOaYpX6F4CVn3sTdY+C9bnIKyaOBbs/f0QRcqzgrOBrB53gTwSAuQlx7sh 48nC/gEzKxI/1OSAirniiIvzQIybCsDwdLB+xIXh3Zei0y8JhZ5KVfYuVqf5RwuXKLWD VwZQ== X-Gm-Message-State: AKaTC01HQCAkkLpE4L1QL9RyyXhREbGNeuXlyA1dqcdrrqChY6qzra2mTQdnWWPufoG8uQ== X-Received: by 10.107.142.194 with SMTP id q185mr5004619iod.147.1479574502022; Sat, 19 Nov 2016 08:55:02 -0800 (PST) Received: from leira.trondhjem.org.localdomain (c-68-49-162-121.hsd1.mi.comcast.net. [68.49.162.121]) by smtp.gmail.com with ESMTPSA id h76sm4901356ioi.43.2016.11.19.08.55.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Nov 2016 08:55:01 -0800 (PST) From: Trond Myklebust To: Benjamin Coddington Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/3] NFS: Fix a performance regression in readdir Date: Sat, 19 Nov 2016 11:54:55 -0500 Message-Id: <1479574497-38268-2-git-send-email-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479574497-38268-1-git-send-email-trond.myklebust@primarydata.com> References: <1479574497-38268-1-git-send-email-trond.myklebust@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ben Coddington reports that commit 311324ad1713, by adding the function nfs_dir_mapping_need_revalidate() that checks page cache validity on each call to nfs_readdir() causes a performance regression when the directory is being modified. If the directory is changing while we're iterating through the directory, POSIX does not require us to invalidate the page cache unless the user calls rewinddir(). However, we still do want to ensure that we use readdirplus in order to avoid a load of stat() calls when the user is doing an 'ls -l' workload. The fix should be to invalidate the page cache immediately when we're setting the NFS_INO_ADVISE_RDPLUS bit. Reported-by: Benjamin Coddington Fixes: 311324ad1713 ("NFS: Be more aggressive in using readdirplus...") Signed-off-by: Trond Myklebust Tested-by: Benjamin Coddington --- fs/nfs/dir.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 5f1af4cd1a33..53e02b8bd9bd 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -477,7 +477,7 @@ void nfs_force_use_readdirplus(struct inode *dir) { if (!list_empty(&NFS_I(dir)->open_files)) { nfs_advise_use_readdirplus(dir); - nfs_zap_mapping(dir, dir->i_mapping); + invalidate_mapping_pages(dir->i_mapping, 0, -1); } } @@ -886,17 +886,6 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc) goto out; } -static bool nfs_dir_mapping_need_revalidate(struct inode *dir) -{ - struct nfs_inode *nfsi = NFS_I(dir); - - if (nfs_attribute_cache_expired(dir)) - return true; - if (nfsi->cache_validity & NFS_INO_INVALID_DATA) - return true; - return false; -} - /* The file offset position represents the dirent entry number. A last cookie cache takes care of the common case of reading the whole directory. @@ -928,7 +917,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) desc->decode = NFS_PROTO(inode)->decode_dirent; desc->plus = nfs_use_readdirplus(inode, ctx) ? 1 : 0; - if (ctx->pos == 0 || nfs_dir_mapping_need_revalidate(inode)) + if (ctx->pos == 0 || nfs_attribute_cache_expired(inode)) res = nfs_revalidate_mapping(inode, file->f_mapping); if (res < 0) goto out;