From patchwork Sun Jun 17 02:00:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10468235 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 840E960535 for ; Sun, 17 Jun 2018 02:02:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 731DA28BC1 for ; Sun, 17 Jun 2018 02:02:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67C7A28BDB; Sun, 17 Jun 2018 02:02:10 +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 CAE8928BC1 for ; Sun, 17 Jun 2018 02:02:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5ECBD6B0274; Sat, 16 Jun 2018 22:01:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 57BD16B0275; Sat, 16 Jun 2018 22:01:07 -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 292266B0276; Sat, 16 Jun 2018 22:01:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id D5C106B0274 for ; Sat, 16 Jun 2018 22:01:06 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id q18-v6so7729833pll.3 for ; Sat, 16 Jun 2018 19:01:06 -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=e0wudOUZYJQwjzypX+j3m1ttkDOvGtdncskdRKp75uA=; b=IdIT+NPNQhJyBY1XRwEenKuuXz2XBy9z0CGepsYqhLcrteiSV/nyrNaeT452aOdo67 /MUfl4e0ezaGtCSYrhOvKG4SDtVVAlbAYNaVr5ugSVo+OnzXdy+26ulSsnRKzlPtwDp4 ZzpywDz/O+KNdJxjwHXuXxaDcnfcRN2+Kx2Ml/24ZBvxj/YW5mwtu3cX3KLEwcQmMrrs EIaU+BmDKmbPAILBKckKFD5qkzSu1OB48Bli8s2/eldY6NG35JxXuBcj1JQ4wsnclueU XR/psiVNl7RrQXz6Kd9HUKGXAZvA4byFuQAVq52dXZ+QCiSSReCDFrDbtblL+Yh+J/VM 3I8g== X-Gm-Message-State: APt69E3ni3+BP5q8HgHuP3i76y2qDqEEltQGc9GO1gUm9GC/13er9zHy +ttuDWWMvHIdZbJ+bdqqVGjurkGXL2qcgJaalE613nHwtDt1xXz7XBbxL9HRnFsI8H49qeqgY+t NUaucMEosDN5tA0nvNro77Rf9OjBiAMRsPqAn4tYO92aq/xZSGumukExhM70n579apQ== X-Received: by 2002:a62:3c15:: with SMTP id j21-v6mr8103900pfa.7.1529200866543; Sat, 16 Jun 2018 19:01:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJkbTD7k8/+IlSa/r7Xs6IMuhHzgDWchZCdmAcBhdIQGMng3UIv5PeVyVfsw6WzMGu3AfXP X-Received: by 2002:a62:3c15:: with SMTP id j21-v6mr8103850pfa.7.1529200865552; Sat, 16 Jun 2018 19:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529200865; cv=none; d=google.com; s=arc-20160816; b=Nbr3Q+CreXSMsUunBtayJuMhh88xX0Uv3kk1DYJDhGEVVDyzO7Pq4Njn2gJ835mC8w jTT78L0TTSCV4PelJZVTWaEmfvpVyON9Y6wtNc0E9xbdEF+rU0+MEPi7qzBWx8r2+2t+ msD3qL5+ZIEwBcM2DGlHSzoWVqX4yMzAO3HbvKmXqnMV0FAUge2598C8DGn2t+T9c+LH POPWp/Q31dtvxeAZSJPO+TpyQu8c5ppG06KML5U0cq77IlijzgCfaYZXUmRdDL3PNQrz ujQJAY7DAWYl0lTcNixOlFmk7XxGe97kzfWzcWzMCD67VpvKGQ0Sdfds0GmFSglQndLw d5Iw== 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=e0wudOUZYJQwjzypX+j3m1ttkDOvGtdncskdRKp75uA=; b=w10HUybHKJX3RIb26lYMV3S8oLG6mr3Jegk7oPwGCDQlD4LMQHnr/ZluDao6TUZ30Q ahQiYd7BKUlK1imGFSELnpTURqgsChWMtxNItmsh/Ix6XODz1+WTbvGbIA+KFLoiXLSp hQoL5jZ6B1NOETfGvgDD/UH6ajJ5Edc3r9nJ/qW/u+qRSlWQMlCdsxs9F07GcbYEn4q0 5fgFQylkiCont6rJXdw+oVgi0y2SzpmZUEl0qPm/4Utj42gwpKbSSoIXR/YXcGurK3Dx OrTZrlySNbYFoYeMI77kY9Q3AzwFXVxlRB6/+VjwuBnUIUlbG6EIAA/OSUHgRYRqGR9N DnKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=pZujEGhr; 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 m3-v6si9353381pgu.237.2018.06.16.19.01.05 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Jun 2018 19:01:05 -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=pZujEGhr; 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=e0wudOUZYJQwjzypX+j3m1ttkDOvGtdncskdRKp75uA=; b=pZujEGhrlBP43V7+vrMNtARcd /lzpkm3Fq+C7N0XfgP4VK3L7Lb6VX3KFlDbjv29p2g0vQ4kC+MRAahvvwdoTd+auz1D1KgvKLNITQ EPuvLRbN6WH6FVMD2azUI/dsJ4IJiNbFzAQVU6N1cmL90gH9U6fhmELwBIUv1IBj4EWO4kWa7uWmz 0kXK2mnRY9d3hcR3J9GqcqNhudr6TagHW2ETrfTH2e2dftnCL48ylVHM+yHNbqYBXF0alZLZvcLL+ 4LWF7zpeK+6AB/FJomuMxpOoM4wsyoOo0NkpSUM5l5VZProabnDao5OkoOhCHnxyyXKouXtYAFGYP erodrUtdw==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUN04-0001La-Oa; Sun, 17 Jun 2018 02:01:04 +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 v14 38/74] mm: Convert add_to_swap_cache to XArray Date: Sat, 16 Jun 2018 19:00:16 -0700 Message-Id: <20180617020052.4759-39-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180617020052.4759-1-willy@infradead.org> References: <20180617020052.4759-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 Combine __add_to_swap_cache and add_to_swap_cache into one function since there is no more need to preload. Signed-off-by: Matthew Wilcox --- mm/swap_state.c | 93 +++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 64 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index dc312559f7df..ca18407a79aa 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -107,14 +107,15 @@ void show_swap_cache_info(void) } /* - * __add_to_swap_cache resembles add_to_page_cache_locked on swapper_space, + * add_to_swap_cache resembles add_to_page_cache_locked on swapper_space, * but sets SwapCache flag and private instead of mapping and index. */ -int __add_to_swap_cache(struct page *page, swp_entry_t entry) +int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp) { - int error, i, nr = hpage_nr_pages(page); - struct address_space *address_space; + struct address_space *address_space = swap_address_space(entry); pgoff_t idx = swp_offset(entry); + XA_STATE(xas, &address_space->i_pages, idx); + unsigned long i, nr = 1UL << compound_order(page); VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(PageSwapCache(page), page); @@ -123,50 +124,30 @@ int __add_to_swap_cache(struct page *page, swp_entry_t entry) page_ref_add(page, nr); SetPageSwapCache(page); - address_space = swap_address_space(entry); - xa_lock_irq(&address_space->i_pages); - for (i = 0; i < nr; i++) { - set_page_private(page + i, entry.val + i); - error = radix_tree_insert(&address_space->i_pages, - idx + i, page + i); - if (unlikely(error)) - break; - } - if (likely(!error)) { + do { + xas_lock_irq(&xas); + xas_create_range(&xas, idx + nr - 1); + if (xas_error(&xas)) + goto unlock; + for (i = 0; i < nr; i++) { + VM_BUG_ON_PAGE(xas.xa_index != idx + i, page); + set_page_private(page + i, entry.val + i); + xas_store(&xas, page + i); + xas_next(&xas); + } address_space->nrpages += nr; __mod_node_page_state(page_pgdat(page), NR_FILE_PAGES, nr); ADD_CACHE_INFO(add_total, nr); - } else { - /* - * Only the context which have set SWAP_HAS_CACHE flag - * would call add_to_swap_cache(). - * So add_to_swap_cache() doesn't returns -EEXIST. - */ - VM_BUG_ON(error == -EEXIST); - set_page_private(page + i, 0UL); - while (i--) { - radix_tree_delete(&address_space->i_pages, idx + i); - set_page_private(page + i, 0UL); - } - ClearPageSwapCache(page); - page_ref_sub(page, nr); - } - xa_unlock_irq(&address_space->i_pages); +unlock: + xas_unlock_irq(&xas); + } while (xas_nomem(&xas, gfp)); - return error; -} - - -int add_to_swap_cache(struct page *page, swp_entry_t entry, gfp_t gfp_mask) -{ - int error; + if (!xas_error(&xas)) + return 0; - error = radix_tree_maybe_preload_order(gfp_mask, compound_order(page)); - if (!error) { - error = __add_to_swap_cache(page, entry); - radix_tree_preload_end(); - } - return error; + ClearPageSwapCache(page); + page_ref_sub(page, nr); + return xas_error(&xas); } /* @@ -217,7 +198,7 @@ int add_to_swap(struct page *page) return 0; /* - * Radix-tree node allocations from PF_MEMALLOC contexts could + * XArray node allocations from PF_MEMALLOC contexts could * completely exhaust the page allocator. __GFP_NOMEMALLOC * stops emergency reserves from being allocated. * @@ -229,7 +210,6 @@ int add_to_swap(struct page *page) */ err = add_to_swap_cache(page, entry, __GFP_HIGH|__GFP_NOMEMALLOC|__GFP_NOWARN); - /* -ENOMEM radix-tree allocation failure */ if (err) /* * add_to_swap_cache() doesn't return -EEXIST, so we can safely @@ -423,19 +403,11 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, break; /* Out of memory */ } - /* - * call radix_tree_preload() while we can wait. - */ - err = radix_tree_maybe_preload(gfp_mask & GFP_KERNEL); - if (err) - break; - /* * Swap entry may have been freed since our caller observed it. */ err = swapcache_prepare(entry); if (err == -EEXIST) { - radix_tree_preload_end(); /* * We might race against get_swap_page() and stumble * across a SWAP_HAS_CACHE swap_map entry whose page @@ -443,26 +415,19 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, */ cond_resched(); continue; - } - if (err) { /* swp entry is obsolete ? */ - radix_tree_preload_end(); + } else if (err) /* swp entry is obsolete ? */ break; - } - /* May fail (-ENOMEM) if radix-tree node allocation failed. */ + /* May fail (-ENOMEM) if XArray node allocation failed. */ __SetPageLocked(new_page); __SetPageSwapBacked(new_page); - err = __add_to_swap_cache(new_page, entry); + err = add_to_swap_cache(new_page, entry, gfp_mask & GFP_KERNEL); if (likely(!err)) { - radix_tree_preload_end(); - /* - * Initiate read into locked page and return. - */ + /* Initiate read into locked page */ lru_cache_add_anon(new_page); *new_page_allocated = true; return new_page; } - radix_tree_preload_end(); __ClearPageLocked(new_page); /* * add_to_swap_cache() doesn't return -EEXIST, so we can safely