From patchwork Mon Jun 11 14:05:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10457917 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 35ED760467 for ; Mon, 11 Jun 2018 14:08:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2483127F8C for ; Mon, 11 Jun 2018 14:08:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18D8928434; Mon, 11 Jun 2018 14:08:39 +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 742DB27F8C for ; Mon, 11 Jun 2018 14:08:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 384F06B027A; Mon, 11 Jun 2018 10:06:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2B4346B027C; Mon, 11 Jun 2018 10:06:54 -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 0E3CE6B027D; Mon, 11 Jun 2018 10:06:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id 9CEA06B027A for ; Mon, 11 Jun 2018 10:06:53 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id i1-v6so12148629pld.11 for ; Mon, 11 Jun 2018 07:06:53 -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=8pITuBd92w2lO7mrY9ySljX/Vx0Xpt19doJAFI5Uh7I=; b=Ww4nrpFYwu5ZOocIyKHDiY6+O/XdcsCHZ/bKThLnsV/0LTNDdFISoPxVzJebbtPdiK /+bpIT2hPWbUDXy/34vmPtJv9ArpM2xuQIy1IBdWMWpAvZWT9ypMcAbqf0sqnHmhe34x afKCRLNVJpyvbyaBstM637f9bZfbGg85+f0UxJ6CWdGFXTQ1PjlWf9jJ6bajBeSFCKPK acJcP/D6ZsdAUumbQTetp6MVxjz2DzdNUFRg2ojzDMCl8O4fDGvn2vjkYrFQms6HBsjM ohfhyoL145oeIHlq0i6sh6LSRbLAV+UYk06t60dZu6TsTZRcJOMUMQ2Iowna/20W4g5p ojxA== X-Gm-Message-State: APt69E2SODdc7p9HcGViAqtps8Tp42qfFBVc/+nx3voTMHshT1LFxwyD s2et+etFyil4sNq6k/LI8Qaqdjers6wtenR2WKaNDNORSQMIK9BPtH9GOnd5N/gbly8wzzmoO9b ZTOhar/wqMW/nT8tSS9wwpdScFOopvF/ZUZVwK9M3AcloW9+VnnOYDudPqMhBxSvVOA== X-Received: by 2002:a17:902:9a9:: with SMTP id 38-v6mr19034218pln.114.1528726013301; Mon, 11 Jun 2018 07:06:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ7iKSo22Oeio/Ydh1hxp2HdO9vcXh305NjIMbMOOysDf1py/y8j+TIlGJs5H4cM7fgAgjO X-Received: by 2002:a17:902:9a9:: with SMTP id 38-v6mr19034091pln.114.1528726011625; Mon, 11 Jun 2018 07:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726011; cv=none; d=google.com; s=arc-20160816; b=t+DntIs1+Z8c4B0J2dPbm862Ii1Rmh20A1vMA55ecQQbC+XzziEDLKyAzs6iLy+M6E sKLX/KIc8bhIZVSzfrJt44VQ/e7othvdikcSISkkLnpqTOV/FyBrYff2hHzp/rOA1o9w 85PAEouBlP1AC/0b5u6IMFEFnh685jYCcnkj3rpSc+iQhtwhYvkRPZdiG4+FZ2eqXc0F Bj+uRGQcZuj88WGYpL5wrTgM08fNbEgPMjFmGYawyXGHqW0L+IKw6nq+Fyx9xnGoHamK h6TKgugOhtFRHZA3vlJxCRnulqZWrih/nCqQoxzX3YRTVeHN6vngZyYIxQHj5iKaaqZO Iylw== 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=8pITuBd92w2lO7mrY9ySljX/Vx0Xpt19doJAFI5Uh7I=; b=l2vwuMw1EhawLNCAi4RTjTu8+9bPu+PB0Lhln4KEGF3t/MYB798jIxSBJxYpUSwaKV X8EjPXmwRW7fnikKFIk4gR1OaBy2KrrCORUFcOEFx2Kaeabnbzpg4NXR8LZZ6fbT/TCc pOYeFQBgIjNXjD6pRFy9VgDiRwa69k1APr5JsbyXl1VLtEO01O6tz6TB621kdnfJ1n4a K7hEFGjGB5COsBKw0guk1WfUrFl2jazZITxE9PT1+uWudE0k0kI6EbnMEsRH0L4ZPE4c 7p5cRACBGwsZRmeYdV2RBAcsSsfiw4mWEmebg0rwqJBOHKWHmep4zCtu4xmYKqNwZq4C 0RAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=r+qP97fL; 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 w190-v6si34135574pgd.5.2018.06.11.07.06.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:51 -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=r+qP97fL; 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=8pITuBd92w2lO7mrY9ySljX/Vx0Xpt19doJAFI5Uh7I=; b=r+qP97fLcA4hOGqyFa1JFrKje Rrhpcky6kdox/NIe1AAqdadXAS5WuNomlVJH2iHlhBenB0nOx0MdOy1NB3YdJY/Hig7XJZlH6Ac2l H6CbX5grqFUfVEsudvOfn/VzDyV6NWk3eh9vTYxAPvuRsvRpwjc5Y8aFiGpXHiUjwZ7stYSJZ7DHt i/j6L1GZ58FPT/59mI84N0gecY+oQpXVpLVfsJvFUBjme0CI44EfnYXRhayhulMXIJEpdLvDkw3ib i20bCJ/H4EJb0jvpvjxknbsEsS3tgZkyFvMBwVve+m+gMPoj8B7+lf3ea0UWCSe3hqFBewMuX7dMn GGCtLdCqA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNT8-0004gY-GE; Mon, 11 Jun 2018 14:06:50 +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 v13 26/72] page cache: Convert find_get_pages_contig to XArray Date: Mon, 11 Jun 2018 07:05:53 -0700 Message-Id: <20180611140639.17215-27-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180611140639.17215-1-willy@infradead.org> References: <20180611140639.17215-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 From: Matthew Wilcox 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) {