Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp716105pxm; Fri, 25 Feb 2022 18:08:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzT9a+yCxTWPoREZp87YCFPzqLQel8m2mIomwb//ZhT5xJeXn2xa7HV6b1TGO4HJ2SqLEze X-Received: by 2002:a17:902:e34b:b0:14f:c969:765a with SMTP id p11-20020a170902e34b00b0014fc969765amr10295776plc.82.1645841310486; Fri, 25 Feb 2022 18:08:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645841310; cv=none; d=google.com; s=arc-20160816; b=ypZU3GsOHju7TwYdqZu2hrTyj2pHsm12H1z3wHgv+2Eg+NTt/ZsqES6nQoP8IgMrpJ F3fTvMoZNA+tX79gkZUqMEQCWxy4yMkkAf44+c7+PKHB4bS8sEXF5G/ZwQUD+5OW/HSn UmKCWUEXr2cM+WQkAkTCMzX/qzvzv1P6q+Li+6f5q5Z1uIkuSF7KmjJL5FovKfXnKfaI yqMzti/wcq1p0jxhYnJwUYQ3DAIGJ/uOn6nr49PiL8/QuPN5bLDhwyuw74eT6pwOWbyx 9sepyth7IPWT3AuhFhaMM5tYN7/Epa8isoGjsd7RBKFP4YGNuijnORHQ12vsf0PFdxWo M3Jw== 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=zI9YJa/2SlO+zcA//Q7neRHtM9ClgEslO7JQ7NyVkzdYQRCbHDx8O1Zx7Ix6pyh3+S 8Kil23N62Thg7AQpqJh5wyNljJBjDA+vNJ8LZ2ntPKn5da38CfGKynwWoCe3PvRRIkx6 AT7zCZePyVgUFuoVwhYBhWM17ov8ZOPxbLLcvZK8mrZrySdiO5bogLgMLPJbtOOGxOTC +30IhwJPjIoeK8IMNo39B2e28GVuAgpVcS3sGFrXAc/sTX5WMcbpZpAF8G3N6G3wTp/5 f1ak1Yv/N6+Nggj7HrzKNLjdK507wpTWpmIqZzGNNDY1sdxl98b5oJyMS50cfB99cArs NZlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dcLkRgFD; 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=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f10-20020a170902ff0a00b0014fb0382a7bsi3268718plj.610.2022.02.25.18.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 18:08:30 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=dcLkRgFD; 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=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AF4D92AFF6A; Fri, 25 Feb 2022 17:46:38 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233367AbiBYSfU (ORCPT + 99 others); Fri, 25 Feb 2022 13:35:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233363AbiBYSfQ (ORCPT ); Fri, 25 Feb 2022 13:35:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E3161A9069 for ; Fri, 25 Feb 2022 10:34:41 -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 ams.source.kernel.org (Postfix) with ESMTPS id 9E118B8330E for ; Fri, 25 Feb 2022 18:34:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 172D1C340F1 for ; Fri, 25 Feb 2022 18:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645814078; bh=zYhvub24lZwHSGJubm8T+/Fb/2omFYNma1blsw8u/iU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dcLkRgFDY6MYPHiOTyEd4QsvSlUxrN7+Nwdte1VIrmh4Sxe/YkwLjCK27w6YB+sno C3JVw2n2X7dtWvxyfpUXaapDie1WScFyuRbTGsK9h3wEESASgULXiwDhFhBQRUTq+o K8jYAQFMEMToIelxbObjbMe0s1mGOsCMtrZyQY85KM+qtrtCR0H0O97mBXXeXyQarI WuoQUcSvrRUQtuZC38/+382YLqur2NTgpVUd6hHql5dRzBWev6iOOpLBDbodhQTFbv FxnPvPe8w3f4LyALSELCJgRPz0Nn3fxGyhU1cdHHpT36CS214X+4UzZk5JJ9lp2jU6 UVb/S1XX3ZtUA== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v8 06/24] NFS: Calculate page offsets algorithmically Date: Fri, 25 Feb 2022 13:28:11 -0500 Message-Id: <20220225182829.1236093-7-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220225182829.1236093-6-trondmy@kernel.org> References: <20220225182829.1236093-1-trondmy@kernel.org> <20220225182829.1236093-2-trondmy@kernel.org> <20220225182829.1236093-3-trondmy@kernel.org> <20220225182829.1236093-4-trondmy@kernel.org> <20220225182829.1236093-5-trondmy@kernel.org> <20220225182829.1236093-6-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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