From patchwork Mon Jun 11 14:05:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10457915 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 AF4B36020F for ; Mon, 11 Jun 2018 14:08:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D1BF1FF81 for ; Mon, 11 Jun 2018 14:08:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91B2C277D9; Mon, 11 Jun 2018 14:08:34 +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 0B1C71FF81 for ; Mon, 11 Jun 2018 14:08:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF3146B0279; Mon, 11 Jun 2018 10:06:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C7A856B027C; Mon, 11 Jun 2018 10:06:53 -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 AF1FC6B027D; Mon, 11 Jun 2018 10:06:53 -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 660C36B0279 for ; Mon, 11 Jun 2018 10:06:53 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id y26-v6so10337496pfn.14 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=mKlDprFcod+mEKzLVONxtmRV1mIt0qW8UDzOtSiZ0e8=; b=DX+G8gOul6NEfpDI2xuT4AaWwlRzUq7lHO1gFxINyhz3G7lHRRDai+3WMeRGUPtsDd VxEwl00/1oEX82GJStKTEhVuf9zCLdCzsWu9OuiI7cPak1zl7mOpDOvLHj9Emq2jKv2N 5I2my8jwz5XJQzSAAwCm3/+jo1GfWBGAE/OhVXwdo8dyc5tMGKTopHTAa3+gI5mQ0XgH xETsdwJUK6u0K/Ooea/IguJEKGm+PhpysmDLfFkSqBOH3daaGflRAwbHoAp/gPN19ML3 VyR2L4nfajcU2umGayjXTAtHMeK+w+EPJI4lB6b/yUlvmV8zPzpnS0mLFuL1Hgq9B6Z6 LyLw== X-Gm-Message-State: APt69E2XW9Ng0gCTO/VjLGy87R2nld+v9ivswWjCasMifM1Ya/KdbXwv EAlbyRlH98Y7GXUf1xyDIJJv6jFIi3wE4K1DLO4BYQbncGnglF5FUx9vzLtojDbJY862kEedaE7 ZeVr9iDul/UgBlRr+wp0ckS/MYbiq3zz6Wikhwnx088KLTTTQFkN+pSkw33rehlXD8g== X-Received: by 2002:a65:608c:: with SMTP id t12-v6mr6789268pgu.159.1528726013071; Mon, 11 Jun 2018 07:06:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ9TjOmSqvMdZUSjtC1w7E0CCcBinLITYCFY9IfLsZ8kUolEYrlKXNWCtBS46z+Hp8wDyie X-Received: by 2002:a65:608c:: with SMTP id t12-v6mr6789211pgu.159.1528726012138; Mon, 11 Jun 2018 07:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726012; cv=none; d=google.com; s=arc-20160816; b=FZ5uD/07a8p9QSF4q1Q8KqnVCLD8LOIDPg+b7FJOliCPgt9WM/iQ4sJLPJOkfO1U63 wRj3zJQonqi7shePEpYZwwau1w9qPtem+ikFfgPxi1G5Uz/xYCI/a7PzW874hb1MvHBL Ja4nuiIzgbfPYbSaQZYSJK+8IKY1pdt5Zng5clr9obnq9MvU16Ehwf1EhT7QXV1MKSEE B6JZWsRvGPy1HnJqj0/yGSfmrNNigEET4xXwT/2qVWwWecGL7r9XJ2V54mKuIROB2Uwr GbqituQ/J9tRboHxtPqD+jQ/mCYZ55QHtcs+NbDA1xWALY5yIID6PhlIBw+o/yQ/pUmU Ovwg== 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=mKlDprFcod+mEKzLVONxtmRV1mIt0qW8UDzOtSiZ0e8=; b=vfo31DjlYJ+8KZvZYXxREwZ08DW4mWz3MXg4GipY56fQTRWi40BU5v4MOMIz1ab1Yc BZhuByjQ0goAsCp11skJOYjaqztYdOvomwzpffj2FsGg9iiWmzr1CGyj9dL994/pnT1j /Ktb/BIVsWj76dgVXflUzoi21fPHU7AKRd2lOgX3DxwtAH3rj7BLlxysiUUb4MXmsLAp wtQZudGS98pUtSuoaUmjJj28cnfvI05Y/0sAi008NDPSca4HhdCyH/pp2GuV9c+ALFQk sHf7Kkh1Sib0mQn8I+rOVZMMt39LzUhJHPYZITaTaiLpLRtxfMv2VMI6t83sZMH0tFWc WNPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=stPY4WFi; 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 bf10-v6si23448517plb.423.2018.06.11.07.06.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:52 -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=stPY4WFi; 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=mKlDprFcod+mEKzLVONxtmRV1mIt0qW8UDzOtSiZ0e8=; b=stPY4WFippmnburrIWxLJ29Cf T2j8yEfcZ4UtMsVYKR9T6k/3vRlhc/b4GL6+L+1m+GFDzFXohAtcXrSxGXzK7QkMhOZU4SbvmkYFP Evb0oA5e5X4Wa46zPBcnctROlg25E1X5PNFnEBh+VXe/5/H2mGoM/awtxL68wymOVGUEsiPG3WRcR UIi5HcDl5EZd3J4zwr7Tel4FuKgOwGPMSm/sTe6huQRuMylaVLhznJGDenSa8STGQPbqankuM4Wbd J3eQ1qAY1hGg2VJ50SNBgHHepLnlxiAOvEB0RueMu8DrN0emEJz7li1KyX6hLxkGm/6Xa/WpAdOxg 17uL4hxfQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNT9-0004gr-1N; Mon, 11 Jun 2018 14:06:51 +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 27/72] page cache; Convert find_get_pages_range_tag to XArray Date: Mon, 11 Jun 2018 07:05:54 -0700 Message-Id: <20180611140639.17215-28-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 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;