Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2456554imm; Sat, 16 Jun 2018 19:19:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIOJYGTyzk5PRkZFT4jYdvq18wOoTsyKCqZS83VzMqIPNWXCwhop7Fm10yjPaOvE851TqHT X-Received: by 2002:a62:6406:: with SMTP id y6-v6mr8150048pfb.204.1529201987586; Sat, 16 Jun 2018 19:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529201987; cv=none; d=google.com; s=arc-20160816; b=jq+mpSp1ugbWiS/jicMGw7Ab8Z7LDuiqQEl7VWMVgbjf/hWeOpLfaCzY+Seqicu4jZ 3fQi42N2n4ZCt0R7C96s6XF2V5yN+26DjHtt45kJjYDw2PDE8xPYpyx1f7XXcwIGq0Yz 5gRDfodKAbfKuI7kM5VXmJ7F6E96mHI449S/n/E/xBuSATZvy0coCWBfpgXYyubeQk5e Zf0wxh7ppjMzKd1D91sMp53R7hvLncyHLhm0MZJXvrkb0NjVTFsb0yUZ8lPs5IIv5bgS ARmeDXXjBw4Nic7LW8MYg99Sn3fiDsOd7chfkm0yhGo1WPbiUAYXN2kFWCbOONpR3+5a Okxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=r5CukERBzeIlr83uJco+d+VA4O1H8AQ0gO0fzR7QlcY=; b=hhxOO24/14HRGnBLN3chvOFRsgJwDHz6W9Q4dejBCzw8gPfso91KOgzVj1U0b9NOgn vWjzuo9GwS6JhCOtGo/H/zumz4RD58C0xfEMMFyLT5kkYmeWqSPutdEheD2See1pbN+u T56Ax+hw/cyZd46KgIq9f17X+IGfgEJUxjoCu1ryGbwVOfiiSKssDQnLsR4iqTqauJtI OJOFJTmquq4EX/RgxWkY4nMjY8YGq724gFgS+Yki7zk8ISKBoYuJ7ReLs67TSxjQ3yTf SCBQl90pZV9d6885iOoPR6IUO8qLel9j7OoRf7Sy6xnV8Eo5oIRlQay0Bv8j+OSXvPvq oirA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=g3lwimEi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8-v6si12578417plb.381.2018.06.16.19.19.33; Sat, 16 Jun 2018 19:19:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=g3lwimEi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757079AbeFQCSY (ORCPT + 99 others); Sat, 16 Jun 2018 22:18:24 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58752 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933604AbeFQCBA (ORCPT ); Sat, 16 Jun 2018 22:01:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=r5CukERBzeIlr83uJco+d+VA4O1H8AQ0gO0fzR7QlcY=; b=g3lwimEixpXcUgohYChEkZtdz KwtKpKEVIHRsMIDjtXndB528/7mspQy7lemPMRVSf2zv3eeLNbm5RUZCZvdaAG34MfOAUH8dRF2/X U8GfQKTloejRWx4/xhXh2IT2sTkw6R0VSMva1pe3Pc/8FZLkl1mnev7orE9UhVTsSkxlRfd+agKbW Mc5tbBMT0rnlSXj/gWatpCtkdXFfM92SAuhSKjOLiSASHrK/hn9LdNFM1L5lP0n/hcrpRXMJvOgn5 O9sXLaa1Hejr0piN9oqWTIcPGLPVp9hJzqG7cyDWRWxFovEh2N9jZlAnTO9w91tb2cMnliW1Q6V5R +sBQNJk4g==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUN00-0001IZ-6C; Sun, 17 Jun 2018 02:01:00 +0000 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Jan Kara , Jeff Layton , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Nicholas Piggin , Ryusuke Konishi , linux-nilfs@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v14 27/74] page cache: Convert find_get_pages_contig to XArray Date: Sat, 16 Jun 2018 19:00:05 -0700 Message-Id: <20180617020052.4759-28-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180617020052.4759-1-willy@infradead.org> References: <20180617020052.4759-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There's no direct replacement for radix_tree_for_each_contig() in the XArray API as it's an unusual thing to do. Instead, open-code a loop using xas_next(). This removes the only user of radix_tree_for_each_contig() so delete the iterator from the API and the test suite code for it. Signed-off-by: Matthew Wilcox --- .clang-format | 1 - include/linux/radix-tree.h | 17 --------- mm/filemap.c | 53 +++++++++++--------------- tools/testing/radix-tree/regression3.c | 23 ----------- 4 files changed, 22 insertions(+), 72 deletions(-) diff --git a/.clang-format b/.clang-format index faffc0d5af4e..c1de31c6875e 100644 --- a/.clang-format +++ b/.clang-format @@ -323,7 +323,6 @@ ForEachMacros: - 'protocol_for_each_card' - 'protocol_for_each_dev' - 'queue_for_each_hw_ctx' - - 'radix_tree_for_each_contig' - 'radix_tree_for_each_slot' - 'radix_tree_for_each_tagged' - 'rbtree_postorder_for_each_entry_safe' diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h index 4b6f685309fc..eefa0b099dd5 100644 --- a/include/linux/radix-tree.h +++ b/include/linux/radix-tree.h @@ -522,23 +522,6 @@ static __always_inline void __rcu **radix_tree_next_slot(void __rcu **slot, slot || (slot = radix_tree_next_chunk(root, iter, 0)) ; \ slot = radix_tree_next_slot(slot, iter, 0)) -/** - * radix_tree_for_each_contig - iterate over contiguous slots - * - * @slot: the void** variable for pointer to slot - * @root: the struct radix_tree_root pointer - * @iter: the struct radix_tree_iter pointer - * @start: iteration starting index - * - * @slot points to radix tree slot, @iter->index contains its index. - */ -#define radix_tree_for_each_contig(slot, root, iter, start) \ - for (slot = radix_tree_iter_init(iter, start) ; \ - slot || (slot = radix_tree_next_chunk(root, iter, \ - RADIX_TREE_ITER_CONTIG)) ; \ - slot = radix_tree_next_slot(slot, iter, \ - RADIX_TREE_ITER_CONTIG)) - /** * radix_tree_for_each_tagged - iterate over tagged slots * diff --git a/mm/filemap.c b/mm/filemap.c index 019c263bb6be..8a69613fcdf3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1721,57 +1721,43 @@ unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start, unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, unsigned int nr_pages, struct page **pages) { - struct radix_tree_iter iter; - void **slot; + XA_STATE(xas, &mapping->i_pages, index); + struct page *page; unsigned int ret = 0; if (unlikely(!nr_pages)) return 0; rcu_read_lock(); - radix_tree_for_each_contig(slot, &mapping->i_pages, &iter, index) { - struct page *head, *page; -repeat: - page = radix_tree_deref_slot(slot); - /* The hole, there no reason to continue */ - if (unlikely(!page)) - break; - - if (radix_tree_exception(page)) { - if (radix_tree_deref_retry(page)) { - slot = radix_tree_iter_retry(&iter); - continue; - } - /* - * A shadow entry of a recently evicted page, - * or a swap entry from shmem/tmpfs. Stop - * looking for contiguous pages. - */ + for (page = xas_load(&xas); page; page = xas_next(&xas)) { + struct page *head; + if (xas_retry(&xas, page)) + continue; + /* + * If the entry has been swapped out, we can stop looking. + * No current caller is looking for DAX entries. + */ + if (xa_is_value(page)) break; - } head = compound_head(page); if (!page_cache_get_speculative(head)) - goto repeat; + goto retry; /* The page was split under us? */ - if (compound_head(page) != head) { - put_page(head); - goto repeat; - } + if (compound_head(page) != head) + goto put_page; /* Has the page moved? */ - if (unlikely(page != *slot)) { - put_page(head); - goto repeat; - } + if (unlikely(page != xas_reload(&xas))) + goto put_page; /* * must check mapping and index after taking the ref. * otherwise we can get both false positives and false * negatives, which is just confusing to the caller. */ - if (page->mapping == NULL || page_to_pgoff(page) != iter.index) { + if (!page->mapping || page_to_pgoff(page) != xas.xa_index) { put_page(page); break; } @@ -1779,6 +1765,11 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, pages[ret] = page; if (++ret == nr_pages) break; + continue; +put_page: + put_page(head); +retry: + xas_reset(&xas); } rcu_read_unlock(); return ret; diff --git a/tools/testing/radix-tree/regression3.c b/tools/testing/radix-tree/regression3.c index ace2543c3eda..9f9a3b280f56 100644 --- a/tools/testing/radix-tree/regression3.c +++ b/tools/testing/radix-tree/regression3.c @@ -69,21 +69,6 @@ void regression3_test(void) continue; } } - radix_tree_delete(&root, 1); - - first = true; - radix_tree_for_each_contig(slot, &root, &iter, 0) { - printv(2, "contig %ld %p\n", iter.index, *slot); - if (first) { - radix_tree_insert(&root, 1, ptr); - first = false; - } - if (radix_tree_deref_retry(*slot)) { - printv(2, "retry at %ld\n", iter.index); - slot = radix_tree_iter_retry(&iter); - continue; - } - } radix_tree_for_each_slot(slot, &root, &iter, 0) { printv(2, "slot %ld %p\n", iter.index, *slot); @@ -93,14 +78,6 @@ void regression3_test(void) } } - radix_tree_for_each_contig(slot, &root, &iter, 0) { - printv(2, "contig %ld %p\n", iter.index, *slot); - if (!iter.index) { - printv(2, "next at %ld\n", iter.index); - slot = radix_tree_iter_resume(slot, &iter); - } - } - radix_tree_tag_set(&root, 0, 0); radix_tree_tag_set(&root, 1, 0); radix_tree_for_each_tagged(slot, &root, &iter, 0, 0) { -- 2.17.1