From patchwork Tue Feb 7 02:52:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13130899 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 D079DC636D3 for ; Tue, 7 Feb 2023 02:53:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FAD86B0075; Mon, 6 Feb 2023 21:53:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AB7D6B0078; 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 EF1116B007B; Mon, 6 Feb 2023 21:53:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DAB6F6B0075 for ; Mon, 6 Feb 2023 21:53:11 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A63FFA0B69 for ; Tue, 7 Feb 2023 02:53:11 +0000 (UTC) X-FDA: 80438974182.22.0D7A222 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id 814ADC0007 for ; Tue, 7 Feb 2023 02:53:08 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Hyly4Ctg; spf=none (imf10.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=1675738389; 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=ppc+iA/4jLT/kyK/2EkWiSyEAfiza0foS2nW0M1ktaU=; b=Cj7ATU6IEqyYaf4ssZrNcXsDIic7RDDIl9Ox8u6fNct50/SNMOwe0mvJscrUecSJAeLeIh tV7dxCEpX/0N2ibOgd/I7mbx7spT798jSRv8jK1N1AgJFilPozc73SmnMjlp9jTCPFW+MH IykzDVx1gGc92oX/SqVILlYONM+Ju7U= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Hyly4Ctg; spf=none (imf10.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=1675738389; a=rsa-sha256; cv=none; b=LvlPkUcANleHQ3DUV4k/PUtbdH7YLVnVd9Sd61chF83RqiMNlStgeNucoz1l1/VoDfEe0I AIQ72O6pZu0sGjR0AxavfMk03GjcUFSCF7vIvITaOAvkuAiTxP/lO5Nz3ca2p0wHJxB4r7 115zdzUGzqU0h+YXrLuHTB/qSUhzbXc= 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=ppc+iA/4jLT/kyK/2EkWiSyEAfiza0foS2nW0M1ktaU=; b=Hyly4Ctgcl2ybcZ9Uf6YVJBbZj d8rXp8MTOtkLsYo89C6303qGny+ZLJ8X1/OlyBMSZJiK5eMMDXxjvBmjonKGnjQ60/1hfMX6pbfg8 yiKR4m6fBQf9AmmC/PJ3Sfm6BxquDZdjRcVWMEhdS6CAi2O3XaUWdAA1WK4305EBn7wctnsiPwLLc HlI1EXwYA1U1BLrsam0jMtbVPygKbeNK0X1ap6NHxElHw5Vshw6660O0DRiXF2lpD7cUTvkaqNDg+ fFL17wN/1bPIrceXZHl+j0O+JrhHxGb7P5oTJxapL85uPnZY8Kw3vxY2kKsojLU/jZ8kPUpN88pMo SMb57LLQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPE6S-00AaIb-SN; Tue, 07 Feb 2023 02:53:04 +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 1/2] shmem: set shmem_writepage() variables early Date: Mon, 6 Feb 2023 18:52:58 -0800 Message-Id: <20230207025259.2522793-2-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-Rspamd-Queue-Id: 814ADC0007 X-Stat-Signature: ce9rbudagradmzsui37pnczaurgxh9gt X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1675738388-184319 X-HE-Meta: U2FsdGVkX19Gyb62NqwTqRnQp4p/7tNTt5cUB5kPrf4pXMTzcZiBhXg1LIzfxgt4fECuV5lg2vPWYgO/sEEmv+fKP9sqWPJM+adMpg+G6tEcui7hAiYSYS9zR19JIbPbnWsuofwJRZ/T3PaF6uPyjs0j4HfTuYUuLtrymg3biAmAikRC30+YRoMjIHI4GRJQ187YwcYZ6Cjmza75AWGYKx0D2OPv0s5Ac/D3j7DZ1UrE9mhJov/+0HH9L7Fz9He2J/ny3D6TKK1WIgVit2p/Se51/vWHBY+dAbwY2QrvckUdUhG4r22fdCUKseTsdCaS+QA/Lhs3GiV1IaSKs00HJQXxmV/HeAApU3+uegIk/v141SwYrfCEpcgcCtE0SqyBM6ZK7th7hpPKeI/04PkS1m8jepmTc7Z9SJtM0RJ/vYUZGZY7+UbScdXXaYI3f4PuhmoZHsmLXzyWNgsv28EIrthjD9lRcJnjypygLmiaDJvwNdEv+gqqwofEaaY2YOKjW330yWkUILWl2SsexOtiPaedpkAFIA/BVPsFg3STSuo4PL3TFLOgMQbgQuJBtgeLK+MwVOLy5LHtU//JF2VbxO0XWlIATMvFQK/6OKuq85waFgb+TAYaFqE3DRKZwQcupZnyxVLbIWhZQaiJY9/aCnPeQczB82QPDiP9C6FDIqOalYY1hn9he4AFna0DnEUEHGWdtow203ljnyyxXd7HjVk/DDMWH88OcO8JZ8UFnOFdtb3di0YzcMWBWaiLh8Qv1jrKqkFTP1t3GFb7zC5VeLIjR34MTKFJnY408Az9TGjiOw3eho5UZcW0QjPqHApQ2m7zRYngG4OpRIcYKkHzIUFqRiSRLCDPG7BJbehkJrObKgRmaD/CMKbo30GVGUQkvOmgkgrmswhxjqPQaU0JEysc1ajFjwNTq3livDKCGVgSgoqNG7ohpY80ooq5xqAGLVuAYi9VtEZPAd+KnQx 8+ijv0S5 TeQO/Ejm4a+G94D+kXnBu0quKfnLWSpDmGIbb80KyqorkTUYbev2Lwp7G4mR1INwu5hh2ByK+c41BHNf67zuTIR7SFQD9TklTQxbWqvm7TDn8ajAjsirooew3o/IaTerFmFobVs5YSMreCHVNpz7ii7/PC6r16aET0Zs1Gb+cn3VGOJhK1JymvPbGNnO+G99bVBhL5LaaLsVijM83n+SKfkBHj3S4UVx4jimAULyNKL96ExweCa6PqZGUMyjOPMkdR+Y3pv1xpxKlOmppaE5YnvgSI71s3VRDgwnq5fnbejW8pYktVUNt1IAXwfP34QKOrXEXnTpgIMYj3DswqFxXU+bst2e6duUSJDRBRoXPvNorPsHYsfwFL4tVXLkx14iB2SncWrhzzWHvXBrlQ/aNUC2x6V0WK15skomeSJdCUkP5cUMBk/D2PFPjVQS4GUEAv4kb8B84yYbwNaE= 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: shmem_writepage() sets up variables typically used *after* a possible huge page split. However even if that does happen the address space mapping should not change. So it should be safe to set that from the beginning. The folio should always be locked from the start as well. It however was not clear if the folio address can / should change, as well as the first inode. This commit makes no functional changes other a double check on the folio locking which might be superflous. This change should help make the subsequent patch easier to review. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 28f3c699c8ce..a2c6aa11aab8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1332,11 +1332,13 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) { struct folio *folio = page_folio(page); struct shmem_inode_info *info; - struct address_space *mapping; - struct inode *inode; + struct address_space *mapping = folio->mapping; + struct inode *inode = mapping->host; swp_entry_t swap; pgoff_t index; + BUG_ON(!folio_test_locked(folio)); + /* * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, @@ -1351,8 +1353,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) folio_clear_dirty(folio); } + /* Can the folio or first inode change on after a split? */ BUG_ON(!folio_test_locked(folio)); - mapping = folio->mapping; index = folio->index; inode = mapping->host; info = SHMEM_I(inode); 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/QQz5Br2tibjiU8M0FqVb9sdkAPDQeKnIdE44T4PqAqcYXsjSlZlPnQQgTyHevH40utPZJbUdegRs8igLy+c4LMBeTTD1RlBQOwEwpBK0eidkjEmjbVGi7+O16qt1qE3z/C3jWGqlQQsMu0P+EBxQne+JDmNpFzUngI/lPBycdTHnwa1sC27Pe5DVKGsCLeeM/adgOJGGdAL7UUT5g55MfcmxYuhOpxsNS+meMGAefnFnKEtsi50Cu6NEUYq01ONPwWaXExzneOZ/xabsHjlh5ttfdR3+ubmM+irAzBMP9zPYbjLlhmwMIV9iRVuZBY4JMFaLfKnnnBSf5gC4DbLiK+7m+h0JqQXgVmCAV8HFfnMcKP28wMv+H+f/i7goLLmPMmYdp2sCq8Nw+ojPJhzXFNGYYdahbn4YWpqMbOq2eLZi3JOtU+XtBgdIq4iqFCv4kCTFIXr7+9aKzAbRgHWrtqr7mWCaT/IxmYRvzRQbJLSiYwqGiKhdMfUckSvwgILq36M7KYH9fXzV32l+RZf5cHUlBlBkwKuF0oC8EdBr0P9Msqo74iZoEjDpdcjeSZP5zcBfapaUTiCyqt22wGhQe5zUlusn6VY//xf6Osn6tDQEK/Y0w6SqYMMwmPStsm4OmHGuUjKhxHeeC3iDeid8POVEiCX0RIHa2RDdOzEUX65QZRlIBfOWtEGoCVZYNDHGAl/3gxTLtc8gamcHXnmF/LL90fUJoNrhtR5jB7/CgPl8p62jjDVZbNjNap0XCJlf9RVri910IPYGGvsad l8+S7SxH dSr9CvHpHK7iSZpx0HFeNIO73Sig8t+Q+NeFggPIWr6qt92DOPpRcmmVnJrtRpPbUhYIZub3KSb6dcDzMFDZeSMo4a2Oy5XGG4wabm+28keOW8MFWs0H01GbyZ0nahzNyClcrqPWthzs7XIo0DNSb6sPY91FzzeaArG96shQkFg5qohAJIID2f13oH3PojZjwe7gZduYztIa0cR7uUN+KW+VSHCpCVLvjscwEzgu8cok108wo2JX1JBLU8FYKqb2YUB0XKn+LYGCyrS46xAPCNMgwHS497PgBBkPuOD+gfa0D+hx9hPHg1IA9svpggZJElUJUyZN3Rz+rEXvx/BTLrfljhKNHKQoUkyhsPou1ijDxObNxrdgLGR4zSnM/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; }