Received: by 10.213.65.68 with SMTP id h4csp357266imn; Tue, 13 Mar 2018 06:40:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELtJ4iJiFK4791+6kGrcmwcetrb2GHU3o1xA/j0z4kQjFKlhipD/LN5EdCYGaFys3I+nVavA X-Received: by 10.99.110.131 with SMTP id j125mr545876pgc.382.1520948421943; Tue, 13 Mar 2018 06:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520948421; cv=none; d=google.com; s=arc-20160816; b=t+Wm51tnsaCJhU4OPgBoZp3IPy8bR6q37PCvWQN53sLwG+Ob6MW4XZhjlOitMud2iq 5ifajCVdmeKT+JR2beorZ21HMNDiJrUdftatVpKz63sbA4mzcNrxd5qFsUWgGzs2AMr+ FtDnwe35s/An+wwD9xbOoeYKlrWS1d2XpCkSejmV1NmfSuIIiCf0gD4qROIo6Fp4OIp7 NkNVunPv11T48Vf0NpCJ/bfne0FEt5w7z1OJ5kieobvQurY9p0xh2RmPcexVaGjbPde9 7I8OTlL7/04Qq+HbZBAS9/a6pt/0a0zcHDeVnGeQcYZYnU32FleR/7JXLGT3aoRTDHXt 1p7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=FUeHHltbPCt4ghXEKtN6tuVGKFndIr/DHJPVKl1Uh8I=; b=YCqIeMNwXNK0363b+8ZoHyxWi6NYSWgFOwTVQjURKwW9IbuzQq4cUWovHdZnnjSnd3 cPW4RuyaXwfZKz//71V7Byf534lBRggI7xKoam1W2lCWtj9lQ8ZloHUAQvEVIRv9aejK r5FqWji8g8NPPGJ6GCHaL//fgl8au0FN6JY4JfsSuJKBnHil7o89bPu5GdM5ncpV147E v0GhaNHgF5HcRvxs0Yzd5IWfcv91Cajx8kLBSOcNdHibTn4Cs+r1Gv/Aih0V79mdrc5+ sZb4IqfaJ+HsyOpYvisngqEEL60XzKO99KqU7jPEj9MZECTnsXNC8wFVEybwe8NXHrT8 ZuQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=KGCFI42Z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2si142611pgt.44.2018.03.13.06.40.07; Tue, 13 Mar 2018 06:40:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=KGCFI42Z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752813AbeCMNiY (ORCPT + 99 others); Tue, 13 Mar 2018 09:38:24 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35448 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932607AbeCMN1B (ORCPT ); Tue, 13 Mar 2018 09:27:01 -0400 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=FUeHHltbPCt4ghXEKtN6tuVGKFndIr/DHJPVKl1Uh8I=; b=KGCFI42Zpsjm2153L5+bIzezR xnGVZsXZwwZnQVXgIMuQKVTx8hswC/ea0e6n2/h9l69eHDBMGw1iwJV4Dv82FB5HeJvwQfZiAIKcY 7iyXo1mnSwnOUgCY9j2h0VjRV0CAUGKivZPCIb7cm/l13B62/rtKrefhOTd5BArkUitSL6EV1Gqd4 yGeNYQ6m+xG6HR8PMV19m6ZHmbzn+85eXb7wsnD+LODsG3evrj36XDoz5lRupm9ZM8guu8px6VKuu 3IWtJKb7l4XBXlB6njWicMQ86nH7mhbltWLCwdSNhCdSvHL7ouDolUftg4pquN29rYqpSCaoxzZYj SyY5fq1OA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1evjxE-0004jZ-Io; Tue, 13 Mar 2018 13:27:00 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Ryusuke Konishi , linux-nilfs@vger.kernel.org Subject: [PATCH v9 43/61] shmem: Convert replace to XArray Date: Tue, 13 Mar 2018 06:26:21 -0700 Message-Id: <20180313132639.17387-44-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313132639.17387-1-willy@infradead.org> References: <20180313132639.17387-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ac53cae5d3a7..5813808965cd 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; } @@ -605,8 +601,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) { @@ -635,7 +630,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); @@ -1553,8 +1548,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.1