Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2294412pxm; Sun, 27 Feb 2022 17:22:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwusrSWyVIkNf7abEjUtucBS45eKjNE/a3X/4LTemKZjyDpz8/iBFsO04Jwh+LFptWNNbHZ X-Received: by 2002:a05:6a00:1694:b0:4e1:9050:1e19 with SMTP id k20-20020a056a00169400b004e190501e19mr19081992pfc.72.1646011335286; Sun, 27 Feb 2022 17:22:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646011335; cv=none; d=google.com; s=arc-20160816; b=R85GY+HHrS//OL9EPXhOKyxuo/lYooSV5NEqW8JbZp36qE/8hCuLxxZqLrOPUWzW5T 6D081B9/0wfY7802IOa07ljstqFOZ44h5/MLOt4ySTLZB1HZIfjq/1P2MWwLC0iIogEY cePZhYyH2MOQqX8eeHp/fq2faMwrhagailp9Nl8WqYbg64yukdkfV+P3EAizwWfzj8Dc OzW3DOzYNEQ0TtDagQJxci7ekzG/BBjBku9MN1846LPCF8dy6uw0dzM7bHaxuCbe/uB3 A16JC9xJsPjqDiP0GX6/U4Pb+XrXmPbnarviPtC0JtWZia40rkWgkIqmoWEB+/SrpLT6 quDw== 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=+qZjgALM/xc0pDxuVs1ffxIUqXuhhYmYYvhrGbT1Cko=; b=unemi+54YLeuh67JQuXfewBwaelq/PB1qf9cSX4JRN+J43mxz4751Pk6cSvTe9LrlB c+uKkDy/B7Hxhs1MrMWonZqnmAZgeajYL/nPwVgoVDQLliMNLz/t91Lvz4V4ZsFSOzGL e3sG7H4d5DYiskARbHkt2Fz5X6nF5fa18JtQYyFu8CQe/aIJ74o6ebsMojqNmJam9BZ7 Of3opyHOHYcnMEVJkalsl1QsouZ3QCByJ/+BTcwkNraf5KNF3xulGn64G05y6/zIKTFh yR3/j9hksCRTSY6jRP29RZOL0FsQURLpeLpz7t0jqWVJ9jNjcBMlrnQjOxi8n5uixSKo 7xCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jBWxwXUH; 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 r10-20020a056a00216a00b004e1baee50dasi7935798pff.36.2022.02.27.17.21.46; Sun, 27 Feb 2022 17:22:15 -0800 (PST) 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=jBWxwXUH; 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 S232196AbiB0XTR (ORCPT + 99 others); Sun, 27 Feb 2022 18:19:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbiB0XTP (ORCPT ); Sun, 27 Feb 2022 18:19:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7AA72250A for ; Sun, 27 Feb 2022 15:18:37 -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 5E36C611AF for ; Sun, 27 Feb 2022 23:18:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 047ADC340F5 for ; Sun, 27 Feb 2022 23:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646003916; bh=zYhvub24lZwHSGJubm8T+/Fb/2omFYNma1blsw8u/iU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jBWxwXUHAXsr95BHLHDLcEKu3GYobwNFDkeCXrYdvi/760livNlvuIUzpC4foNFuN i9fCiuTIRuEpW+4JlM2/pAXE1FAHCFupY2PHBICw2WZOJwxnmxPhIVfTpSQfk+fxRG xAXjMaG2Epwe1eouUrPYFWT1+DhxEjt7GTfu/FgQvlDihiPdvHk2QmOpBmkXpEK7lM n3grR/JiPKxwExN117/twy5gPQOJwTr0p4HwL/KlKEDiAnmBWw4iGWZfT84rxFxod8 0tXB/uCBBWDMmGiHn3qsknUobgTjfdhFPcJKSczOrD+MpluezsRD6kufA+Ckem/pgh pCkM7WyBFM58g== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v9 06/27] NFS: Calculate page offsets algorithmically Date: Sun, 27 Feb 2022 18:12:06 -0500 Message-Id: <20220227231227.9038-7-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220227231227.9038-6-trondmy@kernel.org> 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 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 Instead of relying on counting the page offsets as we walk through the page cache, switch to calculating them algorithmically. Signed-off-by: Trond Myklebust --- fs/nfs/dir.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 379f88b158fb..6f0a38db6c37 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -249,17 +249,20 @@ static const char *nfs_readdir_copy_name(const char *name, unsigned int len) return ret; } +static size_t nfs_readdir_array_maxentries(void) +{ + return (PAGE_SIZE - sizeof(struct nfs_cache_array)) / + sizeof(struct nfs_cache_array_entry); +} + /* * Check that the next array entry lies entirely within the page bounds */ static int nfs_readdir_array_can_expand(struct nfs_cache_array *array) { - struct nfs_cache_array_entry *cache_entry; - if (array->page_full) return -ENOSPC; - cache_entry = &array->array[array->size + 1]; - if ((char *)cache_entry - (char *)array > PAGE_SIZE) { + if (array->size == nfs_readdir_array_maxentries()) { array->page_full = 1; return -ENOSPC; } @@ -318,6 +321,11 @@ static struct page *nfs_readdir_page_get_locked(struct address_space *mapping, return page; } +static loff_t nfs_readdir_page_offset(struct page *page) +{ + return (loff_t)page->index * (loff_t)nfs_readdir_array_maxentries(); +} + static u64 nfs_readdir_page_last_cookie(struct page *page) { struct nfs_cache_array *array; @@ -448,7 +456,7 @@ static int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, if (array->array[i].cookie == desc->dir_cookie) { struct nfs_inode *nfsi = NFS_I(file_inode(desc->file)); - new_pos = desc->current_index + i; + new_pos = nfs_readdir_page_offset(desc->page) + i; if (desc->attr_gencount != nfsi->attr_gencount || !nfs_readdir_inode_mapping_valid(nfsi)) { desc->duped = 0; -- 2.35.1