Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2504352pxp; Sun, 13 Mar 2022 20:43:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3MV7PwP/7j8YEb/x6uTdALYpyvbx+J/kP/0XY3qizp0Kq+x+VyXtgx1qUIDCF4aM6swDs X-Received: by 2002:a17:906:2ecd:b0:6d3:d7c9:8fa4 with SMTP id s13-20020a1709062ecd00b006d3d7c98fa4mr16711745eji.144.1647229421908; Sun, 13 Mar 2022 20:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647229421; cv=none; d=google.com; s=arc-20160816; b=FK6zAlCrIzEu2+hMSEQ5Wi6hBRJd+74mBmf4Z0ddu7E7xF1+PKyo6FFGvqPHWfPVy9 iY+5bj7Uz6C+C+nTO5KXbQCdGhtnhs4j1tz7SRQUBYqaquS3yqFo0O9xgZh5n6aP6NeH AYHf3C15PitIBEwxTyBV9u8nZA5Jxh/N4A3913hIJ+QWwQTI2P35POmN73ucSpZMWkdf Z/WjZ8W2rr5K8KdV0IkOsIW3zQezQCoHjR944gKX3U70kdBAFCt+2KKXF87tuJ38r8DV YIfGa/+GJ5vcdgE+t60wtgqg/1gCNczExgVYs2RcP1XMtASODLLYgeQ8RPHdPUy8mK5F YqtA== 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=eQqQltRUxsQkCv9eWMSUi2nLahVHW7eyQNfdHo5wYbE=; b=HmPzv4rEzTkv+4w66Q8rbXVnHVh7WrkFTEymipJG16LqS3Rpw6440uwTuxDWsXw1le S6eT3tMQzR9d2dRJ9EYNNmp3Ow3B0vFTgntrSVccfV0Lii/Sa/NSA85cdGJgb/Kq1rL/ GhT4GioM+CXFM9pclYDik3vTMiTBwRgiDGWi1S9Fdu2C8iwSAwLm+W/qa1CLt1YZ6QCY 1EW+l5hilHV7y0/Tj+HspWzp8++MUYxjaSLPL+IcXZCKr/X3L7IevSQ7x/v4b+9c8dIX 46aCIhw2a/Wec/qOe9Kge4OWZ+wSY1bL5G+0EJb3f/dOQBFBtah7cqdgQJHwCEVQaVXy ifKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="r0XDu+/c"; 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 r6-20020a056402234600b00416a66c3f58si7248809eda.97.2022.03.13.20.43.05; Sun, 13 Mar 2022 20:43:41 -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="r0XDu+/c"; 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 S235117AbiCMRNT (ORCPT + 99 others); Sun, 13 Mar 2022 13:13:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235094AbiCMRNR (ORCPT ); Sun, 13 Mar 2022 13:13:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11481139CDC for ; Sun, 13 Mar 2022 10:12:09 -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 ams.source.kernel.org (Postfix) with ESMTPS id C376DB80CB3 for ; Sun, 13 Mar 2022 17:12:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40D63C340EE for ; Sun, 13 Mar 2022 17:12:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647191526; bh=nAkgAnoC68H8WXGvb3X6kwP1/KNqjLl8An7UgPcZqUI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=r0XDu+/cdL+ZTtm90dvjwvz8KfHLHqIzNq8SYtWMrqi8daFLMBx0Yoz7xmykgByoT 27k6qM8rrqDPDAbWHTVT6y9hM24sE0qhYPd2sJkQ4T+0MKxMTGCulbagsBwAT62zDc UPaaAaul7GiJuRyWrNtrBUxwXk3VfOOrS6i7AxI882MLLG6R+YB7VZ5XWeKiXnnuSH oY3sM6VpWFXCEZpCG1YUs5hm6FarZBfmqKQmVzgDRWJo6jkhdh88Crf/48MdmB8ICX YrHRZQWwqWg4K4rbrhjt30418VXiI4gN1FeoAWuR110tvcgpadrUuvVKlLikHC5D4U tZsHwBvSNwTiA== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v10 07/26] NFS: Store the change attribute in the directory page cache Date: Sun, 13 Mar 2022 13:05:38 -0400 Message-Id: <20220313170557.5940-8-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220313170557.5940-7-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> <20220313170557.5940-7-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 Use the change attribute and the first cookie in a directory page cache entry to validate that the page is up to date. Suggested-by: Benjamin Coddington Signed-off-by: Trond Myklebust --- fs/nfs/dir.c | 68 ++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 6f0a38db6c37..a1767f755460 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -140,6 +140,7 @@ struct nfs_cache_array_entry { }; struct nfs_cache_array { + u64 change_attr; u64 last_cookie; unsigned int size; unsigned char page_full : 1, @@ -176,12 +177,14 @@ static void nfs_readdir_array_init(struct nfs_cache_array *array) memset(array, 0, sizeof(struct nfs_cache_array)); } -static void nfs_readdir_page_init_array(struct page *page, u64 last_cookie) +static void nfs_readdir_page_init_array(struct page *page, u64 last_cookie, + u64 change_attr) { struct nfs_cache_array *array; array = kmap_atomic(page); nfs_readdir_array_init(array); + array->change_attr = change_attr; array->last_cookie = last_cookie; array->cookies_are_ordered = 1; kunmap_atomic(array); @@ -208,7 +211,7 @@ nfs_readdir_page_array_alloc(u64 last_cookie, gfp_t gfp_flags) { struct page *page = alloc_page(gfp_flags); if (page) - nfs_readdir_page_init_array(page, last_cookie); + nfs_readdir_page_init_array(page, last_cookie, 0); return page; } @@ -305,19 +308,43 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page) return ret; } +static bool nfs_readdir_page_validate(struct page *page, u64 last_cookie, + u64 change_attr) +{ + struct nfs_cache_array *array = kmap_atomic(page); + int ret = true; + + if (array->change_attr != change_attr) + ret = false; + if (array->size > 0 && array->array[0].cookie != last_cookie) + ret = false; + kunmap_atomic(array); + return ret; +} + +static void nfs_readdir_page_unlock_and_put(struct page *page) +{ + unlock_page(page); + put_page(page); +} + static struct page *nfs_readdir_page_get_locked(struct address_space *mapping, pgoff_t index, u64 last_cookie) { struct page *page; + u64 change_attr; page = grab_cache_page(mapping, index); - if (page && !PageUptodate(page)) { - nfs_readdir_page_init_array(page, last_cookie); - if (invalidate_inode_pages2_range(mapping, index + 1, -1) < 0) - nfs_zap_mapping(mapping->host, mapping); - SetPageUptodate(page); + if (!page) + return NULL; + change_attr = inode_peek_iversion_raw(mapping->host); + if (PageUptodate(page)) { + if (nfs_readdir_page_validate(page, last_cookie, change_attr)) + return page; + nfs_readdir_clear_array(page); } - + nfs_readdir_page_init_array(page, last_cookie, change_attr); + SetPageUptodate(page); return page; } @@ -357,12 +384,6 @@ static void nfs_readdir_page_set_eof(struct page *page) kunmap_atomic(array); } -static void nfs_readdir_page_unlock_and_put(struct page *page) -{ - unlock_page(page); - put_page(page); -} - static struct page *nfs_readdir_page_get_next(struct address_space *mapping, pgoff_t index, u64 cookie) { @@ -419,16 +440,6 @@ static int nfs_readdir_search_for_pos(struct nfs_cache_array *array, return -EBADCOOKIE; } -static bool -nfs_readdir_inode_mapping_valid(struct nfs_inode *nfsi) -{ - if (nfsi->cache_validity & (NFS_INO_INVALID_CHANGE | - NFS_INO_INVALID_DATA)) - return false; - smp_rmb(); - return !test_bit(NFS_INO_INVALIDATING, &nfsi->flags); -} - static bool nfs_readdir_array_cookie_in_range(struct nfs_cache_array *array, u64 cookie) { @@ -457,8 +468,7 @@ static int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, struct nfs_inode *nfsi = NFS_I(file_inode(desc->file)); new_pos = nfs_readdir_page_offset(desc->page) + i; - if (desc->attr_gencount != nfsi->attr_gencount || - !nfs_readdir_inode_mapping_valid(nfsi)) { + if (desc->attr_gencount != nfsi->attr_gencount) { desc->duped = 0; desc->attr_gencount = nfsi->attr_gencount; } else if (new_pos < desc->prev_index) { @@ -1095,11 +1105,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) * to either find the entry with the appropriate number or * revalidate the cookie. */ - if (ctx->pos == 0 || nfs_attribute_cache_expired(inode)) { - res = nfs_revalidate_mapping(inode, file->f_mapping); - if (res < 0) - goto out; - } + nfs_revalidate_mapping(inode, file->f_mapping); res = -ENOMEM; desc = kzalloc(sizeof(*desc), GFP_KERNEL); -- 2.35.1