From patchwork Sun Jun 17 02:00:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10468197 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EC357600CC for ; Sun, 17 Jun 2018 02:01:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB97628BC1 for ; Sun, 17 Jun 2018 02:01:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEEA828BDB; Sun, 17 Jun 2018 02:01:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 373C528BC1 for ; Sun, 17 Jun 2018 02:01:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D937B6B026D; Sat, 16 Jun 2018 22:01:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D06BC6B026C; Sat, 16 Jun 2018 22:01:02 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 886156B000C; Sat, 16 Jun 2018 22:01:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id 08A696B026A for ; Sat, 16 Jun 2018 22:01:02 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id n19-v6so6633893pff.8 for ; Sat, 16 Jun 2018 19:01:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=r5CukERBzeIlr83uJco+d+VA4O1H8AQ0gO0fzR7QlcY=; b=uJtmE7rk2E6J7gT8l2RdbaYEj31dLbbGtrmWYxxOqqt5AFzAkLzSC9DjGD76Y2L0Dz vGTEmdsW5QlelPIYEuWkJEwwjJExohBjm2ooqyl0j5/U2jeeplP4KkLmhJEUovfHZHxm Hnmze/xNnuiZGl2NJYVjlBQyZ6ESjG/pC8YZimUJReHkyOozPo5dKvvBxCqxM6w0ZWt5 h+EiFkmFJfi9sv9nyjTx0dCnktAHpBs5aXorEmnBKtLpvImhgVNMHElZFXTsfTWwI4Ga LbFMD+aK7kBZE4hBxK17R6z6x+Uyxsb7VmxQp5S889JEgm+EMis64nl9rLWD/P46XOnT sivg== X-Gm-Message-State: APt69E1PnBk3qfyPh2S7YIhcBMg+sSI8leL654VgtVyZsqNDt1fGECRL +njywcn2hO6MgqjsqnSpcSYmny7Gx/EpvxzFvADi19RGara5f+e+FbkVjKiEL9CoxPBlMVcYX9q 1bOh3clcKl2f/KcezwwS6G7/OkPHtKUqkJB+ZFGIJa8E2P0+MOjWqdX1vwjosYN34oQ== X-Received: by 2002:a17:902:bb90:: with SMTP id m16-v6mr8396238pls.50.1529200861719; Sat, 16 Jun 2018 19:01:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKjQm7gst9l3+e3BGiAahBjKG+tEExwOsflTLB9RDxtl6MoTX/f63PYO4dnFYHo6EIDPHp8 X-Received: by 2002:a17:902:bb90:: with SMTP id m16-v6mr8396193pls.50.1529200860751; Sat, 16 Jun 2018 19:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529200860; cv=none; d=google.com; s=arc-20160816; b=Gd4s+AP6c7IiHpCrBThXoLhPwdAwl+zloPuNrAhf3rvS0FIAAudR5ILKaTluKI2bDl KxqlHSynrC0DHLqdUVcGYdlhe+q2UDJucJ4gIcSlO1ixJE4oiTml0eVb5yeoGr40ao0k 8vYDronoR9V1SVsfpHYUwZ3b4k8yZFEY7K2ii0uxLYWPcayViE9r3Ex1gdeY21UlRdws Kr1cogoZX4Gzy2px3nBDwGEnPUijVUcorO92sBRkh4MZ45TmOSofY0Eygv7DYM3uTsYZ vkCaRiYSGbBVyR3SeRWaVKbFfsJb+DMBtkykm+OHf/yFYjTMPqpdWr5YzV+WQn1ypA9c AOSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=r5CukERBzeIlr83uJco+d+VA4O1H8AQ0gO0fzR7QlcY=; b=wljQxH1OW7m8bdera+iOK9PLKwYR1owt/pneawHFnT79xksLlvdq8a6cifW0Cn7J86 KpxX3xdrK5+Cmrh8ZHq+HmMDa/hOxiQoFCWEB1Rk2muh/7ht1QF73KWpqQ3coT6DM+sh EP6lDSzDga2KkoqjpnzFRitsnk2WWqh3CJQgwyGZfDnDSRLclJyXMY+A+5Z4Pt70aJ0X 7HWcfXUpQJ6puJv+1+JyTjvVpOcPmoWwYcU0R+0Djs70y4wjEkLga2WbcgaC5XCu3VkY DuVOoc+Iid3uX5at2Ry+FqcZmsp/ACLRN2L49NWRsLGAPyAYUAL+bi0YqnBKW2gyHaX0 4rsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=g3lwimEi; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id 7-v6si11607974plc.179.2018.06.16.19.01.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Jun 2018 19:01:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=g3lwimEi; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org 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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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) {