Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2220288pxp; Sun, 13 Mar 2022 12:07:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo5JS6eo810YTCAdCXs++PASe9vXGOeSThmXXJ2dPc7VTuN6kvEO0w95pvH6RV/a24hRsJ X-Received: by 2002:a17:906:49d4:b0:6d6:e5ec:9a23 with SMTP id w20-20020a17090649d400b006d6e5ec9a23mr16219894ejv.79.1647198471875; Sun, 13 Mar 2022 12:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647198471; cv=none; d=google.com; s=arc-20160816; b=jf5Xb8m/c1YqaSMSR8RSy7q0lwyIh/U2yYGx8jL1wTeLKaoF+N0dsFQ4azsYpFfqmi K6iZskOUKxeIcWFzH1LeTl9yjf/p6n07EsUKnffVRAB5zxvjRJQQH8y3rvcWfYYYTVBP Lp0jqTz1Kb1e96EFg51DgflzInlv7tWNJRES7ax1oYI24rAgpguFvuV/NrZ6UVex/U48 ZnArYdP5gvhspLXbRoUQkZr+EfjF3aDcSVZr9xT0VZNWd9ZGhZcP3AbZJqOXCKvTVvfA 0/IhSHkeQAE5l2oHCzPAjg2st8cCUwo2v55D4LsmQSH5XH86cIqwGRL/z4tp4H/8gf3U lEvw== 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=eAbUpSTL8eXPztvdyJedw8qBKM5Q4V7DrNYtrG25+Gc7yGQtUlIhZ2zKGgMHmnkjSB ihwluzucXTRAl4u8YBqi/gYELU9iYZvMgQ593zGATQCNywCNq3OkVBrfdY5cTi0Vs/AT jPlVpf9Ul0PzNRd4qW699phUyHPCK1ZQDHCBMOkNbp79wKKK/yREpZq0TO5h+yJpeIXX aEUfPXxBEoZmKEQi10EusE8mn6XXhtprX2h2KZGhI6DuY9IBiqz4qAuypLCvurAdOsZh KLSVNazvmqsrbsKp5hAlgc8LTB0Hjx8VkVDXMharjta1xV397y7wm4SrQXjehIsDvUgi wzhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QKn0+px9; 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 sb31-20020a1709076d9f00b006db4be8d152si9241796ejc.886.2022.03.13.12.07.28; Sun, 13 Mar 2022 12:07:51 -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=QKn0+px9; 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 S235095AbiCMRNP (ORCPT + 99 others); Sun, 13 Mar 2022 13:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234874AbiCMRNO (ORCPT ); Sun, 13 Mar 2022 13:13:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA96139CDD for ; Sun, 13 Mar 2022 10:12:06 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 38A4960FDD for ; Sun, 13 Mar 2022 17:12:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1627C340F3 for ; Sun, 13 Mar 2022 17:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647191526; bh=zYhvub24lZwHSGJubm8T+/Fb/2omFYNma1blsw8u/iU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QKn0+px9pOks7TwTHFSS53MbLE1H4J+28W7UIEOAMAz3oWOdys07VD4ZFTus0/7Jy uvjxu+Ow8HJDTmbhgjtAdlFR9yC7THi4pNEhbwnNR2nyyYfRF3nqpHkusvQYdgtO6M 07P+QfW3gR5vYEFHrzth9oZHPD5S4Q6B7yh1DPv00EH8pSHqFwbs4foGA7s788LeqD haMEXAwpXbtFFkuIvgjgofSHs8huYr7xC5bFXzqlS6MLAHHhGJ+pqjTgYn/MxyaPYo Kjtj6M24RormKMfbx0JLZhjOaz/VZTg7Tp5Part1Cjg1mXOV3kBCoJzLFrqvWBB/Co e1PPke8ZHFqAg== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v10 06/26] NFS: Calculate page offsets algorithmically Date: Sun, 13 Mar 2022 13:05:37 -0400 Message-Id: <20220313170557.5940-7-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220313170557.5940-6-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> 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 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