From patchwork Sun Jun 17 02:00:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10468199 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 17352600CC for ; Sun, 17 Jun 2018 02:01:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 067BF28BC1 for ; Sun, 17 Jun 2018 02:01:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE7CF28BE0; Sun, 17 Jun 2018 02:01:31 +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 65EED28BC1 for ; Sun, 17 Jun 2018 02:01:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A82A6B026A; Sat, 16 Jun 2018 22:01:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2E4F26B026E; Sat, 16 Jun 2018 22:01:03 -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 D8ED16B026A; 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-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 7902F6B026B for ; Sat, 16 Jun 2018 22:01:02 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id x17-v6so6626704pfm.18 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=gqfXkur72PH7I4OwP3gFuN/VelhPslyzABAv8sFERLY=; b=Gt5aMM4u56x5wnoOEP5ESRq92ux9RH9t5W/LEh4rdS9bbrupXCe6jTgAkRw845YlKu jyDNfqvME0eGdX0soHy2kaMHfo9YZzV194b1nVP+v6IKcCeFHrgp2d/QpSQ4b1g4L9Dl AhfNf4ieJRm6Jx+pw/s0ywc9xLqJYkwCatyWccfo8xxrCo8NKEOa5Ba30qUQk/+gjrvw kEani4S0RE6s2MdBIYdJQzEov25SXgIVYPkH3EW++5w2QDkEmLMpgvG0O0zrsLBfUKfv 8Kkr3cfjBLHhpA7i6tMSGLUpaBJYgGNVKPQOIiqLrNsYamtTqch2+H23D/F605T7jem3 NbvA== X-Gm-Message-State: APt69E3SNvRy97fZvr53LybS4RzAjUV45CseIM9JK26BXiqJc7jbENqI L9GCR+8drjQgnZeuBACdZ3CismI+3irLwXN11ddR0e+s1arsxuPX8lQ6BbHn0lJsmdG7gYp7USR 8rhDPGbCL0aA1xdO+fYlTYMLHTGWdwHP9MbxOPywCzkgZro7W6q9i3vl5KXzferyXog== X-Received: by 2002:a62:e816:: with SMTP id c22-v6mr8021849pfi.124.1529200862159; Sat, 16 Jun 2018 19:01:02 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIkSPCALYQTBWvLftWHYfgUS7GTXIQeiV+Q4YtNDiDW2QXCJLq+GEaBivntvvQXZ3X+v16j X-Received: by 2002:a62:e816:: with SMTP id c22-v6mr8021803pfi.124.1529200861012; Sat, 16 Jun 2018 19:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529200860; cv=none; d=google.com; s=arc-20160816; b=DORqvwGe/fQMwOvQiVlPpUq8Bk6NMNsuDrGL6QA5MkKporzEDjEcHXxsx1tI8wHgzJ fw2Pc9AYcUL0MMwt+pMRYmRofBswTAZGnBgnEGj5tIGonTa7emR0xmRGV/VS5FEKgNko cFCnN76QFW9hRPrKNqcSR64zkkeWB0kxqYp8X8yWX4vdsq2BKMjRYNgJbV53p1pMPpA+ koB1vP9zSpvcLCyFhKysDI5aAtE87NQyKsalVfNZW0r3ACLv/ZogwL5M9zSyplC0A11T Em7D6F+jUKz+4T25LwfljTzTiyf3GfGBixoKGuDlWoFK/TyiG2KdnB81Fji4gfdSqpAh Mfow== 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=gqfXkur72PH7I4OwP3gFuN/VelhPslyzABAv8sFERLY=; b=JeOrl6Zv7tPF/I1Km/9qh6hhz4I5aeoeQ7K0Dgrh5tQoA7TTOaIS+GPWvsIa/ZYmzB DqXLvtvZmhjaxZbnm2bAMeTf4kYza3Yl1cIyiAhQP4xb+Fs7EvQFXVkUengtSB9PseQK 3pbpkHX2eyP+0BZuhs9+YIeRu+X8sWe2GKm/v2AesBjOhOpftaXXCs4Z3MeuQL3f2OP5 iV0Qp8r5Q8XOGLirz2Akj5tqCkNe1lE2UL7LANmZI17q1mKuEcJL2IWs8MdetWYYiVOx jN7Bmxm/9n81ocWHRkHiJYVzUZf7/rUQBGGFU9Nb0g5XQTINjx6rKjCm7yoVyoesGE8O effQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b="N4eJ/m/1"; 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 g6-v6si9388244pgq.662.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="N4eJ/m/1"; 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=gqfXkur72PH7I4OwP3gFuN/VelhPslyzABAv8sFERLY=; b=N4eJ/m/1odYXrpVpDWKP9mHAx V5k/MIG6m++e1+yf1i6Wap4ai0h2aTAwzT3yVGr0l8qjjX7vMRxpckgJyFt56oUPpIplHvUbXBytX czN/ZY6jfxsiFSX5Ce9NqAsCPRIbCyFkEopfs8NpvR8SRQzLw25ah5+hxCFoSsbhXGSrRVp9DBJnk yxKpxmkR27U7UT+U2c4u7kq9kefaoDxKR2wjq0KefjLrFI1igcvolGB1uzXDGz5qEESGb/IqpxtnD SXlyIbm9TCtKyvEscsj9W/z+NodFSszg13XEHJl9adI2VrmYV+PZ2VI1EKnk4QQGSc5R6Q8Dnr+Ki TA42+or4g==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUN00-0001Ih-Bs; 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 28/74] page cache; Convert find_get_pages_range_tag to XArray Date: Sat, 16 Jun 2018 19:00:06 -0700 Message-Id: <20180617020052.4759-29-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 The 'end' parameter of the xas_for_each iterator avoids a useless iteration at the end of the range. Signed-off-by: Matthew Wilcox --- include/linux/pagemap.h | 4 +-- mm/filemap.c | 68 ++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 44 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2f5d2d3ebaac..a6d635fefb01 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -363,10 +363,10 @@ static inline unsigned find_get_pages(struct address_space *mapping, unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start, unsigned int nr_pages, struct page **pages); unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index, - pgoff_t end, int tag, unsigned int nr_pages, + pgoff_t end, xa_tag_t tag, unsigned int nr_pages, struct page **pages); static inline unsigned find_get_pages_tag(struct address_space *mapping, - pgoff_t *index, int tag, unsigned int nr_pages, + pgoff_t *index, xa_tag_t tag, unsigned int nr_pages, struct page **pages) { return find_get_pages_range_tag(mapping, index, (pgoff_t)-1, tag, diff --git a/mm/filemap.c b/mm/filemap.c index 8a69613fcdf3..83328635edaa 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1789,74 +1789,58 @@ EXPORT_SYMBOL(find_get_pages_contig); * @tag. We update @index to index the next page for the traversal. */ unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index, - pgoff_t end, int tag, unsigned int nr_pages, + pgoff_t end, xa_tag_t tag, 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 ret = 0; if (unlikely(!nr_pages)) return 0; rcu_read_lock(); - radix_tree_for_each_tagged(slot, &mapping->i_pages, &iter, *index, tag) { - struct page *head, *page; - - if (iter.index > end) - break; -repeat: - page = radix_tree_deref_slot(slot); - if (unlikely(!page)) + xas_for_each_tagged(&xas, page, end, tag) { + struct page *head; + if (xas_retry(&xas, page)) continue; - - 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. - * - * Those entries should never be tagged, but - * this tree walk is lockless and the tags are - * looked up in bulk, one radix tree node at a - * time, so there is a sizable window for page - * reclaim to evict a page we saw tagged. - * - * Skip over it. - */ + /* + * Shadow entries should never be tagged, but this iteration + * is lockless so there is a window for page reclaim to evict + * a page we saw tagged. Skip over it. + */ + if (xa_is_value(page)) continue; - } 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; pages[ret] = page; if (++ret == nr_pages) { - *index = pages[ret - 1]->index + 1; + *index = page->index + 1; goto out; } + continue; +put_page: + put_page(head); +retry: + xas_reset(&xas); } /* - * We come here when we got at @end. We take care to not overflow the + * We come here when we got to @end. We take care to not overflow the * index @index as it confuses some of the callers. This breaks the - * iteration when there is page at index -1 but that is already broken - * anyway. + * iteration when there is a page at index -1 but that is already + * broken anyway. */ if (end == (pgoff_t)-1) *index = (pgoff_t)-1;