From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: [PATCH v11 35/63] shmem: Convert replace to XArray Date: Sat, 14 Apr 2018 07:12:48 -0700 Message-ID: <20180414141316.7167-36-willy@infradead.org> References: <20180414141316.7167-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=0sd4QYghhsDVhtJ0qA3qQbuVk6MN+C5dkkPqVZwb9CI=; b=NeNebDtqJUVUQHXSX056q65clh 8S00oKp5Y97G5wlbcKmPUcQn3bhduSJuzEvdkhvceHv1tWlCyVMlytvNEpWCo0i/uhyv8Bmtz2WZF kwSuOr7+OR7LECDlzSKjA+U1B5rz8S4m7snM/kuCuGejq5j5NorY54eOsFXxKzFJCQhM=; 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=0sd4QYghhsDVhtJ0qA3qQbuVk6MN+C5dkkPqVZwb9CI=; b=dRKwjV8vm8kZr2HjNINsE3fH5O FGB9FNm7iSIO2Gh9AeOZY1INsBmHFUd/bjsHXQb5+vkhP/eB6poTh4Yw6dRhvve18b62NxGIBTjdG q+r5qJPWhG9fXVwp5JzSM2Hs/HP/w0SgBX6GKYwOU3SCrJIoVfqwoyJqLPwLZMI/70iU=; 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=0sd4QYghhsDVhtJ0qA3qQbuVk6MN+C5dkkPqVZwb9CI=; b=S4QlnkFqFRKBR6umSSYCXE0V+ QMbPYXA/R1qFzQaeCB7t9ChFgipENhG85ceYc6PTyBPdJ3yTmqPSdNJDhgKz/epoZW2p87AQDxHxn ge1x7ECI6zTVHvvFB+GZoj/FHuOznKf2p4cbtvTK6Kcme9nunIJpI8FwhGBmC0zOCckjGeDU0Ro2o B13jJu9noDJyK4UH+k36Wvj7d5T7Y0XvHLSJrTYsBpe8XRBAorTPJG7cUrrl3LJKxr+oSjKzIwYIm ITiIosTN8IzhCRSc8V0Dw+ziHwBdScts3OjvNt/YarwiPr4N05hzXZU2FQJINeTFVI7B6/CHNZw/n m9+TSxL2g==; In-Reply-To: <20180414141316.7167-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 e47aaaed0322..b538cd71f772 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.17.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot