From patchwork Tue Feb 7 02:52:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13130900 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30586C61DA4 for ; Tue, 7 Feb 2023 02:53:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 779126B0078; Mon, 6 Feb 2023 21:53:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 701F06B007B; Mon, 6 Feb 2023 21:53:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57B666B007D; Mon, 6 Feb 2023 21:53:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 470D56B0078 for ; Mon, 6 Feb 2023 21:53:12 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 14844A0B57 for ; Tue, 7 Feb 2023 02:53:12 +0000 (UTC) X-FDA: 80438974224.25.A6EC813 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 6CC1C40005 for ; Tue, 7 Feb 2023 02:53:10 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=n3Xzbpwv; spf=none (imf11.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675738390; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tHEHYU6fwwSgYtD4IiT1K2TtAGYnTqD5ffLm2GBmZUI=; b=LIodVTPH1v/JYHWAaHDUvNlCfGm3qXYIZ8QTmbVUyaj2s3SdmWVKYJHkQIoUTDVDFDe9Ym mSNGWCaxjXxUetKsnAXPorIJVXJXD4cWkCTDMbCc9Kz9jmhtQBm1iudp+KUgOSWxmQNxLn GR6ReU4oiwUUWtdWhcJGr9SEEbkaDsw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=n3Xzbpwv; spf=none (imf11.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675738390; a=rsa-sha256; cv=none; b=dj0hfBP8Ox8QaP5FfSeyvbM0xJJ7T73NYk4hMN4c42Uols7DY2/RSIQRRCT5IhUnrHAkUm 3kqBghpRXHI/O70F6upbjJ+lKK3Kp0jDrj6PSZBlh6jw70J6MImLIyP/tV0m14HLfk5Buv +x9X1mhDCcn9ywDOJHsav46tKIgKRzg= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=tHEHYU6fwwSgYtD4IiT1K2TtAGYnTqD5ffLm2GBmZUI=; b=n3Xzbpwvi5oAiSo5zYlxk8sfdB 7WVyFF3CjHjFDkGUujgYcbAC9WFOsz2K3HCPL7jlrhJ31kurxtDK2v/eYtMu0fq0FvLAq94pd/Yig Wr6906Jfnc0ktSQfgiH7WhxLuAV4eUFplQBu+1wf3jWeKpVUQg9ZvmUPN4v4OFeKp7DN1KsCYiAJl GCta8WSWj7WZ3mzcytPX2363rN5qT10QiCologeRtELY3PNjzb129tAoZ2K4byHBeFigqL3W9RdHS CGCkjCivYb/giDRn4a52UDQ+Quqb+J5lt8wR3OJJKI1gkKE2bVvyL4SZ66CKP2ebUSgLoDLkrjvGM ilnor7xQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPE6U-00AaJC-4H; Tue, 07 Feb 2023 02:53:06 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, dave@stgolabs.net, a.manzanares@samsung.com, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [RFC 2/2] shmem: add support to ignore swap Date: Mon, 6 Feb 2023 18:52:59 -0800 Message-Id: <20230207025259.2522793-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230207025259.2522793-1-mcgrof@kernel.org> References: <20230207025259.2522793-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6CC1C40005 X-Stat-Signature: 61hkrtzf4br9kwx1kfaeupyuahcqbhbp X-HE-Tag: 1675738390-982487 X-HE-Meta: U2FsdGVkX1/v/yIrZSX5z/8Z7cNtnL+ylMHkRSEL8xTXEKA60Mj2Of5CWzgTjWSVhmhoRvBX10ME2TQLbS0GrSfw1aYj73hPyrh6YVDm220MtGcZqw/ec8IeELe/CFo5YjIUR3ROVWMGuf1CXvMlN015FL5pF6ChY+dlybW38sPH5UowXCtrNzS3BOepSa1bn/QQz5Br2tibjiU8M0FqVb9sdkAPDQeKnIdE44T4PqAqcYXsjSlZlPnQQgTyHevH40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ijDxObNxrdgLGR4zSnM/Q5dT/sCc01f3cvfoNNxz1YcsiWEYoWKE1wLvD27A 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: In doing experimentations with shmem having the option to avoid becomes a useful mechanism. One of the *raves* about brd over shmem is you can avoid swap, but that's not really a good reason to use brd if we can instead use shmem. Using brd has its own good reasons to exist, but just because "tmpfs" doesn't let you do that is not a great reason to avoid it if we can easily add support for it. I don't add support for reconfiguring incompatible options, but if we really wanted to we can add support for that. Signed-off-by: Luis Chamberlain --- include/linux/shmem_fs.h | 1 + mm/shmem.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index d09d54be4ffd..98a7d53f6cc5 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -45,6 +45,7 @@ struct shmem_sb_info { kuid_t uid; /* Mount uid for root directory */ kgid_t gid; /* Mount gid for root directory */ bool full_inums; /* If i_ino should be uint or ino_t */ + bool noswap; /* ingores VM relcaim / swap requests */ ino_t next_ino; /* The next per-sb inode number to use */ ino_t __percpu *ino_batch; /* The next per-cpu inode number to use */ struct mempolicy *mpol; /* default memory policy for mappings */ diff --git a/mm/shmem.c b/mm/shmem.c index a2c6aa11aab8..92aa927cf569 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -116,10 +116,12 @@ struct shmem_options { bool full_inums; int huge; int seen; + bool noswap; #define SHMEM_SEEN_BLOCKS 1 #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 #define SHMEM_SEEN_INUMS 8 +#define SHMEM_SEEN_NOSWAP 16 }; #ifdef CONFIG_TMPFS @@ -1334,11 +1336,15 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) struct shmem_inode_info *info; struct address_space *mapping = folio->mapping; struct inode *inode = mapping->host; + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); swp_entry_t swap; pgoff_t index; BUG_ON(!folio_test_locked(folio)); + if (wbc->for_reclaim && unlikely(sbinfo->noswap)) + return AOP_WRITEPAGE_ACTIVATE; + /* * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, @@ -3465,6 +3471,7 @@ enum shmem_param { Opt_uid, Opt_inode32, Opt_inode64, + Opt_noswap, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -3486,6 +3493,7 @@ const struct fs_parameter_spec shmem_fs_parameters[] = { fsparam_u32 ("uid", Opt_uid), fsparam_flag ("inode32", Opt_inode32), fsparam_flag ("inode64", Opt_inode64), + fsparam_flag ("noswap", Opt_noswap), {} }; @@ -3569,6 +3577,10 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) ctx->full_inums = true; ctx->seen |= SHMEM_SEEN_INUMS; break; + case Opt_noswap: + ctx->noswap = true; + ctx->seen |= SHMEM_SEEN_NOSWAP; + break; } return 0; @@ -3667,6 +3679,14 @@ static int shmem_reconfigure(struct fs_context *fc) err = "Current inum too high to switch to 32-bit inums"; goto out; } + if ((ctx->seen & SHMEM_SEEN_NOSWAP) && ctx->noswap && !sbinfo->noswap) { + err = "Cannot disable swap on remount"; + goto out; + } + if (!(ctx->seen & SHMEM_SEEN_NOSWAP) && !ctx->noswap && sbinfo->noswap) { + err = "Cannot enable swap on remount if it was disabled on first mount"; + goto out; + } if (ctx->seen & SHMEM_SEEN_HUGE) sbinfo->huge = ctx->huge; @@ -3687,6 +3707,10 @@ static int shmem_reconfigure(struct fs_context *fc) sbinfo->mpol = ctx->mpol; /* transfers initial ref */ ctx->mpol = NULL; } + + if (ctx->noswap) + sbinfo->noswap = true; + raw_spin_unlock(&sbinfo->stat_lock); mpol_put(mpol); return 0; @@ -3784,6 +3808,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) ctx->inodes = shmem_default_max_inodes(); if (!(ctx->seen & SHMEM_SEEN_INUMS)) ctx->full_inums = IS_ENABLED(CONFIG_TMPFS_INODE64); + sbinfo->noswap = ctx->noswap; } else { sb->s_flags |= SB_NOUSER; }