From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: [PATCH v10 36/62] shmem: Convert replace to XArray Date: Thu, 29 Mar 2018 20:42:19 -0700 Message-ID: <20180330034245.10462-37-willy@infradead.org> References: <20180330034245.10462-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=ouiCa5xT8srSD9TFGwNrZtquNaTrnMBUsKY3Aj4xtrM=; b=L0nS8ocrY7ZUEE7RMkstzrvYzT 77Yw8/rArZv7OUR7heHf4Li7PTAbjwOuWM8dpno6aOAWkzq12CtQqETYfph0uTZKdRvxI8fOXhwUu DKqAbqItXShezWRpyHR+Jo59oBJ/QQl9ME9V/WIHZSwEfegVXTAZFK7FDbcFnmV8gKFI=; 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=ouiCa5xT8srSD9TFGwNrZtquNaTrnMBUsKY3Aj4xtrM=; b=UkMCt6Ih9cKVnM/DJYnw0D8M1t YzhbPe0qPK8lgdap0r6TMbGr7bvvdYlhRpGwjs6DLdUDCyOQnj51omVeCDSWDPfNtujze5ODz2ESL wT2sUd5Z3sMSbZfrQ00t7e9OLifDxI07jnoey9Oy5UxTTUgD5UGsF50tmc7VVk93I3+4=; 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=ouiCa5xT8srSD9TFGwNrZtquNaTrnMBUsKY3Aj4xtrM=; b=n784hWh1ZNr6yrZFA09oJE8bG ss8jle4nwa+9viFWy/xKd28UMaK3QtGzc1ewjH4SOPr4gmO3IHEl1ekYZ8K4SHh++0hGAmqHS/816 qZak7cp+jzPUiyyxcsfNZsnwsqfhGsGgthWWCT5y5T6/XyPiBfESgbrOhxwzQjqKmebfwoD5H0bbi 4asnDqi78cL3wWH0/oyXvHhE4lIKCZzqk7++nSS9uhPsjyklaBgDOHhK8AlG/ezmB+Ju6pPkrTlIm FFYP08uKAD/MzlGndvYJ3b6nmhTosSSlHPFM8RcHzBTdKNn/4mDmvG6Ub2JFo7JbPIbFhsp1d5KYn EtZbDq35g==; In-Reply-To: <20180330034245.10462-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 Cc: linux-nilfs@vger.kernel.org, Jan Kara , Jeff Layton , Matthew Wilcox , James Simmons , Jaegeuk Kim , Andreas Dilger , Nicholas Piggin , linux-f2fs-devel@lists.sourceforge.net, Oleg Drokin , Ryusuke Konishi , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Mike Kravetz From: Matthew Wilcox shmem_radix_tree_replace() is renamed to shmem_xa_replace() and converted to use the XArray API. Signed-off-by: Matthew Wilcox --- mm/shmem.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 5cb52a797ea0..fced882e0b7a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -321,24 +321,20 @@ void shmem_uncharge(struct inode *inode, long pages) } /* - * Replace item expected in radix tree by a new item, while holding tree lock. + * Replace item expected in xarray by a new item, while holding xa_lock. */ -static int shmem_radix_tree_replace(struct address_space *mapping, +static int shmem_xa_replace(struct address_space *mapping, pgoff_t index, void *expected, void *replacement) { - struct radix_tree_node *node; - void **pslot; + XA_STATE(xas, &mapping->i_pages, index); void *item; VM_BUG_ON(!expected); VM_BUG_ON(!replacement); - item = __radix_tree_lookup(&mapping->i_pages, index, &node, &pslot); - if (!item) - return -ENOENT; + item = xas_load(&xas); if (item != expected) return -ENOENT; - __radix_tree_replace(&mapping->i_pages, node, pslot, - replacement, NULL); + xas_store(&xas, replacement); return 0; } @@ -614,8 +610,7 @@ static int shmem_add_to_page_cache(struct page *page, } else if (!expected) { error = radix_tree_insert(&mapping->i_pages, index, page); } else { - error = shmem_radix_tree_replace(mapping, index, expected, - page); + error = shmem_xa_replace(mapping, index, expected, page); } if (!error) { @@ -644,7 +639,7 @@ static void shmem_delete_from_page_cache(struct page *page, void *radswap) VM_BUG_ON_PAGE(PageCompound(page), page); xa_lock_irq(&mapping->i_pages); - error = shmem_radix_tree_replace(mapping, page->index, page, radswap); + error = shmem_xa_replace(mapping, page->index, page, radswap); page->mapping = NULL; mapping->nrpages--; __dec_node_page_state(page, NR_FILE_PAGES); @@ -1562,8 +1557,7 @@ static int shmem_replace_page(struct page **pagep, gfp_t gfp, * a nice clean interface for us to replace oldpage by newpage there. */ xa_lock_irq(&swap_mapping->i_pages); - error = shmem_radix_tree_replace(swap_mapping, swap_index, oldpage, - newpage); + error = shmem_xa_replace(swap_mapping, swap_index, oldpage, newpage); if (!error) { __inc_node_page_state(newpage, NR_FILE_PAGES); __dec_node_page_state(oldpage, NR_FILE_PAGES); -- 2.16.2 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot