Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2008782pxb; Sat, 7 Nov 2020 06:14:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzote11FjcdGOeEK0i9uSSvo2l1j1b8FI5ZFw2rlGctoltMAxPwDeHvHvbZjqa7GDF0aenI X-Received: by 2002:a17:906:4059:: with SMTP id y25mr6891496ejj.498.1604758468687; Sat, 07 Nov 2020 06:14:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604758468; cv=none; d=google.com; s=arc-20160816; b=lAAimZjYlM2CgZzMf51S2H8ta5YDkmCnd0lWwMLdvETSIBkVxTA5ReHA6uD7V02F1i p/+j5ysZCUOVYue7GpCtePCTSgPVLVD8bBsOiw/RHw7scPzSp5caGprJXzLsFD+ZtJ0g CA0yYJlUa3yUcqKtAnajEjJvPWraR83MKqyAoXPeAXfj8t6YVAx0LgnreoO3l3MzYDmO 4r1ekhqLfOm1uG031CGSQfjNiCHDaIquwOHFJnldz4SU7OYvetPxBLyFloF/W5BYaTPm +NdfEq28K5R+8mT75IZ0Q0vlhvUg+qRKR1qEn/CLmjRVbpdHXmTfXz/+y1wUZmnOf94a f/lg== 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=QqEUP9ujx8JKAFWmVsvpzR2uWjnk60joL/ywa+OShsw=; b=Ki5SwzKrTe0YJBIZcSiXy9dGcrpyG7fB3BpIu/+qQLmA4IZEgy24lxKr3giMYeCEhu nPrm5/slarR/JuWcK3dPKryT0frSn55fT5eNNTE4NCsc4oi5lvizbz+lYklvsk1kcB/w 2Oel/bYjQQ+FnjaZ9NGCy7RgeJsZ3C57QaWA1MCXlifBYftlgDjsL/+0O+3VKOBWnblJ 6/BRfeSiUOnjAVpHaDNZViO3+GqdagCs83C6JYCobYSM6xuLVJtjnlLwhJinrsaYlsQc /auShjYQlO40oZAx6nSTeqUb/R/fcHddO+8FlHj6/RA8cDefbw9cEjQKyfEgZNvq7Aqy A6VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1k7Md09o; 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 y20si3298600edr.527.2020.11.07.06.14.06; Sat, 07 Nov 2020 06:14:28 -0800 (PST) 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=default header.b=1k7Md09o; 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 S1728181AbgKGONv (ORCPT + 99 others); Sat, 7 Nov 2020 09:13:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:58260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728144AbgKGONq (ORCPT ); Sat, 7 Nov 2020 09:13:46 -0500 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 963F02087E for ; Sat, 7 Nov 2020 14:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604758425; bh=X2+lGW7G/4LdYGNIaAOy3OIdR/2FceS3tTfu5QZPVLM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=1k7Md09odS3jjBoIxghAHHriL785EaRresQVZkcD9eF9apuUWH4x++59tJyC0O8KY hi+dAQrmgDdcVUhwqZLcIqPLofaW0CaybQuUffZay4Msh81rSsHP43RIoGpI2FzCfu LBKb8tzLf9MChKwKqS8ozVQEMNCt/vb5a13OllNU= From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v4 21/21] NFS: Do uncached readdir when we're seeking a cookie in an empty page cache Date: Sat, 7 Nov 2020 09:03:25 -0500 Message-Id: <20201107140325.281678-22-trondmy@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201107140325.281678-21-trondmy@kernel.org> References: <20201107140325.281678-1-trondmy@kernel.org> <20201107140325.281678-2-trondmy@kernel.org> <20201107140325.281678-3-trondmy@kernel.org> <20201107140325.281678-4-trondmy@kernel.org> <20201107140325.281678-5-trondmy@kernel.org> <20201107140325.281678-6-trondmy@kernel.org> <20201107140325.281678-7-trondmy@kernel.org> <20201107140325.281678-8-trondmy@kernel.org> <20201107140325.281678-9-trondmy@kernel.org> <20201107140325.281678-10-trondmy@kernel.org> <20201107140325.281678-11-trondmy@kernel.org> <20201107140325.281678-12-trondmy@kernel.org> <20201107140325.281678-13-trondmy@kernel.org> <20201107140325.281678-14-trondmy@kernel.org> <20201107140325.281678-15-trondmy@kernel.org> <20201107140325.281678-16-trondmy@kernel.org> <20201107140325.281678-17-trondmy@kernel.org> <20201107140325.281678-18-trondmy@kernel.org> <20201107140325.281678-19-trondmy@kernel.org> <20201107140325.281678-20-trondmy@kernel.org> <20201107140325.281678-21-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 the directory is changing, causing the page cache to get invalidated while we are listing the contents, then the NFS client is currently forced to read in the entire directory contents from scratch, because it needs to perform a linear search for the readdir cookie. While this is not an issue for small directories, it does not scale to directories with millions of entries. In order to be able to deal with large directories that are changing, add a heuristic to ensure that if the page cache is empty, and we are searching for a cookie that is not the zero cookie, we just default to performing uncached readdir. Signed-off-by: Trond Myklebust --- fs/nfs/dir.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 238872d116f7..d7a9efd31ecd 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -917,11 +917,28 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc) return res; } +static bool nfs_readdir_dont_search_cache(struct nfs_readdir_descriptor *desc) +{ + struct address_space *mapping = desc->file->f_mapping; + struct inode *dir = file_inode(desc->file); + unsigned int dtsize = NFS_SERVER(dir)->dtsize; + loff_t size = i_size_read(dir); + + /* + * Default to uncached readdir if the page cache is empty, and + * we're looking for a non-zero cookie in a large directory. + */ + return desc->dir_cookie != 0 && mapping->nrpages == 0 && size > dtsize; +} + /* Search for desc->dir_cookie from the beginning of the page cache */ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc) { int res; + if (nfs_readdir_dont_search_cache(desc)) + return -EBADCOOKIE; + do { if (desc->page_index == 0) { desc->current_index = 0; -- 2.28.0