From patchwork Mon Jun 11 14:06:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10457945 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 55D1860467 for ; Mon, 11 Jun 2018 14:09:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 424D72835B for ; Mon, 11 Jun 2018 14:09:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36A8F28451; Mon, 11 Jun 2018 14:09:18 +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 A84C22835B for ; Mon, 11 Jun 2018 14:09:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44BA16B0283; Mon, 11 Jun 2018 10:06:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 28DFF6B0285; Mon, 11 Jun 2018 10:06:59 -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 0FB856B0284; Mon, 11 Jun 2018 10:06:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id B06A36B0284 for ; Mon, 11 Jun 2018 10:06:58 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id a13-v6so10296999pfo.22 for ; Mon, 11 Jun 2018 07:06:58 -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=uvWT6f10klRi6JfdlHzw39lMupXUF1V/YTllgCogeUs=; b=U9SB7JYC7+dCF8ycamGolbhvJyQHrSWgcB9MrCylPfM1CGpeU2OI0xN72djpvkVkNy 3ODsyONA794QEHb8bmYvDOG7nXIP2bq1r3r7qvCH9m6PO2xYN2a6LfDzIVPOranP93H9 fURTNQvD9rMsARvZbcj2DdUby8+4IZf3KrNxGLRCpgTaiFNQ1uwsd5LceYM3GyIAU+kA oIw8sgWZv+k3XCk/eFy/+InnmV3GnzGQiNc+WolLTlP617agb28mjysS3VKNs7NW2i3Q M/ola5uWfPwNB7gBuDcRSAraxjoz2v/yawDq+2MWim61bXzQoH4x6KwsNG4d6NMIGkT2 lZfw== X-Gm-Message-State: APt69E2QgbK7Jl5nJww9madDCMSHvmz/uXYii5W0L/uL3ZphALXr3EHP BRxiPRvl/lXht/PtPJY3gWeTDcqq3uBw2nfqYzIEa50OeVaDgMscWIvyQDogg26IMNEp/HJdJBk 4OWCH9uesK8KAbOPMxeoAQ8ZRtva701G3L7eWTvURHN3Pw+bm/yiibAc/M6qdcwNS0w== X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr19012839plc.248.1528726018422; Mon, 11 Jun 2018 07:06:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJf0/7N3ui+lUekibCIlCOhtbx+vnL9r7QYkvGpEM2KsH8jQL//VQvXq5yJvxW6LpJODGr2 X-Received: by 2002:a17:902:3381:: with SMTP id b1-v6mr19012784plc.248.1528726017683; Mon, 11 Jun 2018 07:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726017; cv=none; d=google.com; s=arc-20160816; b=JjDMN1io/3OBWfAlO0S6dB4R0ihEIB8dQ76kytPMyiez7d7wrQjnp0LjSRt7yNDnQF 7IiPvHxU91xrNeNNG9Uj+NH3Hd/DrRaT739WJQsfcbfMnLy6ys9Lo1Gjvrv99SIupvwC sszyHcXZrHhjs+ppqYizjNjrOUpqX5iFexPzGX9L4sgHqNE9ZLbwHqswxV2h18IpG/f+ VhOw96Aq4zEFMT4frShnPtEo9qTRHqg1AvxG37dAzvhxMEbMTGHWfWgm/2p9etFOvWXl 97cnE2rxz3YwdIcTwe3qgMcz7G9gFyQzBGSpDOEP5yGZdYkIQBcdE72Rkqe55P3sB25V pw4w== 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=uvWT6f10klRi6JfdlHzw39lMupXUF1V/YTllgCogeUs=; b=N0gsJbzincFhSQ+CWZaCrOnAjQ3C6hpll0zpbsZeqoqfI2huLlIiqH15qtUghKoViW Py49Gw4T4oK5Yec6dr8EFcaa80/je2N8PEvAtbh6tGsoGxjLi2pdG4xPP8Lpz4PY2AkD 6YKABhj+Mowcn1vQEh8o8wILXSQ4Narz+DKEoC9jTvf5io45cGwoBK5mFQ89jD8MtMYb u8QDKGYH2G9NYIfUFfNbmzVu5X1U8C7KXBU8IcLMkPI11nDJBp7FKAxs24YLWSDTZxDR A71Inxzd8EEGsgTlS025W/E1jYu7YoWAz0zDZd0vY6lTrVD8lbM3H4Qo1U0ljjip6uU8 24Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=Tb4OH0Jt; 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 89-v6si24918422pfi.362.2018.06.11.07.06.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:57 -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=Tb4OH0Jt; 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=uvWT6f10klRi6JfdlHzw39lMupXUF1V/YTllgCogeUs=; b=Tb4OH0Jto49hcS/OlmqvrGaTX 2w31KZDWmN1UCgddj7yKcHNvky0pWsrvTvMVqnUMh4QYJXcmQqwfLgBRe3rlb/xsJOCJmLU0a9RmS ztKBocaDK4KTW+ljTWVyJ7jiJwiF15ZSBEs0HrrK0POdgfFx7ahLhh+yz1pHN8mc6BhHymvud3Spg MDbWWjjAYt813vsO+EJ4bXkY0jIfa5hjx1iTswqdxUiLjYmG4ZFrCYIh8XpdupdbwDbS7Nvn2Uj5i hOAzMqz9kOBhxddYRnGRENmzPlUVJppdn7Ip7K9pX/fQ4VmwOmlCcRAZQ8Je0nl+T4yZ+I8fDw8+w iipgW+04w==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNTE-0004mE-Gu; Mon, 11 Jun 2018 14:06:56 +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 38/72] mm: Convert delete_from_swap_cache to XArray Date: Mon, 11 Jun 2018 07:06:05 -0700 Message-Id: <20180611140639.17215-39-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 Both callers of __delete_from_swap_cache have the swp_entry_t already, so pass that in to make constructing the XA_STATE easier. Signed-off-by: Matthew Wilcox --- include/linux/swap.h | 5 +++-- mm/swap_state.c | 24 ++++++++++-------------- mm/vmscan.c | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index a450a1d40b19..470570dac9e8 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -404,7 +404,7 @@ extern void show_swap_cache_info(void); extern int add_to_swap(struct page *page); extern int add_to_swap_cache(struct page *, swp_entry_t, gfp_t); extern int __add_to_swap_cache(struct page *page, swp_entry_t entry); -extern void __delete_from_swap_cache(struct page *); +extern void __delete_from_swap_cache(struct page *, swp_entry_t entry); extern void delete_from_swap_cache(struct page *); extern void free_page_and_swap_cache(struct page *); extern void free_pages_and_swap_cache(struct page **, int); @@ -564,7 +564,8 @@ static inline int add_to_swap_cache(struct page *page, swp_entry_t entry, return -1; } -static inline void __delete_from_swap_cache(struct page *page) +static inline void __delete_from_swap_cache(struct page *page, + swp_entry_t entry) { } diff --git a/mm/swap_state.c b/mm/swap_state.c index ac07db436c15..84595e1a4cd7 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -154,23 +154,22 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp) * This must be called only on pages that have * been verified to be in the swap cache. */ -void __delete_from_swap_cache(struct page *page) +void __delete_from_swap_cache(struct page *page, swp_entry_t entry) { - struct address_space *address_space; + struct address_space *address_space = swap_address_space(entry); int i, nr = hpage_nr_pages(page); - swp_entry_t entry; - pgoff_t idx; + pgoff_t idx = swp_offset(entry); + XA_STATE(xas, &address_space->i_pages, idx); VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(!PageSwapCache(page), page); VM_BUG_ON_PAGE(PageWriteback(page), page); - entry.val = page_private(page); - address_space = swap_address_space(entry); - idx = swp_offset(entry); for (i = 0; i < nr; i++) { - radix_tree_delete(&address_space->i_pages, idx + i); + void *entry = xas_store(&xas, NULL); + VM_BUG_ON_PAGE(entry != page + i, entry); set_page_private(page + i, 0); + xas_next(&xas); } ClearPageSwapCache(page); address_space->nrpages -= nr; @@ -243,14 +242,11 @@ int add_to_swap(struct page *page) */ void delete_from_swap_cache(struct page *page) { - swp_entry_t entry; - struct address_space *address_space; - - entry.val = page_private(page); + swp_entry_t entry = { .val = page_private(page) }; + struct address_space *address_space = swap_address_space(entry); - address_space = swap_address_space(entry); xa_lock_irq(&address_space->i_pages); - __delete_from_swap_cache(page); + __delete_from_swap_cache(page, entry); xa_unlock_irq(&address_space->i_pages); put_swap_page(page, entry); diff --git a/mm/vmscan.c b/mm/vmscan.c index 03822f86f288..0448b1b366d9 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -753,7 +753,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, if (PageSwapCache(page)) { swp_entry_t swap = { .val = page_private(page) }; mem_cgroup_swapout(page, swap); - __delete_from_swap_cache(page); + __delete_from_swap_cache(page, swap); xa_unlock_irqrestore(&mapping->i_pages, flags); put_swap_page(page, swap); } else {