From patchwork Fri Sep 7 07:39:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10591777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C018174C for ; Fri, 7 Sep 2018 07:39:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C2282A630 for ; Fri, 7 Sep 2018 07:39:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FFB72A659; Fri, 7 Sep 2018 07:39:42 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE 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 C73662A630 for ; Fri, 7 Sep 2018 07:39:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3732E6B7D2D; Fri, 7 Sep 2018 03:39:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 256496B7D2E; Fri, 7 Sep 2018 03:39:39 -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 0A7296B7D2F; Fri, 7 Sep 2018 03:39:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id B9EF86B7D2D for ; Fri, 7 Sep 2018 03:39:38 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id e15-v6so7192762pfi.5 for ; Fri, 07 Sep 2018 00:39:38 -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=T4zypnAVQJfVK6JjN6ITEGJDUN7vtLnMURc1S60reio=; b=nJdPUjC9Bf1blafYhiqq5pLe1RiCLFQle+k4KAN/0FKpbjYJ9BSVC9x0gfzWtp7/7p Wiu5JjUX3lx3Q+CvMVyAF66sLQ+LJcwZCUJnniDl3drsnhnCKMpKkAfu/UdnPTMifMbX y0GmN5eZkPZXqDESTnJxwUn7dDgKixEMy64JkJ+Mp4+x2F9mNhHleERPF3INRdQjnlYk 2oZa8BX+QInUA1WlJhVahI2oFiBcI8kRM2/QzH6+ka83RhDpEI2c7KyIqsc04Zsgenny OmzHwhgV+hhIgai+0ZMiZu+11cSt8zrHE1iP3bBW6tALBS/7YlcGyQkdidgB+Wa9gdXU NIZQ== X-Gm-Message-State: APzg51A7CWNN5js7PQdkNYz3anm2QifLEImY6Gx1v4f6wBjjcYSSqVte uod9RJx5AcxAphMqcG/OOFgMz0WXXD3wiRmJnfcFHF8NAhVskisGUMvVi/im7/rCS/bWdgYtc8o osC+QKTXnSn+XEz/MLLf0+R2557IqjX2SauMyx3niJXMLILhSHCewpmI0tnC3t4rbgvP7uJY1SE 3PH1r5F0BB11+gd69rIxU27g2JpM/iutfKScglCM2LGaW/00WkYyzV0eL2G5LhhBCZyUoH2NTrm OBz08bWs5k7B4aErB0+XIxo7lW0AHtIYiPBJpGnjzW7LBPn5qWcIwZSrDaEdFX14NRelQRGliOT ndsEf7eDhNC+YLHrwaX0Fzbc5Lrt2KYcI+DryslfPXcs0RvhMUjJgdkFaV/9I2mug0u7GLZGDjJ 5 X-Received: by 2002:a62:234d:: with SMTP id j74-v6mr7064101pfj.106.1536305978409; Fri, 07 Sep 2018 00:39:38 -0700 (PDT) X-Received: by 2002:a62:234d:: with SMTP id j74-v6mr7064064pfj.106.1536305977591; Fri, 07 Sep 2018 00:39:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536305977; cv=none; d=google.com; s=arc-20160816; b=vNKul/fiEcs8NHzTYSi2UowxdU53MFKnS7tJCHX24Mg1Q7zVNQ29zbU3njv57Qvb5z mfK8p/f5Gs4kdIh5YVpkI2rruiW0PT8XXxYyjNBc+fRqRfpGcd294cOdgVg4DlPrXqz1 lRWITfR26NzSBHLJBjbqUksCthzbMHbewn9tEjMdqG11aLiULVkEBz+yXfSVK4d8KD8t 2O1vcdpg5ixgh4q0IDB39t4/2aJ+P58ldISyPUh+dw7jb1w5Tuk9VC8XbXXd7tDaklAZ 09fR3NbJN0IDtYTC2/Xz8IKV/sYi1VewdXvJIXlfpAKgZETJTbSTOBAurcLRvnUoYtlA l3Tw== 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; bh=T4zypnAVQJfVK6JjN6ITEGJDUN7vtLnMURc1S60reio=; b=J753ll+wJeBewARKHgjA1QaFZUeCF1UfXVaq9PeyOAS9f2NDeSpCV2o/yPfeWxWBMi sbwpW2tR9nGzy0n78cPjXzcAp2vYZaqDben2Sdx/lOU4mVhA+9oSG3I6ow1Gf4O6JHmk XaUa30/lMKBEVS/dyFbaS9Ifzy9yZCjv/IuS2/loTiWbCdLthafjxFhE/biRf0wDcpS9 1OG7LEdlQoKpyeh7bpMKGAmUPg7mOrt1u4RuDAZ3CnnvesRKNW6TJ8JAtuG7tXpFyUmc AYD/fFmD36jAF8Uc36UKcy3x6U8FmHRFAqXJbk/aj4DpnEQjrsr3Gfkfv7KONA4Y1Uta VDGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=cI2xbv+h; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of osandov@osandov.com) smtp.mailfrom=osandov@osandov.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y4-v6sor1511189pfm.45.2018.09.07.00.39.37 for (Google Transport Security); Fri, 07 Sep 2018 00:39:37 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of osandov@osandov.com) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=cI2xbv+h; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of osandov@osandov.com) smtp.mailfrom=osandov@osandov.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T4zypnAVQJfVK6JjN6ITEGJDUN7vtLnMURc1S60reio=; b=cI2xbv+hDJwZ0+3IBkv98TFp0Mq011U3+dhk6+LEGnZR2+yEgpSYJQTwMGOTYji41X VE2i1dqplfW2VJOWjWnktzuq0eUhF8pYJlItm2THrdSGBIgepankPwMYc4FKMB3nTkET CqzrqCei014oXVfMF97JEEESUHZEdqf7vdBSiYMV5YyQ25wRQt6n85LIMlv1xJ/EChMK tiVjt/M6HvTcs9GemKAJ9rgVd1fRHUYiHWBkg2VYXI7B+r2H/jQhvvjUqaUoRnSMAxBo SBwOh0C3JS897TbotD0daNfTTtMNX/1eCrfx/nAbqm1DCmmdB/Y9PNvWHlrtGgxD05LT ps2g== X-Google-Smtp-Source: ANB0VdYk4kVHUBK0zs1Tsax/yfZqaspTVo/Ra4qhRcrYT73esq49m3sue+qpeCwRHAfuS1AjmLyepw== X-Received: by 2002:a62:1e81:: with SMTP id e123-v6mr7107456pfe.24.1536305976984; Fri, 07 Sep 2018 00:39:36 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:904c]) by smtp.gmail.com with ESMTPSA id i65-v6sm16276914pfk.43.2018.09.07.00.39.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 00:39:36 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, linux-mm@kvack.org Subject: [PATCH v6 1/6] mm: split SWP_FILE into SWP_ACTIVATED and SWP_FS Date: Fri, 7 Sep 2018 00:39:15 -0700 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: 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: Omar Sandoval The SWP_FILE flag serves two purposes: to make swap_{read,write}page() go through the filesystem, and to make swapoff() call ->swap_deactivate(). For Btrfs, we want the latter but not the former, so split this flag into two. This makes us always call ->swap_deactivate() if ->swap_activate() succeeded, not just if it didn't add any swap extents itself. This also resolves the issue of the very misleading name of SWP_FILE, which is only used for swap files over NFS. Reviewed-by: Nikolay Borisov Signed-off-by: Omar Sandoval --- include/linux/swap.h | 13 +++++++------ mm/page_io.c | 6 +++--- mm/swapfile.c | 13 ++++++++----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 8e2c11e692ba..0fda0aa743f0 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -167,13 +167,14 @@ enum { SWP_SOLIDSTATE = (1 << 4), /* blkdev seeks are cheap */ SWP_CONTINUED = (1 << 5), /* swap_map has count continuation */ SWP_BLKDEV = (1 << 6), /* its a block device */ - SWP_FILE = (1 << 7), /* set after swap_activate success */ - SWP_AREA_DISCARD = (1 << 8), /* single-time swap area discards */ - SWP_PAGE_DISCARD = (1 << 9), /* freed swap page-cluster discards */ - SWP_STABLE_WRITES = (1 << 10), /* no overwrite PG_writeback pages */ - SWP_SYNCHRONOUS_IO = (1 << 11), /* synchronous IO is efficient */ + SWP_ACTIVATED = (1 << 7), /* set after swap_activate success */ + SWP_FS = (1 << 8), /* swap file goes through fs */ + SWP_AREA_DISCARD = (1 << 9), /* single-time swap area discards */ + SWP_PAGE_DISCARD = (1 << 10), /* freed swap page-cluster discards */ + SWP_STABLE_WRITES = (1 << 11), /* no overwrite PG_writeback pages */ + SWP_SYNCHRONOUS_IO = (1 << 12), /* synchronous IO is efficient */ /* add others here before... */ - SWP_SCANNING = (1 << 12), /* refcount in scan_swap_map */ + SWP_SCANNING = (1 << 13), /* refcount in scan_swap_map */ }; #define SWAP_CLUSTER_MAX 32UL diff --git a/mm/page_io.c b/mm/page_io.c index aafd19ec1db4..e8653c368069 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -283,7 +283,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, struct swap_info_struct *sis = page_swap_info(page); VM_BUG_ON_PAGE(!PageSwapCache(page), page); - if (sis->flags & SWP_FILE) { + if (sis->flags & SWP_FS) { struct kiocb kiocb; struct file *swap_file = sis->swap_file; struct address_space *mapping = swap_file->f_mapping; @@ -365,7 +365,7 @@ int swap_readpage(struct page *page, bool synchronous) goto out; } - if (sis->flags & SWP_FILE) { + if (sis->flags & SWP_FS) { struct file *swap_file = sis->swap_file; struct address_space *mapping = swap_file->f_mapping; @@ -423,7 +423,7 @@ int swap_set_page_dirty(struct page *page) { struct swap_info_struct *sis = page_swap_info(page); - if (sis->flags & SWP_FILE) { + if (sis->flags & SWP_FS) { struct address_space *mapping = sis->swap_file->f_mapping; VM_BUG_ON_PAGE(!PageSwapCache(page), page); diff --git a/mm/swapfile.c b/mm/swapfile.c index d954b71c4f9c..d3f95833d12e 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -989,7 +989,7 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size) goto nextsi; } if (size == SWAPFILE_CLUSTER) { - if (!(si->flags & SWP_FILE)) + if (!(si->flags & SWP_FS)) n_ret = swap_alloc_cluster(si, swp_entries); } else n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE, @@ -2310,12 +2310,13 @@ static void destroy_swap_extents(struct swap_info_struct *sis) kfree(se); } - if (sis->flags & SWP_FILE) { + if (sis->flags & SWP_ACTIVATED) { struct file *swap_file = sis->swap_file; struct address_space *mapping = swap_file->f_mapping; - sis->flags &= ~SWP_FILE; - mapping->a_ops->swap_deactivate(swap_file); + sis->flags &= ~SWP_ACTIVATED; + if (mapping->a_ops->swap_deactivate) + mapping->a_ops->swap_deactivate(swap_file); } } @@ -2411,8 +2412,10 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span) if (mapping->a_ops->swap_activate) { ret = mapping->a_ops->swap_activate(sis, swap_file, span); + if (ret >= 0) + sis->flags |= SWP_ACTIVATED; if (!ret) { - sis->flags |= SWP_FILE; + sis->flags |= SWP_FS; ret = add_swap_extent(sis, 0, sis->max, 0); *span = sis->pages; }