From patchwork Mon Jun 11 14:05:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10457905 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 492F860532 for ; Mon, 11 Jun 2018 14:08:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C27301FF81 for ; Mon, 11 Jun 2018 14:08:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6AB027F8C; Mon, 11 Jun 2018 14:08:25 +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 38C231FF81 for ; Mon, 11 Jun 2018 14:08:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B99FE6B0277; Mon, 11 Jun 2018 10:06:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AC98B6B0278; Mon, 11 Jun 2018 10:06:52 -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 96FEA6B0279; Mon, 11 Jun 2018 10:06:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id 47C2B6B0277 for ; Mon, 11 Jun 2018 10:06:52 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id o19-v6so6615105pgn.14 for ; Mon, 11 Jun 2018 07:06:52 -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=+c+l1NkAi3vmmhzDtUhhMVC9W/oaDCjLLlNg0JM0yu4=; b=jAsWuLx9kUfrZ6GGYNM0yIKELdrm/jCWUf+htDvwW6ulIQZnjQIB46u3nkr2kVYSh3 wmOXilGyRVIQxAYTDQkrEzzfJE8tjZjKES+e5CFi5gWUdhMdIGLjJ0HK8hCpoXN4CKiQ d4mfr4DhN1bZfuAAuxFBsBj6nd8nxzYJ2hP7HgYYHjuV5rFOfTsIX+yAqsF4hBXYpYsc wyqMixeMIxN1ZbxBGh3OjmT9K7PqAIbk+98Wmqzs/ixrN4JjDZm/BtU0IG0+cuhr2fG8 FdRWTi+uOnDpm/hChGCsiCXDhZPzx8gccX1xWhfZg+kDM+9+ljHhxjlxAZ3e4tuoOZZj TSRw== X-Gm-Message-State: APt69E2h9A/eY6UuqxdmwBpBJeMMc9KPAAUWC/djUabsSuVgJwO93URP 7UHMGluBFkbdBULAmKawj+KZ//Yo+CvX7n/vPeVuVvKatuizIsNxRy45RNMGljdldi0nWvszl16 Xpo3a9C37zEOEeSZz9syjdd3CK1E5hZo+Ynayav7DFQZdpI5wsIrR+1RxDlYp1UfN9w== X-Received: by 2002:a17:902:bb8a:: with SMTP id m10-v6mr18791256pls.236.1528726011993; Mon, 11 Jun 2018 07:06:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK8totmlYTPeKYvQClx4xumq6pGV+T1S+x4wa4IQ5ERcn3ZwU3/2MPRBnwdsBBTabJeSZzK X-Received: by 2002:a17:902:bb8a:: with SMTP id m10-v6mr18791188pls.236.1528726010843; Mon, 11 Jun 2018 07:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726010; cv=none; d=google.com; s=arc-20160816; b=Qyp+sxlNDDKE5lOOhj+B9scbdfgkTkKGdYO5fPJ4Do4rvGo8zGlMBQdV3JD45s7aXl hFtZeJ38dNrFeZueFUmVue/ZYSdWDD9NsyHkrZ+dGVRMhkYCygwloAYNojWCMBgfnKcX BHpn0nk43fO7kSn4mJgy4gUqKpWbn6BWlszqrK3c9ZLVnvs9MM1ojvptIOyexuPzIcAa TC341fJDHfrB7oA2K23zjLLC4p8h/nevzstwkF8zeSgM7oijtkDsBZMkUHXFK8Pzg5yn nT8TDf94RtizRsSNwsxfensKo6dgL5Y9sqFG/hhyW2hzCk/iolWAdF6Dh8M+XHB1d471 4EEg== 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=+c+l1NkAi3vmmhzDtUhhMVC9W/oaDCjLLlNg0JM0yu4=; b=etNWIZke9NcyRwUDXmfvpndh8wU7j1d5/Bt4UQvUyAYOksmK0YJDfkBrWy3r45JD4r JbxcVnXPkmjxhka3voSRIkzHolxHYYIrvr2SAxHxMFaWSM5Uysgm1cEFt5ajRnmEcs8S 5RksVhT9L+M7cgAsRFlAfC5eI5q23gLz3sl9dh9oGc5SxIOLWSS7DOe7wN/VPtYBG5wK bTNj7aa2Kc5dcwdILYlA8QmMnSqcDSUkdiUPNx7hM1+srA9/DhZCjFPBYC+UI/eSTOSS AFWcg3He40tE/Y7vqrv5pxYPWi5ECWffUnDoF8MSs5kqPYfl1oWbO4JOUobWaKkR5uNS W20Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=iEUzAMRf; 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 l138-v6si22760453pfd.355.2018.06.11.07.06.50 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:50 -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=iEUzAMRf; 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=+c+l1NkAi3vmmhzDtUhhMVC9W/oaDCjLLlNg0JM0yu4=; b=iEUzAMRfHgRfvebMaKJqDTGkZ AaNbUk3keL7ve5wapSApkl5+mV3v6qoydpMdkJaTheMjI6vELUAdZU7QV/Gsku9Qj5HJqsJuUGUju hEOklifUvPIFNxfAV/+BLxaH43R3gguKxR9TGAFhAR3ApsMtoy2g/OJAY81zBLZ7D//mUKx+TJ1nH XIOr0bJJG3hKcwutCd9wuDfNpSxB7JPfVuK3fr10xw2Vqzqek7elH9kPmdy1syE0EN9dpT5i0UWZp B1EutnH3BwxjpC7Eonj/XQwGsrIyMe+ma6OfxKOHwuY5UHwjd/+0MQAltp2LJz13nU0lI5DfIer38 dSj+2S0jg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNT7-0004gI-Ul; Mon, 11 Jun 2018 14:06:49 +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 25/72] page cache: Convert find_get_pages_range to XArray Date: Mon, 11 Jun 2018 07:05:52 -0700 Message-Id: <20180611140639.17215-26-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 --- mm/filemap.c | 52 +++++++++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index b49290131e85..019c263bb6be 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1650,64 +1650,50 @@ unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start, pgoff_t end, unsigned int nr_pages, struct page **pages) { - struct radix_tree_iter iter; - void **slot; + XA_STATE(xas, &mapping->i_pages, *start); + struct page *page; unsigned ret = 0; if (unlikely(!nr_pages)) return 0; rcu_read_lock(); - radix_tree_for_each_slot(slot, &mapping->i_pages, &iter, *start) { - struct page *head, *page; - - if (iter.index > end) - break; -repeat: - page = radix_tree_deref_slot(slot); - if (unlikely(!page)) + xas_for_each(&xas, page, end) { + 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, - * or a swap entry from shmem/tmpfs. Skip - * over it. - */ + /* Skip over shadow, swap and DAX entries */ + 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) { - *start = pages[ret - 1]->index + 1; + *start = page->index + 1; goto out; } + continue; +put_page: + put_page(head); +retry: + xas_reset(&xas); } /* * We come here when there is no page beyond @end. We take care to not * overflow the index @start as it confuses some of the callers. This - * breaks the iteration when there is page at index -1 but that is + * breaks the iteration when there is a page at index -1 but that is * already broken anyway. */ if (end == (pgoff_t)-1)