From patchwork Thu May 24 21:41:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10425577 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 BFAD0602D8 for ; Thu, 24 May 2018 21:41:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1B48295E2 for ; Thu, 24 May 2018 21:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A452E29615; Thu, 24 May 2018 21:41:50 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1975429611 for ; Thu, 24 May 2018 21:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S971644AbeEXVls (ORCPT ); Thu, 24 May 2018 17:41:48 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:37679 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S971626AbeEXVll (ORCPT ); Thu, 24 May 2018 17:41:41 -0400 Received: by mail-pl0-f67.google.com with SMTP id w19-v6so1829701plq.4 for ; Thu, 24 May 2018 14:41:41 -0700 (PDT) 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 :in-reply-to:references; bh=xX9+bpWM5Urwog0221MZc9aDrggmIJQk+7dyxsMOEOA=; b=bgTmzxRW38IlSrbGq5FAT0g2ND6iIuSSZ3TqccFWQlzia99sLy8uPR4qk6TlOOl525 fI4a/FbYWa/ZX1pF4dKs1xnUsOc2Y07TF++7EIM7s600XNvxjt4JvHT+c9ljVJFD7iDR atS/fBWjDtRLrewzNukiXV+bH9bfDUgsczv5x7p/Pb8pzi+xsIMHtbl5DFzZ0joPUFmR sDOJdbvYEpcfxDi/MZJSj8mbAPhw66xNxKVpYjzDMZJQNF7oi+ojiqhxltU/9iDPa6TC 2cnpEFUegv2BvheCK0SUyHIrmpWJUMBMUEZmrKTFF7MXC8a5q+qxzf+vbrZ/LMeJp5P4 9QEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=xX9+bpWM5Urwog0221MZc9aDrggmIJQk+7dyxsMOEOA=; b=QEls8vCEtXamn7jl7IgrYsQNB2pLW1h7gRZmga6WLUrOvBPhpvb87ZwxSR4HDelj7R xbjrrBYG+4lAZuksTBv0Zq3SEfYaI5B6rmK58X0c34wsgkmFdRnJvj2dn6GBPoRJlIwk jVq6Lsw9HN34+iHEkyNpsC46qIBo4wqisQyM2X5Aqsp6o5bkN6QNicmd/81UYn5FDC9f zOT4zuouC7ADnxi4qHcHZX++siU+7BQMUoqKJBc5F40wxxFEk6dthfGazlO9Dl3BZGJT yDdIcRK9XDqP6kaiJI/2IYppmAIuPEifPAkDijgvhoCiO6GiqpmGod0DGyGsIaPCsgAx BgNA== X-Gm-Message-State: ALKqPwezQge/2cO3py/mPfSEyxj6UF4k5QiadZCcEaBbj5T92k1g8ngb tR9mTdte5+gh0ayPMD80hSVRwPmY0XE= X-Google-Smtp-Source: AB8JxZpbWoW6XcInVgAq1wLRApGbrnfjetMdpLxUU6Lzp97brhT47Z45ObG1o5aaDfOZWnTjEheXjw== X-Received: by 2002:a17:902:b946:: with SMTP id h6-v6mr9354144pls.3.1527198100623; Thu, 24 May 2018 14:41:40 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:a0b5]) by smtp.gmail.com with ESMTPSA id g68-v6sm37388994pfk.53.2018.05.24.14.41.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 14:41:39 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, Tejun Heo Subject: [RFC PATCH v4 1/6] mm: split SWP_FILE into SWP_ACTIVATED and SWP_FS Date: Thu, 24 May 2018 14:41:25 -0700 Message-Id: <289f334fa8e5d1239eab667415d287edf0e13f14.1527197312.git.osandov@fb.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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. Signed-off-by: Omar Sandoval Reviewed-by: Nikolay Borisov --- 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 2417d288e016..29dfd436435c 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 b41cf9644585..f2d06c1d0cc1 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; @@ -364,7 +364,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; @@ -422,7 +422,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 cc2cf04d9018..886c9d89b144 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -973,7 +973,7 @@ int get_swap_pages(int n_goal, bool cluster, swp_entry_t swp_entries[]) goto nextsi; } if (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, @@ -2327,12 +2327,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); } } @@ -2428,8 +2429,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; }