Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1048070pxm; Wed, 23 Feb 2022 16:48:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJx27MJc+nwNdL3fgc4vTgb2RQzRMXXIgKIJgPAIhQ3ghCXdeCBAwSinh+irXjp6IVem506Y X-Received: by 2002:aa7:8515:0:b0:4e0:bd8:c238 with SMTP id v21-20020aa78515000000b004e00bd8c238mr244816pfn.69.1645663723315; Wed, 23 Feb 2022 16:48:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645663723; cv=none; d=google.com; s=arc-20160816; b=syYwAwj7818L5F9tXwQz0OlXHJftVh1m47C8e02RNpdmN3shGV4jwiwY+UcIHbK49i 4nbFvZnbfHzr+W4PUDS/3a/51mv8Ylugjk3lZjpNQWCx2HP4qUcbzsCsUTjDwoSwh1He G90QtvdLixTLeYAiWA+zKnHbtWf+O1+F7BRRnDn7+bawIeOyoR4aWAlkH80A+lKBKIci 8vbFzhcKDbQD9fr+2ou2Skl20PLNkHTcTv1wj7nzE/zs0XX1CclQArnJDE4EBjjU5MeD JlbVvfowjFKcbmtsgVWjv9TndptseoPBNOVb9tRPwnyHvLSJCtar07o9O6yCUo2+I5WB sKYg== 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=0cSirUM6KDrC8KaRCM+Qfut47VC45kHld7BEtJ5/G4A=; b=RcCR7iKusOjrox3pVfYqsglmNh4JPVN4D8Zo3UFUcMvDA1M85xsBzYMDxDecGQo7p7 64n1T+bAQt+7orCW/RoswzMnkNydzPaglBNO4od5HrnSmi17zfMnzcYcaguIBoixl6jQ fVs43Non4tQvts0bzWHunarzHno77P05xdGXUyxoKCobvAzxqEuJJF0tQmVZoO1zA25F Eey+o8IxdLy2xymOvt3mtOrZrCr5wO8CWCG5tvOiLn6WceaOskiJgNxi36D/XvpOB8Lv jc0Dsk+x1S6D+aLrm3nyUkvCc3hS/GJB8jjGG2tWYv7ZGPwqAUkWYWvQjb0oAJPCca3R fWOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HY7kUNRm; 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 205si938698pfx.245.2022.02.23.16.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 16:48:43 -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=HY7kUNRm; 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 6B20EE7299; Wed, 23 Feb 2022 16:43:50 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242398AbiBWVUC (ORCPT + 99 others); Wed, 23 Feb 2022 16:20:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242403AbiBWVUC (ORCPT ); Wed, 23 Feb 2022 16:20:02 -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 58D6C4ECC7 for ; Wed, 23 Feb 2022 13:19:34 -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 E81D56189F for ; Wed, 23 Feb 2022 21:19:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27877C340E7 for ; Wed, 23 Feb 2022 21:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645651173; bh=BDtVy5SNX6exg3u/FD6tPHlS7Ace5WAEZPBUVrHFAsI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HY7kUNRmMBazv8m5jd2YrPEMLakbDqEHepHDOqD+IOTFqFbiMHYN8ETC7z6PpKbzw POC1eWGMhc2oyB213GNo1qt4KeoQCHhvm7TnnhJdCyJvu4YDLL3coyRlw8QbbUOcOC 5lADKXhR0vEUp7n3QeJu7jqOm7EQ4aHv0/bkpF/dVoucuJWjLGqphQhBDmRnHq9TUA v0JHV6x+tMZNssRbcDXWpmO0AYc5x+IVZYolYdxcHHzncY7dCA1ifOLt4/QGZnNCsU qKO1poxbkjOqQdZeS7B73YDIgHEa93/PXj8aMmxs4dxkWoN+l4QhGWlDHH1qUXbU1r qL1aSWbM2nbyg== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v7 04/21] NFS: Calculate page offsets algorithmically Date: Wed, 23 Feb 2022 16:12:48 -0500 Message-Id: <20220223211305.296816-5-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223211305.296816-4-trondmy@kernel.org> References: <20220223211305.296816-1-trondmy@kernel.org> <20220223211305.296816-2-trondmy@kernel.org> <20220223211305.296816-3-trondmy@kernel.org> <20220223211305.296816-4-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 8f17aaebcd77..f2258e926df2 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -248,17 +248,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; } @@ -317,6 +320,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; @@ -447,7 +455,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