From patchwork Thu Feb 23 02:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13149793 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 07C47C64EC7 for ; Thu, 23 Feb 2023 02:44:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E73406B007E; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E26CC6B007D; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C54796B0083; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AA9096B007E for ; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8DD291A0AD6 for ; Thu, 23 Feb 2023 02:44:22 +0000 (UTC) X-FDA: 80497012764.04.420AA6D Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id 6DC7810000B for ; Thu, 23 Feb 2023 02:44:19 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WPU7CMVf; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf14.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677120260; 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=krGz8JNPEfUKWYOBIr5M4Mxvx6mftCSbjb3cTtYDfCE=; b=XTEzuejpaSfn6rYTEq9xHjtnI5kIT6eLS3AbBjM1lLYRn3yufiAOLoNKSH/maHYyni4RsI LSw8WxwUhsIkdnR1tVTLW+qiqZlBvNU6srFcvDRcy12xl1NxAWfE8eqSJRhcJF34L3RHiU EUfaxmQw2/nGm5ZJ0WwvuJ3ykcXWZRo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WPU7CMVf; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf14.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677120260; a=rsa-sha256; cv=none; b=kxPLYjxu18YI1KBksu04dL+kiizDPlh/UOnTOZ2B9RjCa2U7i6mAO6vnAl6VJgndMceQh+ H9vvqCqllWs1mvD6sif+efwSb2GMiFdWZFJLUb0oFY6r3bSWR5WIGfWThwyw5NNhtqnPNu YBFaGj3puk8bDNpsH4txKtiPz0p4e00= 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=krGz8JNPEfUKWYOBIr5M4Mxvx6mftCSbjb3cTtYDfCE=; b=WPU7CMVf2DgW2/TSJHS9J0wBbm 7uuRWz2+zFq+EasHiqr1iOkkS9NL5LWxlcCD3ssYHfVxIZqQ+gtxv8xIAdydY8zeX2XXxPd32DMrA xH98Va7Idt0dDo+kqQgqTYTrqEJ2RAZYXxd257F82UMExgv3lmhVcPSPPsWAeKfauFFTA3TPeq+Di Uq9O1gx1dLSp7+uLiQvB2zJWZIz0xjOpuHO5MScdavofEmCokIJtKYMbj90wP8/izrEAVUewGnRZo UUKkZ2ofyPO4lPHlNe3XteK6m8dKpiwygeke619PsuduCvAAoLvnnP9ZRzHoaSHqgmML7d+uGrreJ IZ2d8kFg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV1ah-00EmN8-6C; Thu, 23 Feb 2023 02:44:15 +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, yosryahmed@google.com, mcgrof@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 1/5] shmem: remove check for folio lock on writepage() Date: Wed, 22 Feb 2023 18:44:08 -0800 Message-Id: <20230223024412.3522465-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230223024412.3522465-1-mcgrof@kernel.org> References: <20230223024412.3522465-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6DC7810000B X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 3389kaxzotfsn3qdyepcxsf3r1q5szd4 X-HE-Tag: 1677120259-484463 X-HE-Meta: U2FsdGVkX19Xz+TJYfyJXGxGbhihrmV8iLHo6Dya3WgNX1Tc5cHXLPjqR9XC8uXHH8mVQHPfgtwVyKdw5e8OFXy2dl4KyMHQHT3gcXPr8c6Ul9z2jmztL/A9XBX0Sc4AmxEZ/NoYJcMuJ9WTEFv015B5laaQFJ6/hyPkTLWF9OzdHFaVY9YI//Z+3sHkjwDj2PDGGtCgVaT8ZZ0rX68jk2H4sckDY0quKgoNuLmFODbxJpm1U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Bz/0jhaxCIj5m86DeVrFmtBVPvmfZK/3QPvTbNzHiDzVIeMua6jfCZL/kUTE+/iP4u0a80h4gejDZuBhrXWS9OXQ2Qa9DnTnsqyseCo2sfKS/P3CeJn3PLFO+nDJTCEs6QPIomidiyLDeDfLQEt7DW73y 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: Matthew notes we should not need to check the folio lock on the writepage() callback so remove it. This sanity check has been lingering since linux-history days. We remove this as we tidy up the writepage() callback to make things a bit clearer. Suggested-by: Matthew Wilcox Signed-off-by: Luis Chamberlain --- mm/shmem.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 28f3c699c8ce..b3ad619328bf 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1351,7 +1351,6 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) folio_clear_dirty(folio); } - BUG_ON(!folio_test_locked(folio)); mapping = folio->mapping; index = folio->index; inode = mapping->host; From patchwork Thu Feb 23 02:44:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13149790 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 1E707C64EC7 for ; Thu, 23 Feb 2023 02:44:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 172F56B0075; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 000A76B007D; Wed, 22 Feb 2023 21:44:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEEC86B0078; Wed, 22 Feb 2023 21:44:21 -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 B78ED6B0075 for ; Wed, 22 Feb 2023 21:44:21 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8D7C4160EC6 for ; Thu, 23 Feb 2023 02:44:21 +0000 (UTC) X-FDA: 80497012722.03.609A782 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id 65D77180002 for ; Thu, 23 Feb 2023 02:44:19 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=K56am7J4; spf=none (imf16.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=1677120260; a=rsa-sha256; cv=none; b=1/REeSp6dEnAIe+8y1hfVTbQPSIIr7nCGcIPaNBlV022EHDcrVg6NLpV40rvDg0X0og8KG Q6Ce5TkC89KOM6JrYJVESluKHsEYfsCVUwPaQqSpnnwfGHudefY8lFegbOoTqcVWfS8/DO vnMiRFNZxVnxJvstyfcMj9OTiyuz5+E= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=K56am7J4; spf=none (imf16.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=1677120260; 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=Zf/VP5ikCHj8OLL6rer4hxqpVXK1ALaeitWH3YJJWGw=; b=6UhmnUHOMf/J4TXpyQQF0EtNIuerKIJGJm9dZazD88vDe0Izj3S7V0c2eiSe3jBLN6hNcS RAds2QzikL9BkCZUuy75P5vizhwnZnXzamViCAaNQknvHt6GECis2aqd50csJdjRZgRZtc gOJ+aRnSZIIOCsCuG9M4tswonU9u+gY= 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=Zf/VP5ikCHj8OLL6rer4hxqpVXK1ALaeitWH3YJJWGw=; b=K56am7J4RdGNuU6o8W0jdqS0ki klpCVr4uB8PIfFhNoUaw6mxyic+kMZCAItqPxG3BiXoGQRqZaOocgPrH8mWw6CjcKST0X8JSSiCeA QpOTOeoXX9qjWWrb0lLLZffp5U5PkWf0kMvODDM27SmUhugLUSV5VWCWJf97zZ+rLq0Ow8isJpKAD TMwO2rPqOxnEnU+FpRlGvZZwYXSjTdYixOT0+ynh1x0slK5e1rlLbrccAEbpoTtEnfYzvg4bZcNGx D9TolFbzyTqguOlMSvw5Qzrs2hGcv8k/0Y2R3MBKDoLHYT3zuIuEb9r6VtYKNR7qareuSz5A8lT/9 XlQqeXew==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV1ah-00EmNA-7d; Thu, 23 Feb 2023 02:44:15 +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, yosryahmed@google.com, mcgrof@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 2/5] shmem: set shmem_writepage() variables early Date: Wed, 22 Feb 2023 18:44:09 -0800 Message-Id: <20230223024412.3522465-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230223024412.3522465-1-mcgrof@kernel.org> References: <20230223024412.3522465-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 65D77180002 X-Rspamd-Server: rspam01 X-Stat-Signature: niw71h9aaus64xi7c877thek4ih798qe X-HE-Tag: 1677120259-21186 X-HE-Meta: U2FsdGVkX1832ok5TjpX0EvlQQigKBIK8sUzEIQLBk5xp3uvqbudBMJ57RsZHqjJ6lmo33tf2JEp9ob4SGpszAFc3O1fCRHmJ6T0ZDHVqHQHjSkaV0yHfelaXfEH5VE299GogJgOIGZTF5NNUNz7sAx/6dva4L+5VmPDHAlF8lbJx38C5AD8Dk0cHbgQIAYemGye5uiM5Stdn4FNiQrNGECvq0ZG3bzYrsTqD8lZqVmdAe7w0KyyCTQ7auU28pnogCHm53yu0dD5ruMyzZYVu3YL+uard4pemX7oku0D2aFi1H5SpsHPdJSQsIpFNtkEOvcqVq9WW8hScGipI4eQ0/3VjxNCm4b6BcvGmonwUIhSScPx8OA5JCKvZuusUrdAMqPGzyMTxr4Hu5/JWBMhMSrllUQg4DXy1gbr7PncHoWDQ5jSL2cwCz0SExZEq+wRPPnZBXZCNchZl8MGkul+9OQzZYFOI/qQN60XkHAqQXI/KNm/0nbrfSxlB4XbA13RpqE7/udVwhVpN3GWIbZli6AgSwe8eGXzHDKlbSLdLrmW8mgmDwN1+RNVKSOfxLxeUAJjuUaoIO5ZXZrOqWm5ojWYrwWXwLrUFPW1sRB/zV5pGrtm+G6/1WDxYzk/dLtq0/GAMnu6WmHXzE7Ns4/Di1ZJShPsKB1Ne1C+aea2XRMndSiJ7cRJteJDYIfrUJXpax/J9m9iKkFGqEKo6Nj/fUTMV+8D1WpEjHCmPb77FYYMljx0bvwoaTcnI4I5qtkix5Q6yJAoYE+FfzuvVibaSdXDanmfXVYAyKEiqsE0ofaVMvF5wyugl7TEbwA1rjcdDHdii6R19hsXC3N4GHXe54hhD/gQEsZgPPHbTri+yhYJYdhL70rPnDsh7IoOgBUvut047gr6VTGHhCw9aue4d+5z4mzc7jlHH77caeFkMbexhZ7CNIR9LqhhmXnEJvl2x/i64y7DyXp+yY2ru7t QYo1M7XP CjSeWaujpQnCKl4Azey3GA2wh6VfxqyWDBYVXd+BK2ezjiC/fkHuuQnLblc13stEpOyfLPmjsJsD807+MzWmC1qdSZ/rhNveM6Mn2I14MHTpP9DYeGT0WQT/j7Xvmu8ALYo/Fwdaj0G/OcIJkR92wBw0C1Vze+oOahuG/VSbAGvwBIL05xbIswHwguTtj09s7evWyu1n6pwe9JnP6n0Og0ch7BoWCNGX17CNReg9j4OGLJfyNmKeoIPEw4Gb6B8z6xk/SNfKW1fLHuYYB4yw+UMGMDFwxBTvZ6oc1b1ijHxIPY7xFxV+RuDfhmRo/YkR8+1D9UfPdS5QVR6YkneaRDoY/ab6KFIhuFjt5taZb04i5pXJcdSDkReDVrUhDwY4ytOiFi0/5UTUD39ZyO+Q4RK6/0cssjFp7QDnYQpMxkvoHwq5K8Gt2O4B6Hw56stpsiDVwAxgA1UycpYw= 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, and the inode does not change either. So it should be safe to set that from the very beginning. This commit makes no functional changes. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b3ad619328bf..1269482d0a5c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1331,9 +1331,9 @@ int shmem_unuse(unsigned int type) 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; + struct shmem_inode_info *info = SHMEM_I(inode); swp_entry_t swap; pgoff_t index; @@ -1351,10 +1351,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) folio_clear_dirty(folio); } - mapping = folio->mapping; index = folio->index; - inode = mapping->host; - info = SHMEM_I(inode); if (info->flags & VM_LOCKED) goto redirty; if (!total_swap_pages) From patchwork Thu Feb 23 02:44:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13149791 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 AFD74C64ED6 for ; Thu, 23 Feb 2023 02:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 503486B0074; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4428A6B007E; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E74366B0074; Wed, 22 Feb 2023 21:44:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C72376B0074 for ; Wed, 22 Feb 2023 21:44:21 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9316DA0950 for ; Thu, 23 Feb 2023 02:44:21 +0000 (UTC) X-FDA: 80497012722.02.E0F6423 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id ADB8A20009 for ; Thu, 23 Feb 2023 02:44:19 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=nobDFyPW; spf=none (imf13.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=1677120260; a=rsa-sha256; cv=none; b=u49OskFTIfJsKM6xGB9QgPU6r3m8xg6yH0BcPnye/Iu00MMA7XapCMe+TGmPHIaEyCtHe3 96SLETFzwtOciBLaxYxYog3hNjELk8sdU9FMR5jkUmLquez1uYXYLCqHJdzroKD/SAhacg 2ZtmXuOLKrjzs1B8wSnckWTVEjZoGEQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=nobDFyPW; spf=none (imf13.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=1677120260; 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=vQjHgoe5Jm+n0b1ADMVciA5nvYNCQKcIEIUc76XY5yA=; b=dWyL2k16i0VN5ObJytCyBhaLTpdCHpEUV8JAoCsASBz8Xzd7Amz69SLy8CkQ0w2u90KsF/ l/Mcq+zd9Irz5DXFGXvDMdX99CiuJo57oo/YQqpc1F/I/s1FMbPRdQIvGS+naYowTHV5Q/ nHj7E0E8+kb7KU+1F7BB1UT4KsFQc34= 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=vQjHgoe5Jm+n0b1ADMVciA5nvYNCQKcIEIUc76XY5yA=; b=nobDFyPW1FDWru83lnPC9EwGl6 R/FHdKwibKNjX3q9wvjpliuLql+NoQ9c0rhOKA0yrjL0c2fVAZ8p5RDkCW6T/uLryGWU6LLvIkYK3 H8ZiDSzxHfM1HiVyVJJIIX+A6Fs2dWqSFF4Mm8kGPxhMBXeV+81ZHgNBeGyY6UUKuDDPhMnjqGLO5 TABWOhP+CZw4oNP8VfJdPVbrNk70Mb5neyvgQ6W/IecffA3e/SrfwO1okz2f1jrhReSmm+2oITWqW LBsLcoG8bQlb1BH852kJkU4dTTBSJiFZIiW9Bx4gy3pLT+qeSzmlOw0EHq2ID8LlnX29yOscwqVJd SxirXIAw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV1ah-00EmNC-8r; Thu, 23 Feb 2023 02:44:15 +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, yosryahmed@google.com, mcgrof@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 3/5] shmem: move reclaim check early on writepages() Date: Wed, 22 Feb 2023 18:44:10 -0800 Message-Id: <20230223024412.3522465-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230223024412.3522465-1-mcgrof@kernel.org> References: <20230223024412.3522465-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: ADB8A20009 X-Rspamd-Server: rspam01 X-Stat-Signature: euz3sa4yx7ynr3hjp5taab37xkqjhxzp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X92CSKOVWeDh6aBfaSBa3ae+Q+YdccCgnfAHuTF2Gew4f4DgOfefYReFm0hI690rPXLzeiTLdjhTbBsmNhzBZWgHVJBKr46eoL70c4x1EpPhgEPZMvQws1iLDYTCEV5XfEJxZ4UqKuBFrc2mHvulxGjfVHPE7ELaikrHjmzgh6oqovWuVtBSBKKSTvFRPfgfsE8r3weSEn3D85sEKjFj+jb4aR3JC+PIvNDpQE6NW/Pm6kmDQn1aWTHspr4EcgWgLnqwVEqsMI4Iikj91jJALc0juV+fBM2+h//2SQ9c6BQYpIn37Ltydhrf/wntdwFZKQ9ALVUqlbU1iBSjFQgGY5RAyyGjJYA4nqDy7d/XUTMK8 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: i915_gem requires huge folios to be split when swapping. However we have check for usage of writepages() to ensure it used only for swap purposes later. Avoid the splits if we're not being called for reclaim, even if they should in theory not happen. This makes the conditions easier to follow on shem_writepage(). Signed-off-by: Luis Chamberlain --- mm/shmem.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 1269482d0a5c..626eb1a0856c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1337,6 +1337,18 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) swp_entry_t swap; pgoff_t index; + /* + * Our capabilities prevent regular writeback or sync from ever calling + * shmem_writepage; but a stacking filesystem might use ->writepage of + * its underlying filesystem, in which case tmpfs should write out to + * swap only in response to memory pressure, and not for the writeback + * threads or sync. + */ + if (!wbc->for_reclaim) { + WARN_ON_ONCE(1); /* Still happens? Tell us about it! */ + goto redirty; + } + /* * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, @@ -1357,18 +1369,6 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (!total_swap_pages) goto redirty; - /* - * Our capabilities prevent regular writeback or sync from ever calling - * shmem_writepage; but a stacking filesystem might use ->writepage of - * its underlying filesystem, in which case tmpfs should write out to - * swap only in response to memory pressure, and not for the writeback - * threads or sync. - */ - if (!wbc->for_reclaim) { - WARN_ON_ONCE(1); /* Still happens? Tell us about it! */ - goto redirty; - } - /* * This is somewhat ridiculous, but without plumbing a SWAP_MAP_FALLOC * value into swapfile.c, the only way we can correctly account for a From patchwork Thu Feb 23 02:44:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13149792 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 8ACB6C636D6 for ; Thu, 23 Feb 2023 02:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0A396B0078; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 993596B007D; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 832996B007E; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6104D6B0078 for ; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 35C501A0AD6 for ; Thu, 23 Feb 2023 02:44:22 +0000 (UTC) X-FDA: 80497012764.01.18F4001 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id 53BE340014 for ; Thu, 23 Feb 2023 02:44:19 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=sn2iEaZx; spf=none (imf12.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=1677120259; 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=kiZfMZIUImYTT26kimjDxbkl+uiLHr4foE9jVeUonNw=; b=B4v5Hp2x716iEgGXjVlsIug2EdrcmiqV5uo4F5zL3RijGbnCFMq2Xsbjm2hmokSbe+abQI pCY6RYKm0T8PGqzHo2MC10M5KWDNSbjqtYjQcNp0mAwrA1Udn6+9aIDCRN+d9DICBpOtNs kA7fkL4JlUBSKhOH85Zq5X+PBJhwifs= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=sn2iEaZx; spf=none (imf12.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=1677120259; a=rsa-sha256; cv=none; b=nNAgo6VdxvT/d8E44lgWMajYgP1irsu6kvPeS1b3mdy4jUXSA7OYo2I1Fs4Qfy9N3ShSTr w8Mt+h4dVpMeLOxbMp3px8CYWzjsQ7VxGzBAMAXEk5/bYHI/+4xjYkGtvEDABr9tCpiYk9 SOBhZSbzM4OB4AE/qXVVEiQATBC9tNk= 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=kiZfMZIUImYTT26kimjDxbkl+uiLHr4foE9jVeUonNw=; b=sn2iEaZxSxcZjr+lLEI+B9ZNfD ag2rd1ZA2IdkPMeYOuIbwUEge8ajYxG0X3vo+WuNHeE+62APWJEO/TQ+BEwvXPPTKO08otnIXs5Yn H5l53U6iDGmiMIOfWkieSJ1WN0Q/joKc8yr4grfgcI+SPDH7VlzINQV7egc10DDUTWILqPocCSj1o XDf9ihIRyG8DyPLMC9rit2JBlfpauaPYiOzpZfEAHTt+yslONZY1xDy5BC4wiV6lsokBvqZVjPYU9 M/s2WFxV74jDhTSMO3eHfu513os/QCbn/WTrt9tXhV/ao06RvY6cmntgbABP0/E6sLUKQ8wKo25Fz rCFNadYA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV1ah-00EmNE-A6; Thu, 23 Feb 2023 02:44:15 +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, yosryahmed@google.com, mcgrof@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 4/5] shmem: skip page split if we're not reclaiming Date: Wed, 22 Feb 2023 18:44:11 -0800 Message-Id: <20230223024412.3522465-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230223024412.3522465-1-mcgrof@kernel.org> References: <20230223024412.3522465-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: puc636ju4t9ygncz5m1utt3yyjdajq99 X-Rspamd-Queue-Id: 53BE340014 X-HE-Tag: 1677120259-288124 X-HE-Meta: U2Fsd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647kUGY0/gvSIVLR/7vUHjC/y37mqymEuB6Sw3NkmobimPBdUFTZFg1r8kDRcvyOFga0xDJFApT4yki4IlVZh+qhzD/QRO1DgrqtRczIErRG2OG2JVH6G2LWeu4pwFYXFz3PSCicRpTgocVyKVfDviAV/XbY+Dh+3eN4te7zP6A61w5ba+Gy/KS6+zPV78MRGFXnUriSIgFG/jZJX3X+rgfJe2rps8wFGk9XQOwCj5Cz4UMIlTs484iwwfZY1h3ZI9elJSjGoE45a3eqbu+/72lsQCMUgLbEQvMLuC0XiFrsfeXYQURtMchMp0+beIM0m8IDbILHfGQ8cUt92RfN08 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 theory when info->flags & VM_LOCKED we should not be getting shem_writepage() called so we should be verifying this with a WARN_ON_ONCE(). Since we should not be swapping then best to ensure we also don't do the folio split earlier too. So just move the check early to avoid folio splits in case its a dubious call. We also have a similar early bail when !total_swap_pages so just move that earlier to avoid the possible folio split in the same situation. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 626eb1a0856c..a49b31d38627 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1349,6 +1349,12 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) goto redirty; } + if (WARN_ON_ONCE(info->flags & VM_LOCKED)) + goto redirty; + + if (!total_swap_pages) + goto redirty; + /* * If /sys/kernel/mm/transparent_hugepage/shmem_enabled is "always" or * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, @@ -1364,10 +1370,6 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) } index = folio->index; - if (info->flags & VM_LOCKED) - goto redirty; - if (!total_swap_pages) - goto redirty; /* * This is somewhat ridiculous, but without plumbing a SWAP_MAP_FALLOC From patchwork Thu Feb 23 02:44:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13149794 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 975BFC61DA4 for ; Thu, 23 Feb 2023 02:44:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CD0B6B007D; Wed, 22 Feb 2023 21:44:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 154136B0083; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDA106B0080; Wed, 22 Feb 2023 21:44:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BE9716B0082 for ; Wed, 22 Feb 2023 21:44:22 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 92F0A160AF2 for ; Thu, 23 Feb 2023 02:44:22 +0000 (UTC) X-FDA: 80497012764.09.CBD2C62 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 5F16140004 for ; Thu, 23 Feb 2023 02:44:19 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=TrDfJdxV; 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=1677120260; 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=wt4p/r9ymCcnGEqY87sHknk0U2eY7wcxJejPwvb0Ylo=; b=eAHtXTKM66+qa5brjDhfnQvG6Pep1a/jgAFSj1YYdbxw4eMKhA7k9QYSA4fPJO5yRnB3Fh sBk1hkgTrzaRbgulVg98cGo8ANsOp4FvsW61V3k6MSJYGAmrVMagPoABIAdrK8pmC43RM4 i71jxqLvunjPUew0zZVVOQ2GlctKp0E= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=TrDfJdxV; 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=1677120260; a=rsa-sha256; cv=none; b=Sy44Ze1YO5sM6EBY0FpZtj2+TyqkA79EqnMBqBlVMuWc3Hp6qRI4acE9NZRUjqo9yaOkxT sJnRGz/ttC+Bisqwkz+6IqJBNrEepGlIvMhjvuV/Tbor5bfAE0ltGmb9aPrwPFY0t7TD3H N7f1qIHOrWSC5JZYGdTYECl5jkstD+U= 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=wt4p/r9ymCcnGEqY87sHknk0U2eY7wcxJejPwvb0Ylo=; b=TrDfJdxVZcws00Hj9FGWVMTTCL LfcxodfOiVzFwmzhWMsfva7J5bIJGP2E7QgIGmqqfo0DOX04NoMNtbtNomLSuHaXzr0rQJ8uBJCPI llX7IWzs7lCHCrQRtkGRVdkzf6Wj9qUR7dRDXpKE8czsLpuellL8pHfWdJLVatBbwk7uRCU3k8RLP tH5N9MsQXVK3OPjAO672R0qfraGFGCGc5hq8V5GARE9bDCNt5yr0aFIUrtNVR8Txu6e8QOcsB1HBw OOyzrDPA419O0WyksHMacOMnEMt9/aWoLIr4DUUWS29M99FQ9baEFP4R0ZkbDchM4BVFJH0OqqpIR 7yC1G3EA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pV1ah-00EmNH-BN; Thu, 23 Feb 2023 02:44:15 +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, yosryahmed@google.com, mcgrof@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC v2 5/5] shmem: add support to ignore swap Date: Wed, 22 Feb 2023 18:44:12 -0800 Message-Id: <20230223024412.3522465-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230223024412.3522465-1-mcgrof@kernel.org> References: <20230223024412.3522465-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5F16140004 X-Rspam-User: X-Stat-Signature: s4wasx8ubk6i77ib5p1h4fhgne55qb81 X-HE-Tag: 1677120259-503785 X-HE-Meta: U2FsdGVkX1/Y9E/7F8aPoBqMUPk8SQP0GA/e06XgPw2PWLFktj8+zDUszMB/3w7c2CCMnOrKAs3+kzIJ42YRy5VwLDe+NjZGp4S9AZnZ9bXUrMFunc7pUGqq+j9dBTqgHon6FsajEiNwD8S+LU/ohnterHSq6ySev0iWH6LYlMrUJKQJX3QOYL4FtM3ZXoXEmf3oCX7wpwzlm9BaGwt4K7PRFU/1lzpaOmlriLsFxgd2OgIhrkCM0w1cC//PAAewMj28ymBbMODp6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AnNSk1rLadOlZ0JAlz+tiJ8HNvIl/tbis/quk38tNXoJBaAMxY06YvvZnPnVux5z 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 swap 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. To avoid swap we use mapping_set_unevictable() upon inode creation, and put a WARN_ON_ONCE() stop-gap on writepages() for reclaim. Signed-off-by: Luis Chamberlain Acked-by: Christian Brauner --- Documentation/mm/unevictable-lru.rst | 2 ++ include/linux/shmem_fs.h | 1 + mm/shmem.c | 26 +++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Documentation/mm/unevictable-lru.rst b/Documentation/mm/unevictable-lru.rst index 53e59433497a..d7e11f492289 100644 --- a/Documentation/mm/unevictable-lru.rst +++ b/Documentation/mm/unevictable-lru.rst @@ -44,6 +44,8 @@ The unevictable list addresses the following classes of unevictable pages: * Those owned by ramfs. + * Those owned by tmpfs with the noswap option. + * Those mapped into SHM_LOCK'd shared memory regions. * Those mapped into VM_LOCKED [mlock()ed] VMAs. 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 a49b31d38627..d2f34147fc66 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,6 +1336,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) struct address_space *mapping = folio->mapping; struct inode *inode = mapping->host; struct shmem_inode_info *info = SHMEM_I(inode); + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); swp_entry_t swap; pgoff_t index; @@ -1349,7 +1352,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) goto redirty; } - if (WARN_ON_ONCE(info->flags & VM_LOCKED)) + if (WARN_ON_ONCE((info->flags & VM_LOCKED) || sbinfo->noswap)) goto redirty; if (!total_swap_pages) @@ -2374,6 +2377,8 @@ static struct inode *shmem_get_inode(struct mnt_idmap *idmap, struct super_block shmem_set_inode_flags(inode, info->fsflags); INIT_LIST_HEAD(&info->shrinklist); INIT_LIST_HEAD(&info->swaplist); + if (sbinfo->noswap) + mapping_set_unevictable(inode->i_mapping); simple_xattrs_init(&info->xattrs); cache_no_acl(inode); mapping_set_large_folios(inode->i_mapping); @@ -3461,6 +3466,7 @@ enum shmem_param { Opt_uid, Opt_inode32, Opt_inode64, + Opt_noswap, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -3482,6 +3488,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), {} }; @@ -3565,6 +3572,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; @@ -3663,6 +3674,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; @@ -3683,6 +3702,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; @@ -3780,6 +3803,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; }