From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: [PATCH v13 64/72] dax: Convert dax_layout_busy_page to XArray Date: Mon, 11 Jun 2018 07:06:31 -0700 Message-ID: <20180611140639.17215-65-willy@infradead.org> References: <20180611140639.17215-1-willy@infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; 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=YZEZhtidxbERQmqpIgTJPIyTZV3rzcBKGQfijbq6eAo=; b=an5cHkDUjxx+HcyIAdSvWpAkxG b3jgDNYd6LXObWHh4oszGBEoSSHp5YlpISbWdHucOhIlihvqvJ7DjJMBADWkC9nz9YbGsj/8iWkAG CVu6d9AMda/woNxSD6NO3Y866Qr2Ed2XA9zS1feyX4bZs4gepgqk+fFwzAUFLqwGBAqs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; 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=YZEZhtidxbERQmqpIgTJPIyTZV3rzcBKGQfijbq6eAo=; b=I+siEonhObrL6mjG5H+BTLH2Ry KX9JT14jxSXmPaTjAPc/eeCzY0j4T5akLRs0fVZDInUgoZY3HLPTEQiMEIhf1o+K3gS9Um8Qa5Cft hCeBkE8XCf8MQmVAwRcUtB4V4aXOMQ3BFc1DwdfBytOGiK6w/eorT79M0bzKeXTqZJU4=; 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=YZEZhtidxbERQmqpIgTJPIyTZV3rzcBKGQfijbq6eAo=; b=LJNjD8aUGTWjXHythh3JGMmev DadDkFu9xiNsI+UxD/Dsb82sgXExm0x9/32u8bsG8kwv4EwcoWDD842fiRDgilchWtqkHQU/8vjSr 3OmSUKv0EUDPaWYsOTbizx8iQyTE02XtMS3ZlzT8KhtjEbjeMyhwANJd8YXmv1GfldWlRqBWMuABn y2BKT6VL3/YvsLoYABSGRcSlYKCPzgnsZxe9m2SXmgO2kBq9KtmegYM0Ajg49E4j3SH3Zrmu/4Zvs eWUms6flEVIJlQbeZZ5VzfYmet+roI8W6iiFGi4kD4NT4peqWhHo5mLGg6mqL2SXafXxpQLkB2jYc UAFgq/gfg==; In-Reply-To: <20180611140639.17215-1-willy@infradead.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-nilfs@vger.kernel.org, Jan Kara , Jeff Layton , Matthew Wilcox , Jaegeuk Kim , Nicholas Piggin , linux-f2fs-devel@lists.sourceforge.net, Ryusuke Konishi , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues From: Matthew Wilcox Instead of using a pagevec, just use the XArray iterators. Add a conditional rescheduling point which probably should have been there in the original. Signed-off-by: Matthew Wilcox --- fs/dax.c | 57 +++++++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 1c9b736147d3..b8ed7bf32ba1 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -621,11 +621,10 @@ static void *grab_mapping_entry(struct address_space *mapping, pgoff_t index, */ struct page *dax_layout_busy_page(struct address_space *mapping) { - pgoff_t indices[PAGEVEC_SIZE]; + XA_STATE(xas, &mapping->i_pages, 0); + void *entry; + unsigned int scanned = 0; struct page *page = NULL; - struct pagevec pvec; - pgoff_t index, end; - unsigned i; /* * In the 'limited' case get_user_pages() for dax is disabled. @@ -636,13 +635,9 @@ struct page *dax_layout_busy_page(struct address_space *mapping) if (!dax_mapping(mapping) || !mapping_mapped(mapping)) return NULL; - pagevec_init(&pvec); - index = 0; - end = -1; - /* * If we race get_user_pages_fast() here either we'll see the - * elevated page count in the pagevec_lookup and wait, or + * elevated page count in the iteration and wait, or * get_user_pages_fast() will see that the page it took a reference * against is no longer mapped in the page tables and bail to the * get_user_pages() slow path. The slow path is protected by @@ -654,36 +649,26 @@ struct page *dax_layout_busy_page(struct address_space *mapping) */ unmap_mapping_range(mapping, 0, 0, 1); - while (index < end && pagevec_lookup_entries(&pvec, mapping, index, - min(end - index, (pgoff_t)PAGEVEC_SIZE), - indices)) { - for (i = 0; i < pagevec_count(&pvec); i++) { - struct page *pvec_ent = pvec.pages[i]; - void *entry; - - index = indices[i]; - if (index >= end) - break; - - if (!xa_is_value(pvec_ent)) - continue; - - xa_lock_irq(&mapping->i_pages); - entry = get_unlocked_mapping_entry(mapping, index, NULL); - if (entry) - page = dax_busy_page(entry); - put_unlocked_mapping_entry(mapping, index, entry); - xa_unlock_irq(&mapping->i_pages); - if (page) - break; - } - pagevec_remove_exceptionals(&pvec); - pagevec_release(&pvec); - index++; - + xas_lock_irq(&xas); + xas_for_each(&xas, entry, ULONG_MAX) { + if (!xa_is_value(entry)) + continue; + if (unlikely(dax_is_locked(entry))) + entry = get_unlocked_entry(&xas); + if (entry) + page = dax_busy_page(entry); + put_unlocked_entry(&xas, entry); if (page) break; + if (++scanned % XA_CHECK_SCHED) + continue; + + xas_pause(&xas); + xas_unlock_irq(&xas); + cond_resched(); + xas_lock_irq(&xas); } + xas_unlock_irq(&xas); return page; } EXPORT_SYMBOL_GPL(dax_layout_busy_page); -- 2.17.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot