From patchwork Thu Mar 9 23:05:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13168529 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 642EEC61DA4 for ; Thu, 9 Mar 2023 23:06:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C0A3280007; Thu, 9 Mar 2023 18:06:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 67068280006; Thu, 9 Mar 2023 18:06:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55F25280007; Thu, 9 Mar 2023 18:06:00 -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 48D7B280006 for ; Thu, 9 Mar 2023 18:06:00 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1337A1205FA for ; Thu, 9 Mar 2023 23:06:00 +0000 (UTC) X-FDA: 80550894480.22.2231BD2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 701FA1C0017 for ; Thu, 9 Mar 2023 23:05:58 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3S7FD3TX; spf=none (imf18.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=1678403158; 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=H478EBfRc8YOP2keWn4dK4BIB7gGzmccWr6qJ1Nxgx8=; b=agJf9++92Srqwq7AalHFk0cHPJZMG7qBrFG4fym3Uc8LeRwwwjHP6ZFF88hhhjZy4Y0ILS TBR7VCnyBa33Pkt9ye6tIprcMhT4SWrUCrxuYXUudSs+UZMnTJaJBK7GcXm4ikqc8pvqBo eVtuk0CR1dmf9gWD2T706HibKUVD0/0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3S7FD3TX; spf=none (imf18.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=1678403158; a=rsa-sha256; cv=none; b=iYmrBIpxsCzwP0HXD1dk8z6OpZ7+g6bGrWUiwcKMmnxJCYKTWrtuFrnf/ffrbxE8avNVqo QcuBsimgr5ErUvuNEZnib0lEAtEWCzq7p5JSRoy0LVflOWiEoBpCb4czHiDC3tiF3HwJMO FtA1ngDm9vffkEJ2Qh8HyMrPSR1M3sE= 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=H478EBfRc8YOP2keWn4dK4BIB7gGzmccWr6qJ1Nxgx8=; b=3S7FD3TXf9UwH4vZnN664p7upk YngkEO7ZO7iHs5EUB/KYcNJUo/BBNpSQIKzIX2veruPnCMScaqst8M6NFr920RF+Ka8GmIiv23fXF e+foHWC2ZT4xOTXoeG61Ldgxwl1krdl21xo/MYEYnmV491LOq4xx+g2ILjTCD4JWvm+gt/0lL8SzB 7Bm9YAxy2MY4dP5fTR9VKWl1wIcNDc+iMCjK0hDYqtGPmSX4QavVkCiT3qr4JIHo/0u50GiK8JKGd LgqymKO7cQtlBE5EemwB6Nd2OqE+Og8haRrr/W8LciuaFC6uSXoTtZsSZUNijvsMRv9frTHiLnack 9cLWBkwg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1paPKW-00CIRO-3B; Thu, 09 Mar 2023 23:05:48 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, David Hildenbrand Subject: [PATCH v2 1/6] shmem: remove check for folio lock on writepage() Date: Thu, 9 Mar 2023 15:05:40 -0800 Message-Id: <20230309230545.2930737-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230309230545.2930737-1-mcgrof@kernel.org> References: <20230309230545.2930737-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 701FA1C0017 X-Rspam-User: X-Stat-Signature: mxi47reywif149uwq14fxk5xk49d9e9z X-HE-Tag: 1678403158-722245 X-HE-Meta: U2FsdGVkX1/Yqt1fiiAbExh78CxQsBjwU683evjC2W+ARBnLpbwSZbFEdQnapzg9fo0/syKh0TCMjp5hcdoCFgnQKlMBYujdNjkzniA+K+oTPt2E6PdxQ5IeHLfq2XbX6GQYjw9hQXYGODxNgDtRGlfve9aQGjx0kJfOmzUF0zBJ+bVJQBVN/Hc7FD35G6X0KwoazwNafqnbkR/oqwEM1eQgUWcJ0DTnarzQf7hTkt8Wck846q9Pxspowd8Jlzm/fyP2DHnqPNe/+QJU+5KQR+Mi5B4e5WDi2FJJs80DE4+dVBZ4EZybVn5Ybfa6eqWI0AfoxGXEB/93XYv/8JC3lhPXt15a42ThME5lSqxZRxbbAyWtOb/z9g9n9M2/Wddn/sxHv9RZSLg6DK9p1TgAEa2jkyJl+ktQXYJCadVIxJq5X3jpxHyQakq0sbaPD7LrJ8hQiCS9LBOCM6FvpZ+W0xD3Q5zc0tsfWamGMEKrnhLmbvGhkf1AMajptlrts0NW+2M05Y1n8zV7V2piKocNmhe3PhcF7I/U1p84/zSDIujq1nRllQ8K4LhWvcJw3DRt8+zrK+QviNJwVJIbYLQ0ReiSE9yAT3d+/wvkqbx422fVKSOmSsltmSTrfGR6fb/3QD3BiKiwdIdKPX9WFFlpVfsVAP5JWZIPRDQTBQimjGUarJ1QZFI5UvjlL5JyXlU2ufMMi5P5NLTIomSBGJMVkw2Lwtq8c1Bm444kWmoqAsIjbz/4sm0r7LxwEyM/gcIQv/PahZ5mSj2dWCDMu4xzPTjuSiVnCAhT3K+XZgrdMkdcvcQ0WZ5n34u7AizRcnBnD7Tv8I05mNp2XP28Ch12+Zp1ZoxHzJUYaJvJxH8HilN3zvsmOVb3ApWzEIZv9pCGPy2qVaN/pUNtklTAF2EMQmfjWN4OFGcIMo4vizXubLtf/2ZDjM45vSKTMNw6XcoCzrw5h+24maozK054ZBY Kgx3kU5D ueV8y/Qtdr5Iqm7Pz+mPu9gWfWnTXw/Mwx4orxvf2s7CAAfFj7T9m1jyvgAukBwcXiAuLNLWivKDX1QqW6knAOQVQE79qqguzwK8U0PdikhCGtw1LdggpDS7ZY+P1y0RoXt2a9Z3gT/QJvG18X/YZuTsFaNOGxKOb414VxI84TUohJMHSjV24KsgtObYFwOVn4Iza6xItZFTl4fJHpGnQHi/5hbPa+8YBhoSrQUg69TcXZboj6ojfMmvpj+kf7VC1E0wk+BFsA9wouZiDI8S7uLFvkWYEfj1+1q3KTKoOfL7J+mLJlJCUKnEAC31J6Ru+/J33HIdxGgQ6MhXS5azRIvzwlhXMNuUf858jUIatpw18jRy8RkmGE82rVGmsFshhMomnkemObZkza3dvZTJU6Qf3W5HEp9DHCO5NiqRH3+SD+kC6UDRSJwb+rHG69Bvf8EFMJBp8guAF3DuL0rcsulHTe8/b6EfCmFo6mrBSKsX5Kx4oE8z4KH+BKQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, 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 Acked-by: David Hildenbrand Reviewed-by: Christian Brauner 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 1af85259b6fc..7fff1a3af092 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1354,7 +1354,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 Mar 9 23:05:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13168523 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 B646AC61DA4 for ; Thu, 9 Mar 2023 23:05:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22BAC280001; Thu, 9 Mar 2023 18:05:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DC136B0074; Thu, 9 Mar 2023 18:05:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CAEC280001; Thu, 9 Mar 2023 18:05:56 -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 F10996B0072 for ; Thu, 9 Mar 2023 18:05:55 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C13A51A0282 for ; Thu, 9 Mar 2023 23:05:55 +0000 (UTC) X-FDA: 80550894270.02.EF3A786 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id 232E9180017 for ; Thu, 9 Mar 2023 23:05:53 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=seeJm9gY; 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=1678403154; 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=Mj38/Shbs9ZyLGljvL78FJsMrZNw4adJNB7STaV6cuA=; b=JsLkuU4htuZvSZO6Ofbl6UdJ+x7uIhjf/KaMn2RUHE5kVAlNitmSVNgvdlat1yfh5VkihS Un0GAWovr5efC7VGduKy8GR5lK675/Es4nI9DHIdZygHNbgCQ9TtGugX42Fuj4EM1jc4w1 sUcen4Qc2sWG019ooc2W/DJfKiqSQ5w= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=seeJm9gY; 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=1678403154; a=rsa-sha256; cv=none; b=xVhcCimLbsWiKMbnH4XozTb6yrZpqxx05MpVmCR+WMw6Di5f2liMIAjHC1fVTrifHSDS+C mG5IK1WswjL+Sr4vQA5JOdNLXU3sHxkd7eIEU6MZNRftIbem/CaGpJ8kL355yuBcgbssiN p04EU6OXG0l6xOwKgsL7XJjlWo+atl8= 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=Mj38/Shbs9ZyLGljvL78FJsMrZNw4adJNB7STaV6cuA=; b=seeJm9gYP9E41NpNLIQfn02A+C oxlZ3k6wzYiLUH1KFiSb05cnPDxxE85TUCsL05PdvvOaU6QIuFDUpzxwIZeM5WsxwhAmZzqgZSSl7 8hBYfYuPOrxwUcjZKpqMjt3Nb6f22NzLkFsgK7K/Y5Lb/XJs0ZAhpfXLhj0DRTUwjaOTXI8FGUT5d 44OtbSzlkiJoESExutB36lEeI9dejYMgU7S7R7ApLodCoJtM4HPACPX51Ftk7Pyfct5xSDZ0+nutl pXExNQXMnX+lTj1Bareamc66niruXfSdjnmbxhqrUnXtYCLtmkZtYwcGSf+KatBCDrZ3pe1ZlEhyX pd/xldcA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1paPKW-00CIRU-5W; Thu, 09 Mar 2023 23:05:48 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, David Hildenbrand Subject: [PATCH v2 2/6] shmem: set shmem_writepage() variables early Date: Thu, 9 Mar 2023 15:05:41 -0800 Message-Id: <20230309230545.2930737-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230309230545.2930737-1-mcgrof@kernel.org> References: <20230309230545.2930737-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Stat-Signature: wfpf36nsbnukbabzenaxe49xd6cbmx81 X-Rspam-User: X-Rspamd-Queue-Id: 232E9180017 X-Rspamd-Server: rspam06 X-HE-Tag: 1678403153-257682 X-HE-Meta: U2FsdGVkX196tijMgjnFcfM2XhUfUe25DU3guq79yqA1eaUTb1JaWVgzm6sEnLNeWY/quIfpP+5jcP53PLEsyR5u5N2j1BmTowhy+0c57d4JMovwpVo4YFCaP751fbrJBXU8YWpHE2LO0iqs+7/TafKjNz6ZTKEItVn0Eav7SmPe5TAVXbSmV14VOrT3vtk/e2PWXBd+4L372YjWKWBREbGVyLv2Yhm8MklU0kUlnJcsQMY06zgdsSy0ahEAGemaDwUgM5RcrWIqg5SyBrXl7TKIm/l5gAB5CO1yBacTug2SYOO60akPsDHrAMq1Bu9mIJ25siIs/NQZrzOQr9W5IN00Ai2bHTe3rim+KUsTYphUmAxtE2L6sEgLKesL/sePo+Z7qTeterT/Yc9DISPM8KstmMgUgSogER1330umUNqhydI4/5p6vwumts3w1bVz3DDV9VoEG/ywj5QGPMib6L//A0bw08ZH3D/BS0xdTPxCnb16qYIeiVCNY6uOs5jWtP/Y1chFqArYn0owazfeZdMf9xvClFVYjc8XpDKYDwxlu3+lEsS0QO5ixYzHzm5SW9thx9a+Z7vxH5LV7P5VC33D2jz0Tjo12x8tHMTDgG7srMNdd6go/s1OAtNrYVAFoeGYiyDxbSOLOAR3KRfBfsIXBkQm1wXJrVtSpL+YmhElpNen6vf0nCcJCMOSxbaoKEXLTk4ycxv+ru/z1uTlVVj/iNS6QKj5xOpg7V6tchfwC95g5Jd5XvUf5xI0yhy6zTrndYcHSViu4JJ12/xkwpzvXGKJ5wG5To5peZuUHN+vahmmZOB67rGXu3ZIZmRdLfZtROEqdrlJsoZCXdAv3+BJI3KIhGa7vqOUtqqelFZG2AKOHLPAqWqm86tnXdcnaGR3t2+LfDUjX0MOJywXt+IcSTROkqki5P4D24aL1Jcp2IgK4KrEjpWNtDRr3dIlqnhbis133lSQ5n8SXVY TLRzD6F2 yFalIC56/tzPclEb6tXDZQA77eJet4vmL1rf/OiIWyzXGoZ6T0z+g2V0SIKRPwLjjO+2GQsTty88HWKBsTK6sKtlYwApd3NoOzRWhI11XxVKbsLUOZP4P+xxImZEmCy5fwh3Onk2NC3bDLI5QDYU239Sle1RZzWlEcedeX6SAHn7VVJusp3EPFlbRmM1BUMdjeh+/eXAPZSeHmEp10mILqNrfkm0eM0hpV6Ns3eKX6WpuTeBmufXprhfVYhpPPxCdwN13VrEubKO9s6KZ81MYT9P7/xSvDgqH+xl/4ypluxizGcADwsU5B+TwWD6E222vpF9o+6SjvxlU+4hRwqt3hkgpYBFTztqiPKDxLNV+v4ODLhf/+dO8jMTs8cbg5r0Nq8KF9oPxzi+OYUO3FqYQ70c1M7fSBd1m0WZIIRnEQ+heYwdc/obIJ33sNy4VdO6ofuQewk5n56N/7JmRuNH2ERldFhEDISLw2DeYAXtuVT/dGeE= 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. Acked-by: David Hildenbrand Reviewed-by: Christian Brauner 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 7fff1a3af092..2b9ff585a553 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1334,9 +1334,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; @@ -1354,10 +1354,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 Mar 9 23:05:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13168524 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 6F7FEC6FD1C for ; Thu, 9 Mar 2023 23:05:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70DAA6B0072; Thu, 9 Mar 2023 18:05:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BE54280002; Thu, 9 Mar 2023 18:05:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 584AE6B0075; Thu, 9 Mar 2023 18:05:56 -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 4A8006B0072 for ; Thu, 9 Mar 2023 18:05:56 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0BB8340811 for ; Thu, 9 Mar 2023 23:05:56 +0000 (UTC) X-FDA: 80550894312.27.C3A3A37 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id 60D8920018 for ; Thu, 9 Mar 2023 23:05:54 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=gLrCmQ+J; 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=1678403154; 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=lRTyWhPNnRtMIqcninG/zeE0F44SVFjwfZYisJiUrvs=; b=8B4UOIdOAPET11McwAPJ6prfcBjuivZ3vhrt/1sibYCQ6TTv0I+Q+604ozGrA0GbX3cjd6 /O+zuCUKh7tryAsk/oo7MhBx49yAvQZqM2j/y6l2vmHdQd/RK9fJYi6LMFLuigdS+/6bZe dppZf0qDFBLSFlGqcX8gxyEcImRv4Rk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=gLrCmQ+J; 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=1678403154; a=rsa-sha256; cv=none; b=bVIV9RmoLGUHhlQb4HyfKswS6NI+u4pSu+/yFa3LPwvrJXp1gmxboqe+4ZWUX1igK4YLT+ uh7nX/+wbZKTNPJWO8+QdhmqKfDz6UrUQC9ziP63WG/p7gKbUjkDVGmtUpxtM45bJw8t+n KS1wMwOFzGzgiSbeBPtjbzRCS+FTTRY= 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=lRTyWhPNnRtMIqcninG/zeE0F44SVFjwfZYisJiUrvs=; b=gLrCmQ+JAmVqsGLnc+ORmTR9Po KUk+ypQwAKuob3XUb+wNe97TWEZv4xENuSB54H1MRcT5n5U2JpvIE5Ysf4oRoQmn4KwoZpT+heKBD bJ6A1bK+Fe0UV0icaRTaGBI8yOXczM+rW0owdM7y9w7NnixJe59wgw89zRYFYjKVtKrBHNwm3xGlj dpat9O+ynl7cjNJqggoOfVLoW7YnoumCLQM0WzApY+vgIlEep002GRlUkPdvy2pYCtGaOcxyTvp0h Q6sQ0lq3b4JFMxBExpRhPEOpHbcolHLjsglmub8cSWnmdm4QziVbGrmC7mKCC6Gz0/DlbVYM3a1DO VlWyRLaw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1paPKW-00CIRW-7E; Thu, 09 Mar 2023 23:05:48 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, David Hildenbrand Subject: [PATCH v2 3/6] shmem: move reclaim check early on writepages() Date: Thu, 9 Mar 2023 15:05:42 -0800 Message-Id: <20230309230545.2930737-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230309230545.2930737-1-mcgrof@kernel.org> References: <20230309230545.2930737-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 60D8920018 X-Stat-Signature: 84ya3nm5xhjpqmhyd8rqqb3doiwu7jue X-Rspam-User: X-HE-Tag: 1678403154-133852 X-HE-Meta: U2FsdGVkX18fMLduxKdScsyz7Rl1cKgRwFG/zMgs6McUsuSm5REPJGwkNMzWm2YoHy5yiPsaR9irJ4M0gFgCKnpmhdy6+fiY48OklVciw0JLcti2JOMelCzStqFZvSGuh/QJyOXRR9HEhzu+gg5PdFgUbk0cIXMODxtBMKKX8LoZ06mQq739oSP6116+8xSDrLhtWKnROrtWfjgJ5LAsBlFPyC9YWOgU4Vg3kStpmbyRDxJlUW/6VoJHGydZvk3d6kxw3vDuTuuj7znKsHzuJ+sMSJnMJ32zYMZWRrYroVwVn/UeioPvsBMHo7gybsTV/kwORA/NfzW8KiwWG0aTIPz9nfa7J5XUTnYeiFx9lu3YePpV3JosoOUgisrXzljruA79M7+GT3cjUmSyFRzfbi8WLCqAUP74sf0tZ7sKt0iHi/xQSqMEavhscxrh+5kS1QGjeRSr2deyTQXS0u6xORfNZhphDGNKl1G6mc3hW1a1Fhk1hnic/vBdKTgz9Gq+tBv4BFDb03HsyikoM5T6HPqXnefTv1thDAcm/pNXIBgr5b5KcGceGfyLl763hAaENKZyfGbMwb4NlRLt0qW61zbHeOZzy+FrlNhCwBuxSzizrYz+kUyEeCFhKP0I5WAK5QfsHCscEGMfu8cLKmhy0IyISwZBJFl+XAqKx8Am9UataRIPJ9qO6XW/K6iibSVAGqaE4l1I5l5weXxVzz7mMnfT2uxzLP14CuvgNUQGxVrb/ONK/BogrOzugyVg24vVGVFZYggoLGZ7x+k8BXeSmiynVD7eQoNtrwfLGpUtSEo1PwUNQXGW9hfwVs1u4gBJ07oJXpjdbDuN1B0x4kdDNwLbstHlQynH+iUE34s140hZddIzawrL1XBPgTXAcDm02HPHOedH4Mm3aIhqcYNxZ5rGkjf3qdNv/0237WtSjyXxxK2bww9pwaRr63jK745rk07NsR6PpWrdP1s9/gH mwb/gxtZ G/R7BypBIfkPmbRAG/3l4YAsVGNzbKjedgjKu6LZPPn6t8/6zKiNKSMnyBGrgBI30a0wt318PM1HTkNI+BY78VqoAFAruFTSNJs2M1kjcftqzl/rtf3+k8ic1qkVWJMkzCtFDDTW6llrbd8fXmCFdTUTG+/oxaPDrrKpoaAUGsYejsz17+bHYFMhu9TpynJlXeArXr/6ChL0vuUQS8fUM8rVZty34VFXgHk4WjF3l2fTOis8zSUOjCR6dPL6LoPlFyFfIblLyDegEn+J3NuVNraPJ+Oq0X5SgOri/dh1EFZukv8afiMoLQJOGtDX80IRHKMDzV+nwBw4+avkWvWQn52pC9noGwcbkHNdWodPJ/vNL4Gj2rE2Yy8ed/DPrjGuZdh77fj1g8P85cJrZwyADH8y0yY4GaL1a6MIttORvwISUdZQmo8M62UChOEz9IgactpxmZfdZZhX0L/E= 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(). Acked-by: David Hildenbrand Reviewed-by: Yosry Ahmed Reviewed-by: Christian Brauner Signed-off-by: Luis Chamberlain --- mm/shmem.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 2b9ff585a553..68e9970baf1e 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1340,6 +1340,16 @@ 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 (WARN_ON_ONCE(!wbc->for_reclaim)) + 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, @@ -1360,18 +1370,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 Mar 9 23:05:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13168525 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 E3953C64EC4 for ; Thu, 9 Mar 2023 23:05:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB380280003; Thu, 9 Mar 2023 18:05:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6443280002; Thu, 9 Mar 2023 18:05:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2A5A280003; Thu, 9 Mar 2023 18:05:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A4A0A280002 for ; Thu, 9 Mar 2023 18:05:56 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6EE4CA118C for ; Thu, 9 Mar 2023 23:05:56 +0000 (UTC) X-FDA: 80550894312.28.17F0D7B Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP id C5DFB1C001B for ; Thu, 9 Mar 2023 23:05:53 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3HA+jE0d; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf21.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=1678403153; 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=nd2m/LNu9NMKcIyRptke6PFaE+tBCNb9V+MN5pDSpQU=; b=8KwLI9/SvlnpUyhXEHG993PJdsBvdqwC5i5zYHXtBQkyC/uEa8cpJVAZ1h6lLLsYeYi6Uj xJnLjgv5hTucakTiv0l/UO+Au7zeS38osr4Uqew2vAwgRjs1GoIXKPWNY0zcLptzYDPKxT UyVDzQG2HyQ19IiXdYRRuXidVOSnIW4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3HA+jE0d; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf21.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=1678403153; a=rsa-sha256; cv=none; b=5WIzs3e4tX0RtpgQMLQ+FVlf1x/4xiFe9euRA/MJG2BO6jHMCwmtHgfsTVFGn+JrDt7En/ /ysj1pAtU8CpdNeijLHLlzU2iJLwbrRoOW2KF28r70X8STftoRzZcFu7czJjgdGHJDVo/3 4pSDiPCJE3+nSKE73o8EVSj7m/h/sE4= 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=nd2m/LNu9NMKcIyRptke6PFaE+tBCNb9V+MN5pDSpQU=; b=3HA+jE0dyswGu9J5ZVVPfPe329 BO74aE5mhVip8O7KCZwd+SF7eFwb27HJyop6K4tGVHCtQXPIHeTkMP2VAkR0T3MojwU8x6u+tf0Dv nBlE2vsMycFdc8mJdNhg9Wjv8EuDGp2Liutocgdvmqk3KDlQD+PgebAyTzprcitwS5UM8JZ4yfkgZ UNrRRD4Z1LIzm7QVLI/cT8FeeIAguMrwrgUAi/3NZY3KeND9TvJ0wUDcAtY9ObElBVCcs+W7kwkZ9 7EyooKOu7ISN/RzkBo8MmRK2IeqGOi5Rh2g77AKzK4W7UpYmr2grBlhpxHPHisC4onhlVIrgPbgEq 5dxQmXXA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1paPKW-00CIRY-8d; Thu, 09 Mar 2023 23:05:48 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, David Hildenbrand Subject: [PATCH v2 4/6] shmem: skip page split if we're not reclaiming Date: Thu, 9 Mar 2023 15:05:43 -0800 Message-Id: <20230309230545.2930737-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230309230545.2930737-1-mcgrof@kernel.org> References: <20230309230545.2930737-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C5DFB1C001B X-Stat-Signature: j8fi5dafd3g9gmxqacwerr1ua71be57z X-HE-Tag: 1678403153-950591 X-HE-Meta: U2FsdGVkX18P4jpXGTgsrcUyx0XIUdRbJy3oioH+hnIFI5/IOvfkWoosFHmwheOsVJwhRkCNLyXb102VT5wWLkAOtTdb29xrh4yLaMY788eQZElMykgtljpMQU7GRkUSYOvPdf0UkwpJwXwsCgapj9gV2sGIUgbFDMtxUoQDKuU8tVGSZQu1qQvAgaWmLzFkCKhL5RBc2mKmAh7LbbxgQ/CP2ufn5u+KQC0xMN+O33B0n4gM3gmSGj2mV10iG8MnVf5eDBxwS4SD/I8+xelIJxbO0UeDFs9vNO+eUx9xDtLiF8+WuWySY8xj1r4QF61ydHtDbSgqL5eGJcBlMe1MRLg6QxeyvBclL8MuUsebyaHzhORHL45vncEqmEzeGQnsidaLhG0kcHTIwVjAMPSpgdFU/9+G7nsCFrU9EZHap+mFej/h1QBXB94qANXpIWyvNDVta6evVfqSNinwoTawzqXHxp+OZVWaaxY+mIbCbI71VlSJeehLao3vhPNJcIKeBF6LYtwr1bstKSnADx0ZW0Cuc/DB6iVu/bj4814fFcsr8AhML+v57UGqjJDn31ZpthtImF7NlFMFeoZyWfxqBWWay3tBBlZdVbFza7gzYD47iofVtyX3TRqrB+bIEmX3GLiQIFCbEZ+zMlx72ShwJDw3UZgqjYoAX5lZ2yBwNyJJjoViDr7e5IJDia2/CS+7cKHi0CGnh3RnUKX8RpReBOVGF9Eaw7meWoSvdzDpFzR9BjRea4IvSE6sVf21hXJtshRBWY+qc+rh2HgnT5F1/7hIcuhK7V6jpwY/K6umVYt67f4nnqlcomZju/1YYDcJoKOkp9TZKwxIdiGKTfcUoxF+SbhNrRcbXlZbcAM9Tv98c5I4gaTa+w39PknhEFJZM5QbJhWxWTpgIqk180k8mCaI1fJtPfHp6xmv5K0Q9cBdJAftROpKDXdH/nFT/GyW/tTWgJjhVQeKk0V5F6A u1fJ9XkP wJ12/F7H8WSZ4Ay497bvsyFStvbmU7jjDx62syU4HtB5+EJUPjNSqX2LvlNO1wusLdFJMG2FVUDXky2OB0+kE2GrpWcajWT9GGxqMFLHflCiHLiWX9CRR0avQinpm2GTbNwFvI2Bh7UwcSDmfXDvGJsmvJnO80X/VXuOAGJAyLfGN8Y34VzC/MBw/3Ea1+bu9ZBiELn4IbUIPAzqIOej9OMz5OOYmv88omz5l1k43cNWbdtzTQaNAI9NpJ/3wt15+QT4Xx/6p7ukUs1vxzJ4gFECUeq2sgggiHSnTmKHzQBxNTQRaksljyOlenxkRe2xUrnxEeJRpSYDyNGjb1Bcvc5HaEY5sPoch5pTM6Dt8etljTwDNpySi1KflbAS5u/KOoWM6BvivkJPaZ4h3rh4/7ofOzH5LNojKd1QKE0Y/d8+fWPkDq/FP4uD3bA== 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. Acked-by: David Hildenbrand Reviewed-by: Christian Brauner Signed-off-by: Luis Chamberlain Reviewed-by: Yosry Ahmed --- mm/shmem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 68e9970baf1e..dfd995da77b4 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1350,6 +1350,12 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (WARN_ON_ONCE(!wbc->for_reclaim)) 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, @@ -1365,10 +1371,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 Mar 9 23:05:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13168526 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 C067CC6FD1C for ; Thu, 9 Mar 2023 23:06:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA2EF280004; Thu, 9 Mar 2023 18:05:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B079A280002; Thu, 9 Mar 2023 18:05:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86C4D280004; Thu, 9 Mar 2023 18:05:58 -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 79D1B280002 for ; Thu, 9 Mar 2023 18:05:58 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 554B1407B4 for ; Thu, 9 Mar 2023 23:05:58 +0000 (UTC) X-FDA: 80550894396.09.7F9AFD6 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id B10C6100014 for ; Thu, 9 Mar 2023 23:05:56 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="oZkr/qx3"; 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=1678403156; 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=KhIOryYi/WjMt1G9oWTtfKzfZj1AUYZk+i6xawkBgBo=; b=cjeupL/WHTAQoxj2/lEcBdy1IbrpjuFlizdr5h6xlehQDnV7PBlwX7GkIHhbuPxv3YfGY5 RU9kiPIskdMAWxAA4idkhstMnxLREp390MXvaf1dlc7B7ogczQF+EDaiog4+gn1JcIQR6k 6LG6FWCzCAKfE5OqRiScN6JQQqBworQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="oZkr/qx3"; 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=1678403156; a=rsa-sha256; cv=none; b=tu7DqQbAAzbss3wsLUNL8sBQpyh3ST3gRgFA8IWy778e9OtdZv0Dev9mWeGgN5TylgWZ8A KYu2IgvqA6zxlTZjPHVryJVlcnmP939OZf5FzAiEf+YqmmmK94MBR2SibosBmmU9DElBCg A8vXGTReQhAbU85/WfEb/Ma5zG35izQ= 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=KhIOryYi/WjMt1G9oWTtfKzfZj1AUYZk+i6xawkBgBo=; b=oZkr/qx3wEVfj1+ZVhCpyCYUCM jPh9BtYO/JSVE8KrDiP2o4+eSvNFTDhlZZMAGxJNUISY7r5Y2UQ9kJ7YZ7cFxmcydxWagnOYed0Og wDztp8ZfqI7TdvS/7rrodGjB1hRbxyZoDbRSj2Mhdxfex4+EkVe/kcw4urS7yVzUCrelwyN4OH53M pAguCzkK7m39yc+D18Yqzw4LPOmZDxW1iRJDItZjlzSejD1aNkbTxRX0HfkUWjGtOOtW3KhfjHCIZ HVtJ04r4g8q08N0npmkuwuhmFDnKnU1F4T7o6wh3xbBAlS8F2RA2HFNXQ2VjZe2ygU7wxl1qrFmMu jmuVMOqQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1paPKW-00CIRa-Az; Thu, 09 Mar 2023 23:05:48 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, David Hildenbrand Subject: [PATCH v2 5/6] shmem: update documentation Date: Thu, 9 Mar 2023 15:05:44 -0800 Message-Id: <20230309230545.2930737-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230309230545.2930737-1-mcgrof@kernel.org> References: <20230309230545.2930737-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: B10C6100014 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: ngeo8aocrnorsjbbcbabtmwdwu9htyeu X-HE-Tag: 1678403156-629320 X-HE-Meta: U2FsdGVkX1+vo2MwDiBHIkcPSw8A6G7K8u1hg/nGLjNg/NMMD3saKsj6iFTNiy3IFfRjVQoCbZk6wksQiZM9lf/v+lWOH32fJlSD2lNM/COD7nKmtgEAZjTxFBd6pc1GqEnR+f2fztmr03x9O+B566YGZs5LR1z3WitcH4DCh8Ff/JicQK0ON9tqtnwvWF8ThYDG5sWlx4SaUHdjASEJ4U3hhBqVdf2lsXcSZukN4KpWYnWtw2p7HFVUfvktZbqNU5Yc+C/ykSZWJaKYMTlY+KeEUSg5GUMLBcYoqJkzY9o/MDzmp880dlw2899MC9D1ji2ItmD5GJNE7S2pJwVM+wCMiWRlkvGpoXlDWPczIeRuycWxg7y/UqAGkMfnNK4klWTaFWstzjg/Icn2d054aS3mnccxho/q89OTFsa3fd4PQ8xphVJujOaP+l9HQ8XXnYIkmQzX1ErHla8QnyrndwopmlOqATuK74gb9Yj+z2I86DUCFcBun8yWGw6NB81/4rr4T7bfoldvM1wbg72yJm6GW2K4mEvITXEQDNlh4NstBJJZpKvpruwfrObve4JXyYgq/WNKyUV0uoBBqaDvFfECMM1uYGMaIzB/zs3VQyILygw7DoEQedvFCDemq5kohmIufoBYwiZPBBFKe19u8V2Q3TRvK6/TlhbX1UxSa9nIT8GomfdMJKks8nXgYsy6gw5EyUNz1umYclEhmqD2EoYxofA6MUaAA0G2BXGVHVZgdj4E8sSPOi7tOtcL9iv+ukJYkCrvjL+yBtyJDPbw9d+eUy1StHxQZwrLn3OiVBIxVzukV8u0Wi7sA9ZQ+oQYN6tT815rgrj4mUV8hArMd7BgaeAH9WorCadppIEBEx49HsD6LnjzIgn2x2vo+jtT0yKSXF+/qTNpPEY3X1tt9/tBALwj1aozyQuAyLjdASYZYB4pXOxZOc5ChsqTithPvNf5NCKIJPoWmTDhSBh oESIHfCS WxR+Xw/SJbXx1EGH746KsWN0j924LuV17pd/0ZSI/gmaDnqmDXyjZHSvssPzU4Au9g2DTN4KKmU3LLnttE+dTSZmezPgQTOb+y0HVXkK5XpWP3e1sw9TFqXlVjkl4jTSlJCFeA8oh1znCoEFzWKe9xpYzTDKDcv1GkVbzhJ9X/dCFIfiw9vYbjl6wLbASvtcj4CQITxbeBmd4lTthjb3DKUkGmHfIObFKCpHh5e9eIMwnkXtZZNBWBPZ+91tqGWXHai0OsgXlVzTUEn5Mo3ondOcRqP/Tz23Z/Ugzs6KetRsI06Ls4Gai0W1unZb9CKqCfTZb9cSN5gCm5g4TYPa3cQPP53QeVku6ihE7spv1fe7486SIGx0sscaCeRZFXw9A52LM7IRntEOpzMZt+r/Ur3TLl+unjO54bHD5hRULkNe/d1TYoV0zv0j0zQ== 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: Update the docs to reflect a bit better why some folks prefer tmpfs over ramfs and clarify a bit more about the difference between brd ramdisks. While at it, add THP docs for tmpfs, both the mount options and the sysfs file. Reviewed-by: Christian Brauner Reviewed-by: David Hildenbrand Signed-off-by: Luis Chamberlain --- Documentation/filesystems/tmpfs.rst | 57 +++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystems/tmpfs.rst index 0408c245785e..1ec9a9f8196b 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -13,14 +13,25 @@ everything stored therein is lost. tmpfs puts everything into the kernel internal caches and grows and shrinks to accommodate the files it contains and is able to swap -unneeded pages out to swap space. It has maximum size limits which can -be adjusted on the fly via 'mount -o remount ...' - -If you compare it to ramfs (which was the template to create tmpfs) -you gain swapping and limit checking. Another similar thing is the RAM -disk (/dev/ram*), which simulates a fixed size hard disk in physical -RAM, where you have to create an ordinary filesystem on top. Ramdisks -cannot swap and you do not have the possibility to resize them. +unneeded pages out to swap space, and supports THP. + +tmpfs extends ramfs with a few userspace configurable options listed and +explained further below, some of which can be reconfigured dynamically on the +fly using a remount ('mount -o remount ...') of the filesystem. A tmpfs +filesystem can be resized but it cannot be resized to a size below its current +usage. tmpfs also supports POSIX ACLs, and extended attributes for the +trusted.* and security.* namespaces. ramfs does not use swap and you cannot +modify any parameter for a ramfs filesystem. The size limit of a ramfs +filesystem is how much memory you have available, and so care must be taken if +used so to not run out of memory. + +An alternative to tmpfs and ramfs is to use brd to create RAM disks +(/dev/ram*), which allows you to simulate a block device disk in physical RAM. +To write data you would just then need to create an regular filesystem on top +this ramdisk. As with ramfs, brd ramdisks cannot swap. brd ramdisks are also +configured in size at initialization and you cannot dynamically resize them. +Contrary to brd ramdisks, tmpfs has its own filesystem, it does not rely on the +block layer at all. Since tmpfs lives completely in the page cache and on swap, all tmpfs pages will be shown as "Shmem" in /proc/meminfo and "Shared" in @@ -85,6 +96,36 @@ mount with such options, since it allows any user with write access to use up all the memory on the machine; but enhances the scalability of that instance in a system with many CPUs making intensive use of it. +tmpfs also supports Transparent Huge Pages which requires a kernel +configured with CONFIG_TRANSPARENT_HUGEPAGE and with huge supported for +your system (has_transparent_hugepage(), which is architecture specific). +The mount options for this are: + +====== ============================================================ +huge=0 never: disables huge pages for the mount +huge=1 always: enables huge pages for the mount +huge=2 within_size: only allocate huge pages if the page will be + fully within i_size, also respect fadvise()/madvise() hints. +huge=3 advise: only allocate huge pages if requested with + fadvise()/madvise() +====== ============================================================ + +There is a sysfs file which you can also use to control system wide THP +configuration for all tmpfs mounts, the file is: + +/sys/kernel/mm/transparent_hugepage/shmem_enabled + +This sysfs file is placed on top of THP sysfs directory and so is registered +by THP code. It is however only used to control all tmpfs mounts with one +single knob. Since it controls all tmpfs mounts it should only be used either +for emergency or testing purposes. The values you can set for shmem_enabled are: + +== ============================================================ +-1 deny: disables huge on shm_mnt and all mounts, for + emergency use +-2 force: enables huge on shm_mnt and all mounts, w/o needing + option, for testing +== ============================================================ tmpfs has a mount option to set the NUMA memory allocation policy for all files in that instance (if CONFIG_NUMA is enabled) - which can be From patchwork Thu Mar 9 23:05:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13168528 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 7161AC64EC4 for ; Thu, 9 Mar 2023 23:06:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56208280002; Thu, 9 Mar 2023 18:05:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 477B6280006; Thu, 9 Mar 2023 18:05:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33CD9280002; Thu, 9 Mar 2023 18:05:59 -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 25CA8280006 for ; Thu, 9 Mar 2023 18:05:59 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A65CE40ED3 for ; Thu, 9 Mar 2023 23:05:58 +0000 (UTC) X-FDA: 80550894396.06.56A46FD Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id E836C80003 for ; Thu, 9 Mar 2023 23:05:56 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZOkHpRV5; spf=none (imf02.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=1678403157; 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=Y21J21Mx6XlkkY3LHzdeVvTlVfIT0jycn4uNZ988WD8=; b=ccK3BlTDbLW0h0UsWP51JHITgfqisQTHTWfuYIMumvFVWMKPUkQKFas0fDBKFBrDnRe/wi lD9w1D9E07dtrDCWNRedY5varOLxioI1S457ld9b0AP2LWW6u08moQbpXj6BnzwSWv+IZv uHCa28I3vQxKM8bgFqpmu4bdg/eXJnw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ZOkHpRV5; spf=none (imf02.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=1678403157; a=rsa-sha256; cv=none; b=gH4Gz5+beqU+D6cN1NgarLGF+yUxEgi22wyb3sDwa8AzvpteCaVhMfIxKTTloJsmh8kogV DIwiT8Kg/h36AdV+jmVQwzQOG0wOgKXpedjYzIdLiFXJ0qEOzT2raQ20eViYmclFPyS6Sy Ge9mL6KxunX79M2xwDPjQZjmFWcJLEE= 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=Y21J21Mx6XlkkY3LHzdeVvTlVfIT0jycn4uNZ988WD8=; b=ZOkHpRV5sG86BmDY3iU6uooKNB X3EgaVH1y2vZ8Y60RVSjgd8vXePnDDwNwiZgCL7Jx8kSkkxi+M7ICS9cWp6Fqj0QL4IDr4lusiybL GLwkVmNemW5q94eEDaG1NQg8bd9eI2rT2SekcRvywb7SEIjLWXO+AMm+dE/HTYrzSyv7kJFiQ3IT7 kw27XPA3Hw7D4RlPo7C+KcXnezJquG3ev5odFrxa+d/5hFE3F2qs5HH38Y+MSrpkapTY1e3q5UsHR y/yyIBml3owJtYGV0QLnLnl/Py4djMGQXd5bdOyoAC6P1eeSB5GjL+5yYR5HToQmYWrP/c52xdF+j j4mPV3yQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1paPKW-00CIRc-CU; Thu, 09 Mar 2023 23:05:48 +0000 From: Luis Chamberlain To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org Cc: linux-mm@kvack.org, p.raghav@samsung.com, da.gomez@samsung.com, a.manzanares@samsung.com, dave@stgolabs.net, yosryahmed@google.com, keescook@chromium.org, mcgrof@kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] shmem: add support to ignore swap Date: Thu, 9 Mar 2023 15:05:45 -0800 Message-Id: <20230309230545.2930737-7-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230309230545.2930737-1-mcgrof@kernel.org> References: <20230309230545.2930737-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E836C80003 X-Stat-Signature: me7iti3suhhsnsqumbtim77ubjswiyme X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678403156-601933 X-HE-Meta: U2FsdGVkX1+nU0Ao2hK4XczCqGTDaAB+/MMm55uNp8uR8czN4SRN6ehrviD1hltbImBeHJwcvJo2luWGEPg4efpPVzBUA7fJVMTp3mInHbv8tszMrxdljp6Mjg6u5L94J+/i9lwyK5J0z1bXm3H0LmGW0AdBaibKoZ1W96bTmv8/fCema50CUwVYxUplMfJfCHoDwpwD6oBOn+D9XpNb25wF2UqUSUZVpiHO+zD2qMKZ4NM5f9wazM8YV49+4VIOnAhpn0HhnSZzYKBzIvX3ZtXWHEZD5Rphm5ASnCyXhtpqcLYpCfTVnFrJWw74gI/r2qi7NKcXBSAITGY4LIxQaX1iXiSMIEdbynfpCDOpXYt2XDOFS+werSCXkaj29XFH2WpXwPa5ZlA7ir4GebyB1orzzIhweofL+ATJnuJUztNXLG0KJtBG4ZGZR+d2EvP+UJpndxsNnWQbWFlcA8IPZNVQCtfvUZloKlEI7ptaqS9TBT9R3vXCx5aHGHtKwz+gWLWVIyOveEEoGZnwzzZN5Dalp0fynE7vQAiHsuu5jYib5912nkiDmGGd9g9NgEG+nDnuGYCmsudp11QoBrGgld84klXnD3zHMob2EDp9hxMA7Jw2dBAyDpF0gYk1VRpKODWZEGptSYS04u+PRmfrUhoFvQVv1dmgVI9Lepny8OdO45De++G1ka8J4WYEab/zhLAkA6CGenxMWud0KKAWQdrTpDbO75O6lP51ag/15Xe694w4M+Stl9iPqa+Gx5vOHbHq05gmc+BggrhtpkvbGIme1U4FVrCWY3t+LIuPsESmzotWKZ1h/V2MN3n2s3y2pLT0+Ie5KijFJc1ZgvXZaP+VuzJvBhZ174mqnnsvPguKJ8Obj3Iz6kfEJb9UiADNT5nopWz+t+SNx7NjtNvhuydes7A02abDAPE41vsx9bJH7vbtOn+CxNrxz6+RbZB7vyiZTyd0hcIPBq+fIIg A5GHle1u fFZZ09ZXHW8RGujiB5HCr2bgve2mgoueGWDG10Dwgox/dCnyVHrgOn9ug3zHHyqyww1wXgiQVk8MuAilmSkdvjmu4tjQ+zS+mNBiXYHLbFj3KtjJvEDRNSVF9iF0d1WxEPvpXWSOQnLhWiJJofjXaqzpE7qpvhLJkiDfnKTCCYtGge/X1HZ8tNUU5AaWfTXydAK9PK+TBQ4ijiVkpyiqYpvh0klxuTsEWyhxhjNvQf5+b+lmja9WrJB+bEeeSxULnhxELrcqv8zSeDdPFaXt5mzJIsFsnMpiGHMscGyWrFoeJe6+E0jc+JCNfnGC3EoXy1mB5jUDXMFBm42vgESZh+MmUd58+pIW21/2mxrG9DepTYRpSQYc0Py/O3ouhUyQDMx5gqqlbkAsxxIWJuQJF9/yUm2OYdKc2QqREcH110XUWc5u9UAHz5M3cVg== 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. Acked-by: Christian Brauner Signed-off-by: Luis Chamberlain --- Documentation/filesystems/tmpfs.rst | 9 ++++++--- Documentation/mm/unevictable-lru.rst | 2 ++ include/linux/shmem_fs.h | 1 + mm/shmem.c | 28 +++++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystems/tmpfs.rst index 1ec9a9f8196b..f18f46be5c0c 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -13,7 +13,8 @@ everything stored therein is lost. tmpfs puts everything into the kernel internal caches and grows and shrinks to accommodate the files it contains and is able to swap -unneeded pages out to swap space, and supports THP. +unneeded pages out to swap space, if swap was enabled for the tmpfs +mount. tmpfs also supports THP. tmpfs extends ramfs with a few userspace configurable options listed and explained further below, some of which can be reconfigured dynamically on the @@ -33,8 +34,8 @@ configured in size at initialization and you cannot dynamically resize them. Contrary to brd ramdisks, tmpfs has its own filesystem, it does not rely on the block layer at all. -Since tmpfs lives completely in the page cache and on swap, all tmpfs -pages will be shown as "Shmem" in /proc/meminfo and "Shared" in +Since tmpfs lives completely in the page cache and optionally on swap, +all tmpfs pages will be shown as "Shmem" in /proc/meminfo and "Shared" in free(1). Notice that these counters also include shared memory (shmem, see ipcs(1)). The most reliable way to get the count is using df(1) and du(1). @@ -83,6 +84,8 @@ nr_inodes The maximum number of inodes for this instance. The default is half of the number of your physical RAM pages, or (on a machine with highmem) the number of lowmem RAM pages, whichever is the lower. +noswap Disables swap. Remounts must respect the original settings. + By default swap is enabled. ========= ============================================================ These parameters accept a suffix k, m or g for kilo, mega and giga and diff --git a/Documentation/mm/unevictable-lru.rst b/Documentation/mm/unevictable-lru.rst index 92ac5dca420c..d5ac8511eb67 100644 --- a/Documentation/mm/unevictable-lru.rst +++ b/Documentation/mm/unevictable-lru.rst @@ -42,6 +42,8 @@ The unevictable list addresses the following classes of unevictable pages: * Those owned by ramfs. + * Those owned by tmpfs with the noswap mount 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 103d1000a5a2..50bf82b36995 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; /* ignores VM reclaim / 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 dfd995da77b4..2e122c72b375 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -119,10 +119,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 @@ -1337,6 +1339,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; @@ -1350,7 +1353,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) if (WARN_ON_ONCE(!wbc->for_reclaim)) 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) @@ -2487,6 +2490,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); @@ -3574,6 +3579,7 @@ enum shmem_param { Opt_uid, Opt_inode32, Opt_inode64, + Opt_noswap, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -3595,6 +3601,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), {} }; @@ -3678,6 +3685,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; @@ -3776,6 +3787,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; @@ -3796,6 +3815,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; @@ -3850,6 +3873,8 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) seq_printf(seq, ",huge=%s", shmem_format_huge(sbinfo->huge)); #endif shmem_show_mpol(seq, sbinfo->mpol); + if (sbinfo->noswap) + seq_printf(seq, ",noswap"); return 0; } @@ -3893,6 +3918,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; }