From patchwork Mon Jun 11 14:06:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10457969 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 2A5C1601A0 for ; Mon, 11 Jun 2018 14:10:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16D672835B for ; Mon, 11 Jun 2018 14:10:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B40A28451; Mon, 11 Jun 2018 14:10:00 +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 7F88B2835B for ; Mon, 11 Jun 2018 14:09:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A55D26B028D; Mon, 11 Jun 2018 10:07:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9E4936B028F; Mon, 11 Jun 2018 10:07:04 -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 7E9B76B0291; Mon, 11 Jun 2018 10:07:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 311346B028D for ; Mon, 11 Jun 2018 10:07:04 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id y7-v6so12148786plt.17 for ; Mon, 11 Jun 2018 07:07:04 -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=p6NnmI89u0sq1FU15L+NpkGefGHhKJMhHQetKgwT18I=; b=rHKtXqd5fN4+NyG9g0GAuSynqj4M8bZ3tQ3FKXnaPnwI3Kjr9EhpFx51CjtRaFXXjj y+d28FyrtA+//e6OAp5lUiUXg0O9so/nm0N94XESlXlDri9CtY9u2Kf2D7acd9bdASDM Opby7VxgPrYe3lkZaS93mw/ucSonzVTb66etRMWpK7PvQTMgKZx30dZ13EhcFGHghD1s GeY3Am7lrRma8/7Ip+RdM0tuwFbSCJ6OHcJpqHw5+rhzQgpldQbWFCrMc5qEaKipNk5O Xpuc6O76GzbvFkr+IpZva138Vjabp5MVRN4qAKl6BWLXj/sjLlld7bH736x/OeR0LqNy dXiQ== X-Gm-Message-State: APt69E0iDMTzARflz28dRte2QnF3sCUyGYz/NF2u/oiHgHxVCayKrOa8 8QT4EJKb7+XeM16hZ2kpyhZZ9rFQ7l0p0Nl1TFnUFICtvfH8/WuJl39oKaUf5Mz7YA+lZecAJWU a6cQatXKF5PaoF+K2i4oSXsLhKIHMAMerRuaKh4THULlFSCcW0WED34mC/MnfVAB6Iw== X-Received: by 2002:a65:51cb:: with SMTP id i11-v6mr15178312pgq.320.1528726023878; Mon, 11 Jun 2018 07:07:03 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLI570DmjSxC2PAUgv551z+03oxhRNnkLRuTyeNaKjWXfk69+WBadGDfPdBrgFOfiLmMsTg X-Received: by 2002:a65:51cb:: with SMTP id i11-v6mr15178257pgq.320.1528726022905; Mon, 11 Jun 2018 07:07:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726022; cv=none; d=google.com; s=arc-20160816; b=O4LdjLeafIVn12Ej3tP/clzXCcQodeveqmJAxH7hZMY8u6XTXgF3UI0O6HjGwVta9R Wmh6kh/0fbI0jA2BdhFeuYrvH7M4SZCuCKcKW1/+Rl/PT8FAnOAcPiNZXOusiR5kYdvt MwMiQJJqAXc2WmdJxbwSFKEQ3ZPp/9DwWe6GcaAPIgUWKsV7rAXwJSl3n8IUolggdwqq /yN2u/vH7CKmTcIck4n4OH1yB0OY4Mbld5iSjUnrVoo+vXlJ41zuKp4mIudghkYO0Rag 13CJvKkaN0+piilSUM/tFIsy+ASM4D32KWoUV+reylORMfq6kfoJOtN5rqeMHB6qiuPc PR2g== 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=p6NnmI89u0sq1FU15L+NpkGefGHhKJMhHQetKgwT18I=; b=ZBxmAqbVNIN5g+BmNFlv58kuGLa3aAKiIn7N+VeNnjubQcQk8PN8pnT0/V9KUt9QRF 8xurBlLvWxgKqjRNCVJagyhM/EehcSFo/TOuI4cKddfP2OHjhthLuArV8EHSOdfeGwM6 Crf5n/5DFEFwFTVIiuqWiK7xO3DZpz+PZfRW4+H3hYuo7pX91TrWdHGSnYGQ9cEylP9S U5v2F5Aq1bntKDz+uDfgIQ87jabG3QrPOEW/Q+Q2Fk2HKDjHXydT8ZsciP3jEy6t+8ul iHOvCHNGiuew1ZmfNDCLj8U2Kpmvecp+PQo99yHCr3GKkN9dCzMusNOPelq2lgrzxi7v 56RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=K9IZIMan; 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 h8-v6si23576921pls.69.2018.06.11.07.07.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:07:02 -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=K9IZIMan; 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=p6NnmI89u0sq1FU15L+NpkGefGHhKJMhHQetKgwT18I=; b=K9IZIManm8qnl8VgceF/LH0sE /TEB0rGfI7w/GjS50xYkL8QnUx/M1GRU+kQhbvu8pFpQm9Rvf2P/bl5U4stjs0x9T0PV3qPqcEt1U yPEqiURARaAtIWWiGU1uICNlSofinMRaghWmX5dUXrOl+iaivI83KdlY91+vF9IHaF9D8JuH3o8vE IwL8gKdyjIBfDdNaT5Z3nuBWbm3WIl8kAb0s/qTvhG+oL9rIr8Npn6v4QHUtlmDFIn/av8UlMx8z/ 0pbQuqo2lLrba0JnCGBz0D/ULrmR74/IvSfhkXhtulXLLeJZzGNXGTdfzW0gG3RfkpH3cMm3fHQ2X noVVn9ktQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNTJ-0004qG-Jl; Mon, 11 Jun 2018 14:07:01 +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 46/72] shmem: Convert shmem_radix_tree_replace to XArray Date: Mon, 11 Jun 2018 07:06:13 -0700 Message-Id: <20180611140639.17215-47-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 Rename shmem_radix_tree_replace() to shmem_replace_entry() and convert it 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 3b03ede3515c..2b8720d32e7a 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_replace_entry(struct address_space *mapping, pgoff_t index, void *expected, void *replacement) { - struct radix_tree_node *node; - void __rcu **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; } @@ -623,8 +619,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_replace_entry(mapping, index, expected, page); } if (!error) { @@ -653,7 +648,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_replace_entry(mapping, page->index, page, radswap); page->mapping = NULL; mapping->nrpages--; __dec_node_page_state(page, NR_FILE_PAGES); @@ -1577,8 +1572,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_replace_entry(swap_mapping, swap_index, oldpage, newpage); if (!error) { __inc_node_page_state(newpage, NR_FILE_PAGES); __dec_node_page_state(oldpage, NR_FILE_PAGES);