From patchwork Thu Mar 2 23:27:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13158048 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 E165CC7EE30 for ; Thu, 2 Mar 2023 23:28:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 088AE6B007E; Thu, 2 Mar 2023 18:28:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB36B6B0083; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6C726B007E; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 82C036B007E for ; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 45E801410F7 for ; Thu, 2 Mar 2023 23:28:07 +0000 (UTC) X-FDA: 80525548614.10.C832270 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id 17C09A0008 for ; Thu, 2 Mar 2023 23:28:04 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="A1T9i9l/"; spf=none (imf15.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=1677799685; 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=X3niQqWSDaRdijh0GPlKHY1yoysmmoQVBPzADYFTAAk=; b=7mkVtHz4GFEONTQFYpRMMiACzD8H6HXwoeFFEtd9Y5E+ibmbUJ6UuDWbQXy+/CnSxW1N6n 0FspytqPOixwhkhcyUf7fU9aXUVQXNZdjY2WGRFvDdrAxyCBUZqM9QwWhUYtMcOHPehCM+ IxVgQ0Ft7/lDlva0B08Lr4CiCmbkhFg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="A1T9i9l/"; spf=none (imf15.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=1677799685; a=rsa-sha256; cv=none; b=tAy1eIDlke0LtejVwOBCW7P3/WpTG0kA9oAV0V79MxgO6sDdA9MkHr4gQuKyxO12eKRNWq uL5ISSV9TY8KVyuVAX0sPW529fhEAOcWS+D2LE0GgnP8ml03Bviih/ZdlKdTEYBIB2YJqS IFuGrGyyhkv5BQyWPlKsTZIHmppOUiA= 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=X3niQqWSDaRdijh0GPlKHY1yoysmmoQVBPzADYFTAAk=; b=A1T9i9l/KhB0qQZfQ43uw6v8kl DTCTRWDp8ClUN+kK4tmCnmWxFQZNAu7/KlswhmxIBSNnubcoAF/0v32hcIh7vsx/2fYebdrGuOFfD cAnCJAhSbnS1joVOILJsNws5NnKu+5mYSq1Eg2EeWdf/r2/gWG/2PiHtkicrXr4nv4g8KNvqyd+h5 zSb4BZm/8ekQ3nBFaKCQSpzvzbNAJor5LMWh0xvyjEChMKRIwSW6QtvSbE5HH6mk+eiwxMNN1wRYL NN7yYd8Xgu8+6Yqm6vtCggq8UsMK7X8LuLapwpCc3bG7p2c7yZG4p+iTMZohqzaupylW/idKcbw0L a/8QUp7w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXsL9-003j3I-3W; Thu, 02 Mar 2023 23:27:59 +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 1/6] shmem: remove check for folio lock on writepage() Date: Thu, 2 Mar 2023 15:27:53 -0800 Message-Id: <20230302232758.888157-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302232758.888157-1-mcgrof@kernel.org> References: <20230302232758.888157-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: pzafe5c8zy5ixkjoe8ugpwymspdj4fsk X-Rspamd-Queue-Id: 17C09A0008 X-HE-Tag: 1677799684-543581 X-HE-Meta: U2FsdGVkX183XkJArBdEFP42Iy3qPvxZZ8RMDK8YnM+UlbVLQ0LHgWCxnBG08AtE1PyyvzmVGq6/6nFlVLGfKJFeNUrIQLyU5o85z1DeD+Q1kY3G+qjYmOqPhU+grfV6zFUWI/rNE/S3M6s5FfdJP2CY7cHnAlCwhvuXufVrPnB5259TsudH52zAsbN+HdmunLIpZOmjWY4G4NXunzGbpiNUYTaKyzZmUcbIhAa9kfAmogA5OPbGOHlZn2bIuutH1wP91y3STL4kcjnDzKnAnN7H13BEvho6LKq8k9npj0b2o73QSgPpR80uvnQAzpi4wxLnK6tqF9qZUtM8DMfX2YuETs0ijdgDMKgzW+j32UGRId2LYsrGmwCPgzqfwu0FwCO/qKj8oyB9tedr3vEXyCObli0cvxvjgvkDq3yLDdi2feyakbSTOW3KwN4PiJd5Wqsm5DRXNJhSx1VeGSi5rukQAkv5zw1lTFzMPPdYc+pNihAkKlekQnvDH+FBgEtxyFHY1VZcWQrsNk8/saxwp65Vrx+SBMABMBHSEAF5wcmhGKVCw2S91swep5FMx8PCegiLeCs3S9RH0ARXQ3IVc6KIuZd6EyVDz6URIBKuoWvccEWNOkBMGEu+mPPqNWR3Q3vYIauMd/TqEqSCeBWkSo9aUyBNh/yhW8ZtBN1OTUNTOAfmU0UqxDMpuRZhXhd+hAj946xs/PKIm2lV13OCP7DUgs4Bmiiq5oCEW9nHU18q0LCsfw5f16boIKo2l52ee25UJXyLBYbQcOfrjFqNSWMzetqWm55dS8bfSTqddZc7YuReUcIijxKb8G33kEJL728cIz0mZcPzgIZE7f38f8VQt00RCaqcLg3OhHgyVZGscr00Nl85QNmZSxJ9zBD27qBBD3yW8x32P8aIBYwZoVpe5Kgcc2mb10rM/zfjFHYqejWHLvw3P7H2SsGPyNYtova71JGOMQ4r6UbELNa /INfnfnI QxI1uFE6Uota+DFXjofGJE45Oyuts10wzOmmfQvcQfvTXATYw/boGz/DMfc1gtmvFqn7r+JTdLJcVvcAmxItBEA4do8NIdCvuySbAQbHkd8/AdvjtvRhzFeZ1aYkZ9sTfiBxs7MysXTHas8KD46KBpCufgu6M/3efFaJ/b4nqiqM4w6+ohm9YV3bai4TOPocwlfmS9aiva8w8GJJ32WjqdmVz3Lc++af2Tj+w+X69wXLyryXaDAaaKcyv7beXix1UF8s2DS+lUTIEBu41suZLrl+lFdPHCUPuhlX/BdteNpk9yW241h2OiBuHG9uMC715PPkBF+t4o31kfKJz4IBfwN0uLnp6lxypWqEbpLrsGBxJgNQyRQt3kwGek866kHmgrTVuBVH+OwUTrPWrF5YcGn7zenWWKpHOR1qyuHfEsyTUNuCrrNMYTZah69mqKcTydT0cdtv1K9VccklHc8Pczt2yismzZlAgyGF5 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 Acked-by: David Hildenbrand --- 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 2 23:27:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13158044 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 71EF8C678D4 for ; Thu, 2 Mar 2023 23:28:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47DC66B007B; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E0766B0080; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05EAE6B007D; Thu, 2 Mar 2023 18:28:07 -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 DBAAB6B0078 for ; Thu, 2 Mar 2023 18:28:06 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A5D51A17EF for ; Thu, 2 Mar 2023 23:28:06 +0000 (UTC) X-FDA: 80525548572.14.36467DE Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id 0B17914000E for ; Thu, 2 Mar 2023 23:28:04 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=TFaKHOzs; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf09.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=1677799685; 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=Fz4rjXU4pv+JoX8GiRxuwd31ga6ygJiOfjuBNAA23TI=; b=zbAnl9rKO2tQp7dXxI+62SHmeBott/xePiLSx+W+KpAXur+7mCaR46Wjk0Y/YFb9NbQHPs lcSO3NKgmkCXG6bzWOyET39A96w5L1rOANDus+pzsxEG7Uv8q9YFpKiAP3saA5mqEiQhkE G8F5PimshvywXD5irj+vcNAs/iTOddI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=TFaKHOzs; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf09.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=1677799685; a=rsa-sha256; cv=none; b=p/W8fgea3itw88ZqxiNDsOIPcyPPiwklV12RjCxBnj6HmUspXn9vuNYL1Tek++VqHucWAn OaUUZCHhBckMcFQNhr9kKscKmDnIjNT9i7fUL0OFRKoOjZn/b4iGn1KzLBsL6wh8xPk+9U gtFb2KTKF4IDPldqgEZGcheb6grffYA= 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=Fz4rjXU4pv+JoX8GiRxuwd31ga6ygJiOfjuBNAA23TI=; b=TFaKHOzs5zZrjEDnSHRp+DurxS EZpK7uL5ROEanWcdSjADz8IiT9IvqFH7WDeg96aXeb7m3m2MRMicspkiYt/i4MJb32izDxDrcXfkR Ds12Y4SSHzRZi2EavEPEHkitO37g6qnc2bqD93P2Sq+ov2YZdiNMiwq8LHIGSBEKfaxEzkuVTb/Li eyQolkb0Tm/6Zpnk/sRhTSjX8E0AO5dabHME4Z4quDrlZlNbzf2m9AK6EB8FSAvjOQwlwch64nCYm vap3IRDQrZhqDi0Vi31lW7yLoGiYQQ7Tck2NBz7gPOMSSu22zuLA/5dPm8V7ADT8iujNfWaqSicNC 2GU4CIiQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXsL9-003j3K-61; Thu, 02 Mar 2023 23:27:59 +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 2/6] shmem: set shmem_writepage() variables early Date: Thu, 2 Mar 2023 15:27:54 -0800 Message-Id: <20230302232758.888157-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302232758.888157-1-mcgrof@kernel.org> References: <20230302232758.888157-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0B17914000E X-Stat-Signature: rz6emoucq18jjsfugdnwjb4chru1e4sd X-HE-Tag: 1677799684-466242 X-HE-Meta: U2FsdGVkX1+TU2KKw5Y0Ukq/O5nWeZjx/FOFABDi7gPkJFqJN4s2morFuWJjFckV3NF61gqLw+aq0qZAADfjzIdRp7OZeaLckotvJz/J8TknwvK1lv/h4jEnzp+rQeKS5LaRdqCBX0WdFMwJeLQsDsPSu2jEeuTc/uFc8waZRpBbs/uITAA5z/hcJiEYFuNinTFsCmqQLlse5iEc5ynmagFHZp9kELs4MhRzJ8ABmbNz3XavF0NRJ9ue9vuzpbQ67gpbMlhkecLuyzxlXlqtc/OOkETkhuW9qweTu+W/5zEdQ/8lcaVX/YizTX5Loge3WlcSVLqUGD/b9eSOaVIyrokkVCnPI3nn3h6qtFmBA2dj3plbflQy531lQegqjiTrWLGPkZjqtTItwL9IVrvP1ArSucFFnDJ79NcgB5vZabadgcTQB9q0AonKqI4oofuzLI49pillRVnJA4o879aq06XA7vedmIp63gCBmEroNqaS7F8NKJ58BjFSWaAqKUYbspmWWAAA6Mif5l9m+BoHnhM8nQcknciRoR+YbpXS/KdyVuy0AGie11xwTTu36KgEO/AD6Dn5iaLUri3ky0SktFVp/GN+JW63b0c5bY+pajZWv8SJt7W8ZL07PWmrVHZOc6CtSU40SHzc9o4DVjNBOjHWAvDEIFr33G4hq5JtOlam3yH1FaWjon/FAn2vC6klatXXVdhnJIqYYQQgsDzv13KrLqFo7gfDKlw9ljBaG/mWJ2CNrPFkM50v423/9TzlFE9I/FKb7h/qyUor+HVjgKiVF77FJ0Ev5SJP3G1uE6XaMB7aaFsedOy6PTXpclGAljqJz6zF6f9TLd6j48N7r+VMMhG+JzuIi8BwdH7B9254QBv3c//rOHDZZd8aDTfrRqxGxZQdQxPDDliaHdwWLubYnzR3CBb3kvEIO8lz1uq2sQymm07H8cFTfUB87ExRw4j2hBDthbhWj+X0cam +ViD9MeF ogUkXkJ5Rbty9CZ6KocOdhykEBY7TtjlwWRZKLF96HvImRr38vaYvd6OU1yDCe/FbTlttLuvs8HGbjtaPYFs9D4zfTdEOctq89aaBafGVDXgZo6vnlWQp9elDN1pzWyaMdCSpi1P3viWhG9uTFVoGQ6h4Noj3sRipu4lX1iGap5C5DSGowwZEMvazYkSulLITlZpFdh1zDVHjVCJF1zFklqE7tlbO3MCq31bGlUoF5NQT88YO/GyKV5EdIEVh4xqfmrkgDTaQfoYzCRCsAy4f6dFXZAnwp1eN3VkqZWs/wri7upnIUUPTaGxLJ6gmCIm69KX6OfVAXrB2a2BMJUGdwnpxy5BEPgHB27vUz2cunQAE4mk1OMxXrCiEchlxazf8R05JWC02wRMN269K8knCDwsFe88QGpRdwNEKEOkWkbRi7OZqqca8zRUgqw+b5jrx++gujqi0ywCUpiQ= 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 Acked-by: David Hildenbrand Reviewed-by: Christian Brauner --- 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 2 23:27:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13158045 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 EB19EC7EE30 for ; Thu, 2 Mar 2023 23:28:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D3506B007D; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D8EC6B0081; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36F526B0082; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1B5336B007E for ; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C3D3AA14CC for ; Thu, 2 Mar 2023 23:28:06 +0000 (UTC) X-FDA: 80525548572.18.B92491A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id 27930180004 for ; Thu, 2 Mar 2023 23:28:04 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=hKi5B7rk; 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=1677799685; 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=Hpr/mKVZzGGQqVrubmxhAsrFv4PlfL2VXUxF3A6d69A=; b=rWYcjQ2CFufzK2Yt9bON0beHSFWasQILuOAZV1J32R73EnXMviKVylSMLvMExwR36nMbge 22TJtHV+dI33hjU9w9K4WIo8+nYV0UYYKEOMOqmDpp4tArJne5bq56Q4miyZBtXKjWmLTT CGu4ImYUaHGEVZrZPgGVigtodbH6jx0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=hKi5B7rk; 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=1677799685; a=rsa-sha256; cv=none; b=LPEc25dBLSYE4C/cZmEjoQXTei09nngCIlTtGj+U30siUQfDxflehUsLpG8IaJBTMgAN2M e0hVyKWIpJ1RvKErSwD8rVUU41izOP4QpoZEkqY6OEQxRJ1in0WxI0a62S43A1xXVw/9Q5 8fe8j70ha4Cs69MqZgDkfyl3l1n6Z7I= 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=Hpr/mKVZzGGQqVrubmxhAsrFv4PlfL2VXUxF3A6d69A=; b=hKi5B7rksyIKLYpIpojH3COwse 6yVboytacnRm0DNMUh5BKMfZwbdWYuNUklJLKFbD4wjEle33GCTpvZJdXbQPCk3hIf0DFStd9tL+t jq4IAgiksjYqh8v8mIireTRU6LNVj2zfYQ9mtUda+GZCTq6XHxJgjkKPxVVTVA6t/x9znl5F31erd JzgAsoy7GHNSk6QSSzDOJz7LMMAQ1DbbEpT234nu/jFOtmuCwstY5Gm50cCZVHGdz0FpM/qmB87KL Z3RJNpaMrZyQyQJFwvIzGInyQpaIjBIYAAKuhUc2yvfiaKNxUBSuS7LOizfLNgOD6cguhCKiDt7p1 C3zX/D7w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXsL9-003j3M-8Z; Thu, 02 Mar 2023 23:27:59 +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 3/6] shmem: move reclaim check early on writepages() Date: Thu, 2 Mar 2023 15:27:55 -0800 Message-Id: <20230302232758.888157-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302232758.888157-1-mcgrof@kernel.org> References: <20230302232758.888157-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 27930180004 X-Stat-Signature: ntogowrhdutoujpo671smzduggt3ipyh X-Rspam-User: X-HE-Tag: 1677799684-980520 X-HE-Meta: U2FsdGVkX1/objVyUs5H2E6DD4bMG7U1xC/jjLRMLqC0Onyp86A2U8arv4W7fuYxPqpX1LI9NHA0f4aNJWyfK8p9iouGS7SpmcXexg+jM12L9/PQMocTFE1dwXaEMcc6NO5WonRN3pu/Zktsj1uNqoek79HQQTjh+vmfZMi9eDhRnGxJFuZAm6E46alKTJViCBecsCf169JOOOBokYogWbbcbdD2qO+aZYwkjSV5K6qslZrw6gRi3F5Kj3wXJCjXhqpndzk7jZIWxpeQ0hhDlgssuAnu1YDTwJLxRUIe81U+uK8hTqTQHeJsSQdZqk6sYYHSu/gxDL7nSI8WyYTHY6JYK6wrUixmxnaVZZa3Wk8YDRXTVzgPT7VfneMneQB7roEuVSYQvK6k4O+aQiKJqZJS6xeo7PTArPqxvwaetcF2MAODy85mIZuwBgdVX2rDUmJbCRVW0AOYlvr+MMX1OZi3eX4+kW2jJx5dfby5vtLyNVteHlO4ERqJA9KQovM7sUrUZXzAAPIqGXQTY3VRSLlKqSY37a0lgnaok5VfQL/R5btOjQsz374xq/Rdh6IpSYVla8GwUzJPhMdFTScS1TlnOOtmlNJXathWUn8lk3YnHIQNjmhZ317r/ZvHrqGO6KSg98ea3v6f1zWjLHfZLxtf1iblcXe7NMhjO761Qqm0Jris+qe1kna80O/ICRRldd1JRYIOiu1mPV9EquhMrsoo1YZlFnSCMltgPSFXanb+HJQxA2F4ec26FFQG9P5tvaQ4xiP0G8oMZHYuOifonhhtMg13PZ+9wJfabqKO7ZbgiZudVj/Sw1/C5T6Jhxs1UGUua9wJtS8pwC5K2mBnxZvX3P7ZJw/O+f4JzGbR8CuOv68w3GOw3msOaN6NPY3+sJVV/VheShObQhPj992EfoHOG/J4SQWB+IWpU7VROeqqyxUy3TGKjf3w3mWaMjPkV33p0Uuuroamg/IxPfO 3+indAsi z/e0L53w2+Mw0Y2tPONvAsPRbEGk+xGO8UPpMsHeNdjoDAid+zOaI92LQFgi7m0nK90ob/xJ58Nrflvcaq2MCjNM2zTpwpSSzg27cut+AUVD+KofZthDhhQDnTUMYuDldrOp0bKL6rV8z06Q6pYpVOliascqn8wxAye2WMs+EtwruR+9fVjkZuaXlrC1AKCyLZ3GjCrr/UeN+PxIjBEib8VDNvgWT3Dcg5gG1zJXdcjno2jcg/D2GmWZXtzDB0oiq4RpBRpZfxYhgji8IdLkaZ7hUcYxRvZGNNbt/QFRhFOdn6U6iDxcPz44PNLcN3bKhBfe0dO/Mdms8D+r6qRSZfESjYWBQnMiAvfAIuMcG7ScN76hFtZowJnSu2G3LzqMim3uwsZ+DmermVyCPHiBlFinShMa5uEh+gQ/r 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 Acked-by: David Hildenbrand Reviewed-by: Yosry Ahmed --- mm/shmem.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 2b9ff585a553..a5a6da51087e 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1340,6 +1340,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, @@ -1360,18 +1372,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 2 23:27:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13158047 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 637B8C678D4 for ; Thu, 2 Mar 2023 23:28:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDEB46B0080; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC17D6B0087; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D1A06B0082; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7599A6B0080 for ; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 46EA58022B for ; Thu, 2 Mar 2023 23:28:07 +0000 (UTC) X-FDA: 80525548614.12.912AEA8 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id 5C1F18000C for ; Thu, 2 Mar 2023 23:28:05 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4Mn4cSCA; 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=1677799685; a=rsa-sha256; cv=none; b=HHhCAEcAtPnStM+E0BJlUeqkaIXSjXdOdSIUjUIG40LklyvIKynu+50B3ZYprTYof5/EqI LP31hJj/sGvSJsgBchK1lKcZVKf4mTAnE2qwsOjwNG+GRv3HzcNPfSkm7D4gY+3uLETp/Q REv/pNooNXeqi+9ZGgLFWFEae3ecchc= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4Mn4cSCA; 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=1677799685; 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=qG5U0uWPFmEbIzb8qGwDd3VP74J/BRogOkPK92T1eiw=; b=6M0HTFDT3MJXlJg5QESaRd2lqZALP0rCOa0AcNNtAR/BaDaZrq7S+DX5NTIGUiaYnBJ28I 9jGUuNjKPcrpPrf3OPDM+RK3/52/UCm+bKMs8lgMSvX98xI+mTgejQONL87gAsqS2H5gdR UyGce0yWBmUlYrxBfibvSuTT1380jGQ= 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=qG5U0uWPFmEbIzb8qGwDd3VP74J/BRogOkPK92T1eiw=; b=4Mn4cSCAgRAwfc+ofEk7syFvU4 lgI+PixYXC7I6rMVPFt85Y4M8oB/dWwp5q6YY7j/3hgM2uh2P7ZtiZ22ho1zzeWefT3wd+huLJpxd mvGW2hfn1RtW61xAcyyeVfH9HN8JlRi29H3roFcGHcEC+b/G8QXX5LxaV7GoFHadburRxTnA/MMf9 +OPgxbeXJdcEcdQlRLQ0xbxT//SyOp14A7a7SO3dbpZWiKOO2+0j1sd9qtehWMvQZKVPoRxZhSOC9 XOO9h5XjMa5XF91JikH0HlR1tccdHYPW2mUwbxqK+PvPIFK+WTgqQha6vzzE6HKxjq0hmzN8pLejD /ppNx6LQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXsL9-003j3O-BB; Thu, 02 Mar 2023 23:27:59 +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 4/6] shmem: skip page split if we're not reclaiming Date: Thu, 2 Mar 2023 15:27:56 -0800 Message-Id: <20230302232758.888157-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302232758.888157-1-mcgrof@kernel.org> References: <20230302232758.888157-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 5C1F18000C X-Rspamd-Server: rspam01 X-Stat-Signature: 6hnrdh7euibe4gtjfkjede1ib51amgy9 X-HE-Tag: 1677799685-140986 X-HE-Meta: U2FsdGVkX1/GuO+egOPjYPugFsW0pTDCNZo8nN1He0hYui0+a54iN9/u6bdGtb/+6/UMa0yr8Qtr3MU7WseE1AmZq4bBlQUq2mc5RaQWYtONqflWF7dBsH32lmma3DAwOBQXdodV+jrfHb2FjZFnmCW+Ap2OTJczIC3tD/oplcNRY/Uz6m7m182x1B5sB6/uK2V7oVJIEtQ19KpGj3V0uATJvZP5uMFeTBYXjYmlc5iziMjNVtJR7awLI57qScjMi/fOOvnPWnQx5oXSYyR60UXrTXPfSf1kzZH0UQjfiS5bHNcOebjUkMMn/Q5hyueRoubcakNK6m7+CJaPaTMW9jRqlreg5evRrFp6cHhFaObKb08bf1PsQAXVgXuDkiEQzRfTakUYZGW7Rkoa7XzHAPaFWFTWjw1Fmakrjm0dt06+kHFmy1T4QPQMyMPhbzkswuhmUnvcy+5hT1UPtDtscevX2u8sspdPMn3s99CANfvMX+pUoG5ekBE7FX1iVQU6PvIu1t28Z9GpmvynMhBmRedybQ7Lcht+708LPdqr8pJOSUKmlmsHJdZECxYHgLYBxcr4l3gs+qyPatOpla5SpaRYpCo8VHez3jNjrkGwKCLYBC/rX8fSpmRJMy0RSMrKsnrRf3DpRl+3x/fFRBaJ25dvqh2Hc4E3CLQani53QkaOHjeOkPyrqiSCilJCXifVT3H5xicAAu2nN+MDVUqxwEvfQZg3usYySop6X5JkVTtffD/g+2xK77CvQZt8IDYayTFXDCJpn8s7lcBT7OF6kDMLWzMwR4alcinib6WiIyU2IpJTLmbWyuJ+1cwdu5qc0R7BNWNjp5gCCyqRdqP3U4AGmVe4F4Zwnf8s3bvt63MkwA6EQK5eeroeiPXS6nemsqWHNciCr6NxofBboZ6v0hdiLN5wmuU1h+51uKvfDdRbLCO9owKB7nzCxK4dDOmZAtzYnDzClSrnJWx2fCr vgEsD8HS 26ldsO6mF9alaR9uXm/d/uPWtDA0H+es+m9SQmNCRJYKr6ASWhWa6WdbsNuFxPiA4PRvKPisXsq8CFbhgoc3Up13bXn/gjZylHd/UIUwD8YUa/0pzjzDLdV45gqtMdnSzagmN9PL+LU7B0AXRqbMcbJp9yqAVwFoH7RBtkojy6Im3YRpsVs6ROzC15qkLZQvogStR0VNWW+0fr8HyI+MBmTiLWRR6Wh8dO3gzl8fSZA0G+7K0OeU/kK9FO6FLSWTNoiAPOMxJ18nFlSNN/C+J2Pb1qdzyGAa8NGgIY0+083Os9JHPNvazqnXwjSgwlIYXY8fT5zps5qpcpJ+9NJBMuZRy1/nRobVIS475zCwe0w3NjfzYrV65ET2CFdreyoPbjOOp1hbMGDHxZtzLGxn6Xf4mfz/0VWICD7Oy 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 Acked-by: David Hildenbrand 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 a5a6da51087e..6006dbb7dbcb 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1352,6 +1352,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, @@ -1367,10 +1373,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 2 23:27:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13158043 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 ADB2AC6FA8E for ; Thu, 2 Mar 2023 23:28:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 199066B0078; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 147BB6B007B; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F042A6B007E; Thu, 2 Mar 2023 18:28:06 -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 DD02E6B007B for ; Thu, 2 Mar 2023 18:28:06 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ABEE5140792 for ; Thu, 2 Mar 2023 23:28:06 +0000 (UTC) X-FDA: 80525548572.14.ACCF5FD Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id 240C040009 for ; Thu, 2 Mar 2023 23:28:04 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="K/eQSla3"; 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=1677799685; 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=skC96Wt8xxhIMwjo9L+gt44Hnic6JkSNTvyHUyToP4E=; b=acjIYc2l8qdgWaXvoKeH82cWlljyPq5FQeeSHimhwDalmyLVeyxXuuouIXe1CLx2BNrvSZ TKw9R1j+wj2wFOYmMFfwjlRl5/k4gkIrbDwvfI2+nhOqMK5nc598KUp2BcrBdK2h3K2XJG MMTA9ZglORrb1KXhaw0Kqi+nxvXKXZU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="K/eQSla3"; 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=1677799685; a=rsa-sha256; cv=none; b=a9s39dOPpYUemD1fsGBVIXljm+Yjjs2pkrc5N3gbhZTw7xeRKmweg5LFc9ge1Dr/Pc1OmY osgCcqMSLwdaFtiEcyhyQ7FbSoy2a+WBKJEzUivSM3r9bL8aqvMsyzwrwoOK6ZbyoSL2Tl Z/TPxAbUttTwlnqJtDhU6fv7aW9fYjI= 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=skC96Wt8xxhIMwjo9L+gt44Hnic6JkSNTvyHUyToP4E=; b=K/eQSla3MTHn7M0Rb9rcMYDVlA e37q4SAkKhrm7U/RKwrVlRksYjpLSQ7cyFhGajl9HtpsHsUn6N0cRNl0Qv09F6TFF8NJALHGbqV9Y MKle2ZzppMMuer2n5cLdK6TEumXDYu//CEasZglQ4GBDSIpbcgf9zrLrspyNLR57fU9TjiN84RzjX DJKtgrXnUJH4f9ErONxxluGJkBZMTUgr6znqZikMJYzDqfZ43mgtSToV2ADG2RhlMqjD5DNDGVY4q QwjsemBTEGNoJzgAOOd9LwEPm7jsyyl3cLget4EvACCEKtoo27Ivb7ie0zI+m3cji7ZAqVl11QKp8 lTov+nwA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXsL9-003j3Q-Dq; Thu, 02 Mar 2023 23:27:59 +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 5/6] shmem: update documentation Date: Thu, 2 Mar 2023 15:27:57 -0800 Message-Id: <20230302232758.888157-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302232758.888157-1-mcgrof@kernel.org> References: <20230302232758.888157-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 240C040009 X-Stat-Signature: agibmbxuo9gnkt7hc9h81k9icahos8sg X-Rspam-User: X-HE-Tag: 1677799684-825232 X-HE-Meta: U2FsdGVkX19y7jj9Glkpqno5rtNf9YBudny9ech8gEXOSkP+vtdRbxL8y0hDF/ZJM3EsHs62OPwfPhdb2bYAVkYyxUIl9bDBL60CEWgPa+NfEyQsyEhwh/98z5oaU4iRsFMqNSOg/PG+LMaVJshfs4VFPdrPtfZH0QZ9C0HwU2fQPcwyfTUceil/g3oJDo7QySNaz1q+V1wKOAEMHZj2N3C/NHUl+WKn1KizqVaoNmwI/5UkBATbkM1HfFLbH0KxlBQhrsd2Pe2EO3SnkNUuN3P4Swpr1RO6H3Crm2fooG59liUucXL/8hbw6H4Tu5lJKb1utsMNcfDOlsDzVtl6CtrmXXHtZp/y4y5jvmaV5DfYT88KGUZS/V8ZXd/4CxDwIeowk6LPY5BjZVdxeJGDn7ot1fA4YhYtoaamZ4e05sLvC6pai9z4lYg7B7NmI1FszHMAV8hcCgNmGser7/tSlTz+Zv9zWJfLEw0+rAilLl//Urmh3sYnFjIvlLy7V1mTyuDZTmfAfQKHTE1Sx28K5Q5CIbCqyoFGIv0Yc9LAUT4PfUr+iPKd3FNxnZ/HOUgcega3FSjbU/4elNiCHb70n225TD+ilg8wB7/pX1YC9ZkCwmMeRIrVPc5ONZ/oVKBNtYPcXjLpL3yzrI0KCpYQ3jQSuX/8qrrBjmxkAFSt/9L0OQaRH7vlmDDe8lAbSFZP2gIRI4/ErNOtaGbI1jNECjdZ7FY4+nxEI1aj9xZtFfv7uF6zMHouBEl49AMDdamBXPk001OoTsBcnlMp/s0TfINwqQqXvXDDVRCxjIPIil2TMdHvTQAtrkvoRuY25CYWrqVtmbKbpB5GTIjw3lc/I4hNLFZsWlH4+UxrysGA9eqL0Ay1EQpdmyhU+1cGBB0Fe0isDJ7Mnl5NiUJb/GOx4YQ81FQCn2gVIaE8XgiKPm8q53vG7GZdlmmdFTnNzqDF8HWN+xhW4n3I2p8mOES bX8C8D65 mbwY+podgarwjMo8jNKaEi2S2+/3zN2bq8ajLJ+Wxp4vT3a0oXKIug1lpAgMUIzNteEFZM0xFjr1Sz8raaL09CMKutE/48zL62wazv4zLogaZyQ+WyDda2sVn/ZuqXkj5k7Qxgz22xgkaKK+yLcOG07q1kQA2l+NmS9vUrVWB4XI22QFlsyji39a0etCUuvBwdjXeDV0TaSFnXCEDdHx5c9hBcAc+Mk4odBJdscUYoE/xvkReCA6vvoF8lIrEScRoztDUZo6gnhzQPHTJG1Bl+AwTA9lEh6qgAmeYVp+Dia57COCIOfET10FaZbqknxGzvaWv5H+WXx4RCp2PvGf2f8Z9HrBofvOFkaganocvWu1vhUH6ZQq/g0a7geaPm9RqClGtu4VhDp0tcHtstKAR6kjMsgQzyUmHgn+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: 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. Signed-off-by: Luis Chamberlain Reviewed-by: David Hildenbrand Reviewed-by: Christian Brauner --- Documentation/filesystems/tmpfs.rst | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystems/tmpfs.rst index 0408c245785e..e77ebdacadd0 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. + +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 From patchwork Thu Mar 2 23:27:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13158046 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 A24B6C7EE33 for ; Thu, 2 Mar 2023 23:28:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A468C6B0081; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 939B26B0080; Thu, 2 Mar 2023 18:28:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C5ED6B0082; Thu, 2 Mar 2023 18:28:07 -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 47FDF6B007D for ; Thu, 2 Mar 2023 18:28:07 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EE39A40F21 for ; Thu, 2 Mar 2023 23:28:06 +0000 (UTC) X-FDA: 80525548572.15.0715258 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id 378EA40009 for ; Thu, 2 Mar 2023 23:28:05 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=TlDiW9om; 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=1677799685; 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=aVGWGg28pehMWy6o19l/TsZGWBXxeVmCZNXdGLwnZq4=; b=U4/+RYh63pmq+83TaMHKVCD4uGzihoG09fA52kf8INtTjhQZrukDcGpD+ctJwGey5jBoeV iCpKWBUBNbiffeyVwLR6EDDf36Q+XTV2j9KsModDjRdcNnZwSLScuj1JZN0kdzukkWuHiO PzSKKfRYOP6RlYEEI1Fpy9aIxG+Rjm8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=TlDiW9om; 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=1677799685; a=rsa-sha256; cv=none; b=vUjmtiSgaSRidVKIOY7b5Twdu1s8VWFZXpB2nSIW+O/TW9AacvTxUtYwQu8gOasvEU+kZn KZhjKGZNCSCTUDi4XekP+vraquIsCstxf3Th7b2ez8QfSH6FdqNYmVagw3q9Y8xlD/z4px 4qLfrj307OPBBYqrQHwWagLhyqJgrSc= 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=aVGWGg28pehMWy6o19l/TsZGWBXxeVmCZNXdGLwnZq4=; b=TlDiW9om0AtjuznlGSshw1b4sC ghR2WXi7V+f5PZ1jG/o45vCIdVVPAervPRo0lvMQJdxtcovf9IN60XRQyXJ1TOSoZDYvbKBXbI/Wi kuqHDamMQIx8Oh2hC1RmvcgDdngdxl8vCJelPxKnPdI6sZqCLJP7oKLTX7HCNfOVjJ+oJWhrHo56l jIjCnoGvXoEsBAierza5C+Z0oTy0fXnLWb9sfdDC4drisylwEXR0+Vwcjgn7AYvnMbzbxgtrQjiQg eoDfsRFufkoQ6AunUMT7LpC6d+FMUW/ESv6NhPIS/cqtmkwozQFqphCo+anHmfRTZfKqu4eV620Lr q5ku9HZg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pXsL9-003j3S-Gf; Thu, 02 Mar 2023 23:27:59 +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 6/6] shmem: add support to ignore swap Date: Thu, 2 Mar 2023 15:27:58 -0800 Message-Id: <20230302232758.888157-7-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230302232758.888157-1-mcgrof@kernel.org> References: <20230302232758.888157-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 378EA40009 X-Stat-Signature: 4yi6h67153iurdi47osfnjrzy6kb86pb X-HE-Tag: 1677799685-284610 X-HE-Meta: U2FsdGVkX19IyuhgqhGimpl/VLI42A3+gAVE8DsX+2yCDvssCn/eO9rzOBbuXCxKmaoTtyiAdZ2NYiHvCn81ZmxEbTXhvc9kb2mkAfhr1YmtsCZ8Cq1ZS35m8fCrtRGP1spo2mE+3R592e6wFY8PhKkoN4wg1AZ0Qb1NxlZaNE0/JBmJ/RNHMjlhoVXf3eD53tJd0I4VrfFI34JQrTXzGG6S/OOhesHkUiMtQsKiJLWPNX8rAUWqMiGu5VIt3L6fFkzLPJZA7V36TQW0Ey3nKk6bUKO4BqnrAZS9c1wOXLw686SnUYeNm8PMkDnr6mTA8/JBWpEpC1qOimkZN5WHY5e67XQuwknxI/8mobej/az0SWTVoi72K6ABG231rr73u2sPHIMNAxQs/L4kvg/U/Ow6AV+YbKuScXVJRSOfI8Jp/9GThpGr/KHwEgbk95Kjcxbz1TM7TP/xOarHxsKB8QMkQHJyqZ/it5CHHLjjf5V/MlnOUxtkSSK1FCCy+zSdEukylBPwNgiwdXZTsnZ6FTSoFgQ/P1PDbDU8b9c4pJpNe00Dx6FOHWGbL/YsSqV9q9wuDNT2kE2kSPNFROU9BvRbv/oGW5C5IWITFJnP3xdT4jxfIjcxsjDxE9HluvCa4j5yJXyHT0YdPYaARsO8YIdtXPJXB9Elk4i7/EozepAkNQPsbwUIWWUsTc0J1zxQgKyiD7YKre2tdVxe4NU8/zPdu5J/zg2LUsIY5Vkw7dzvkahHBgLAyFlvQmswmKJH4lTDnYXxqlOtm8g28gVZt1Y71b70u2e6wUY0Ce+Sayl8NaqeQXfuWahSNSnElvpnm+c7D2Bj5+++q3puhgZy1v46x6WlrXf2eD8aaV/WTLfOVsiMkdXRnbEA9hyyTadMCgfqfDBZ6Jub+8sx2Xn1+a8aIUGfqagHcvExnxj+SakM7fh1spkIUM01Vi8NPE+yDdwPptobwiGL12r+ID+ XJXWTl8I ipXcqNQqlBLtOghM8VD/AhUkpB7pRquaIDd0p7G4tmdLFV+rURcJWCIscXwqflbYsGvON5VvK1T0adYiuln8Gl2N+pQDa/FBNzfxCRL77TWI85z/jsEngkuVD8sDE0zddBmOt9Lu45RpdXXhPJV8rmPSNX1HWiHXcGURNIyIovqcbxd7Ui0cG7ISN5jk4Xb2rFMVrMJxY8erOGtDyiiCGfBLSSu6nMmWQK2AXYz60pPKB9ur7wXZJ7QCLnJoKIsxews4cRkTF4Gu1tYQJzTdHVScZvzMXiz6RVX2c+W5ruUkmtU6n1OyKV2YX+rkkjCMw0h6af5A9YnYYeQMBJ/AFSeE+6AALUFv31S+ixB8WT/EIvHszhvUF5VgDEwY70j7CA0xx8NjjV5WDHK/+fne0acareij8AG9Pt3lN4xnmG+e3rdKfr7Iu4NI/Kg== 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 e77ebdacadd0..551b621f34d9 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. +unneeded pages out to swap space, if swap was enabled for the tmpfs +filesystem. 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 on 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..3cdcbb6e00a0 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 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..21989d4f8cbe 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 6006dbb7dbcb..cd36cb3d974c 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; @@ -1352,7 +1355,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) @@ -2489,6 +2492,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); @@ -3576,6 +3581,7 @@ enum shmem_param { Opt_uid, Opt_inode32, Opt_inode64, + Opt_noswap, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -3597,6 +3603,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), {} }; @@ -3680,6 +3687,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; @@ -3778,6 +3789,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; @@ -3798,6 +3817,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; @@ -3852,6 +3875,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; } @@ -3895,6 +3920,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; }