From patchwork Wed Apr 2 14:59:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036138 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 399BCC28B20 for ; Wed, 2 Apr 2025 15:00:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32FDD280009; Wed, 2 Apr 2025 11:00:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26953280001; Wed, 2 Apr 2025 11:00:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEE1E280009; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) 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 AA241280001 for ; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6B492C1A38 for ; Wed, 2 Apr 2025 15:00:12 +0000 (UTC) X-FDA: 83289414264.08.3CF838A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id B96938001F for ; Wed, 2 Apr 2025 15:00:10 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=DFlhRkJZ; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606010; h=from:from: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=H/LzOSBZMJnPa9n+hJhMKcetVnuAU/qb1xOh1kNA3po=; b=UKAG6KQ98+cZHFOz7ixjcuQuFhRflSHBidbXxbD5oXBQ8TXM8/glRXnnFYHb7aU4eCsCCC 1HZfC3nUCDdhFnvV9ExsKLZ/QmSYAHACS1aPTPQNPF9x9Z9OpPTxRlX78ydsRCTwCyrWin 9T6ubc9b/YCTCkb8yuUEGSvWTLvVcjA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=DFlhRkJZ; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606010; a=rsa-sha256; cv=none; b=uxk8ZJHOHy75/X9iX83EM6sTCT3JubcBQoKP6YiDlDtOqN/4oaLN5Q9hFq2meCb7fKMmMI RNTD9SU+UQ+sskXhGgrEAFzedqgd6iwo1+rf3X2LGw2S3AJCcSoV+QVMkwbmd24jDK1/GH KRXaBL3/zyHkui5NMqVNDnIVW1SSF1Q= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=H/LzOSBZMJnPa9n+hJhMKcetVnuAU/qb1xOh1kNA3po=; b=DFlhRkJZvk0FxUhTFpLMVcqGW6 xG1V3XXL/3wXAn/c2FOYw2EQMYqW/olCsErvNjPUKfLGXt+KADdT2YskzUX3BUzbnyAagDDYzB/fm ZR4Q9IpNbzkJL3GnwtfzS0XcEfD/32j2Dfmitv5ap5a8XrmQ8JcS7Kf2QXPDc3sqfLLqaVqVAynw3 SVXXASaClM2+3ASDNUleyBPQi3HXCWxVaxx8xZiTEgWj5/FavNMrcjK/FGXAxKgWhUbSiBa86JP8X ULsI58AmQLxczl1eK++kle8TpZzr4ssoKT0HwbiRLd+lve1N9BIfdY9N8jDECSQ2yYLh8qLlIA9Mb nT2UhlgQ==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gs7-0PTo; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org, stable@vger.kernel.org, David Howells , v9fs@lists.linux.dev Subject: [PATCH v2 1/9] 9p: Add a migrate_folio method Date: Wed, 2 Apr 2025 15:59:55 +0100 Message-ID: <20250402150005.2309458-2-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: B96938001F X-Stat-Signature: tw43pzdpubdub8fr1jqujgsibg13z41t X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1743606010-429474 X-HE-Meta: U2FsdGVkX19b3SNoMJysE1Tfw66lEdKnVzELc03OZrR6NSKQYRJ7ZA3Dtwa+XbvIbZ5cJ+AgXVPOUe7symNOLo1z/UvBvdDCbztC68mK2Ds85M4PV+5JrLt9VMTmE9sqNsOGCgC+4+0xYk9ncLt2HDOR8BKk6pRBdvzTsAolmXEVKKuhCKooCahooUAwJXlfPfBcZ8of/fSLjKRmLsJosXAVENu2Eo+xGIJvxVSMxCBEdz6S/W7EBi73qNqBzHI9tV+j2UtX4K6WSmQ+4vdXluEGndnTgXMhNcHRIaRenoMm4wfGe9ICqZFI0dNFnI7LmGpJC/YBkLy6Ia/2W63UPvgllftP9qeiWENJnhPz8TF6tUu4zh9fAztaI/oMV+e4Eo6wDFU2tD4AYmwgsfXyGeVPjHJMH4z9qfR9Rg54xYYi1euglSuBFsVG5k0KB7hCgVnHZA95DXUsEIv8hbm2iWX4GvrMPgnkRkVdljzGJbSjQBHfvFeWqiYv6ecGvzR/D+xNv0S88r0zUu9kztjU36bt70YCUbJ8PKVpmtdp+oEqtj+2bC1xOGk7u8+ptKI5fClBO8Tvns2IwlcMkrCx8b6DkFKV/QdrDRkNgYtF363fyn0nUmaZq1qtORm8Gl4zf2Nx3X1ag5uRm5TWKxztlep364P72P91p1BZy26Cq8QH06rcSyJLOxuF4Y+ekrpFlePCNTDbIxrbKRHP6+hQp2szG/F5aeFyXg/c5xwRRgFWydChSqKfpfp3SaGXmq9bexqQQa6ioIC6jZuMb/YjvOJRxdh1F4IVlA3iukd5Zm3PsjZZjr8Ve/GFR7Vzj6NtOv1tGkMbM3etqBTByaqXf375+IhjH95BtU8g88nr4hF24GZExyAtuqaqGgs0simdq2z9n6gKLcIbsramdYPx4tsYmVxpSnnq+GcJP1SiwcXEZGxbmnNQdHzBP9mUWFrttnh13vl5qBE6F0yJfHq tQExmHEF 15bH3t+kQJF/+sCQ4lnRNR/fNegZNvlpoXP/82SXRGhWBw3tsVNNJVY4kzQJNeoltoxxxTBvogHHwFU/EUvmoM4NFDiX8Q1Q4jQ9oMJosFdAfmyYRwlnkmNkMUsI0mywGSYZtJqzSQnEVYqsmlu9X8I0Iuq2OqvgLEvd5qIIY6MOeA0piYSQA2JMBWguir7WtDUZPIHPCOZN+E1bCw1fY0/K+lPmMXZkJ8b01XCIlGHvQr9NcEphoonauRFSKUE4wj1D75nT2HxolrnjYig2C4z4Rs9d/3n7yYqu0I2EbYUI4CSRA96Lp4fTGsidyK1wrMFKh2p4bQ/CUiTQ= 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: List-Subscribe: List-Unsubscribe: The migration code used to be able to migrate dirty 9p folios by writing them back using writepage. When the writepage method was removed, we neglected to add a migrate_folio method, which means that dirty 9p folios have been unmovable ever since. This reduced our success at defragmenting memory on machines which use 9p heavily. Fixes: 80105ed2fd27 (9p: Use netfslib read/write_iter) Cc: stable@vger.kernel.org Cc: David Howells Cc: v9fs@lists.linux.dev Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: David Howells Acked-by: Dominique Martinet --- fs/9p/vfs_addr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index 32619d146cbc..1286d96a29bc 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c @@ -164,4 +164,5 @@ const struct address_space_operations v9fs_addr_operations = { .invalidate_folio = netfs_invalidate_folio, .direct_IO = noop_direct_IO, .writepages = netfs_writepages, + .migrate_folio = filemap_migrate_folio, }; From patchwork Wed Apr 2 14:59:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036142 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 9B120C3601A for ; Wed, 2 Apr 2025 15:00:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB74B28000D; Wed, 2 Apr 2025 11:00:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C407828000A; Wed, 2 Apr 2025 11:00:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F72E28000D; Wed, 2 Apr 2025 11:00:18 -0400 (EDT) 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 7B4D528000A for ; Wed, 2 Apr 2025 11:00:18 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 44C37141B20 for ; Wed, 2 Apr 2025 15:00:19 +0000 (UTC) X-FDA: 83289414558.17.EC65D5D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id 969611C000E for ; Wed, 2 Apr 2025 15:00:17 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UVlnCqVh; dmarc=none; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606017; h=from:from: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=MofhovjlADQCQPqeYMIVdQLieQlnl0tttbSu0oh4ZYs=; b=dzJkVIqnRkjpalbxgmjqwmioWQVuuc6XpHH+FkkcasyWQY4JRep3vs/QBDRI3JR92Q9L8v vH1X3OsADK87aqhlv/BGKPJLBEM3+MJgusKH4bMgpWokzp2FCTyZwhNoH9UY+UfofWgD2S JoZBVq5L6KhVnkQNcHLa63qKjC0NNvQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UVlnCqVh; dmarc=none; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606017; a=rsa-sha256; cv=none; b=uw3l/ZKaBXs6OVDxOdNvXA6ludUZy3/5gZOL7mXWR+ptLSuCtz6psHW/JLqvbhOj//kzmi EyoGFqUPGtJuOE1JNcTte74rVpkJ5uZO+JAXY8iKPaoeSQr33w4ZhFgnvFPdVkfWf//aVm 7v5D4T+Y2xSuEjeHOHx2cNuKM09Ho3Y= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=MofhovjlADQCQPqeYMIVdQLieQlnl0tttbSu0oh4ZYs=; b=UVlnCqVhaQJS4HJzwCd3dfa8m3 Pl780cPiBkPkCd9y3v9/zi1vI+/CXbFmxttgXnfAIt9Ho06rLTH9JbWU2ujRfyWRdj4w2xSDmSdLo 09wjhqmFORJbT6G1iS+TWFI+6KlmKmFD3JcibDzjT10YbPbv55Oc6W55StfRBRrjhYtDIrPl1Q3kH vG24breS4watPawfBwP1ClNNL/BpIJtMt35gD0D7V2Qn5gTZuO/NEjKofMHBlAW9OG3fbTEkNFY9g F6b7XFVKro+YZj02ApnZFeY1Oqub0IzNI93DJO3HjLPyBPG0flfd2Wv8XwqT5w4sqWOhUjHISLJdw 1MOAPOug==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gs9-0kYH; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/9] vboxsf: Convert to writepages Date: Wed, 2 Apr 2025 15:59:56 +0100 Message-ID: <20250402150005.2309458-3-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Stat-Signature: hhya4dncsidogqt4sazr6csmc74w6wm4 X-Rspam-User: X-Rspamd-Queue-Id: 969611C000E X-HE-Tag: 1743606017-693559 X-HE-Meta: U2FsdGVkX1/32c3il8RwABKcaTuA7IsxkinF9oMegyVcAHTOqk5J5N6YNR1FS71bYlvuRoGyCnGbvtL8MVX4osBHdOUvSBmi+F8M8dZta0xdmIoUxtJ1hRh1AUGTXxWgM9VajzAvIGEWZIpL/eWQwP6JYowol7ILVkI2J2hnRPg/Fu0LLWwB97K2UDO6g43/dhXta7sIEWl/tQTIgKp69x7i4B/bZhjkO4Jx03BRQ36VWkTnWW3ofwh5h9o5DJUOdQNzwtj6CoOGqZZrz57fzNYy/tHB2PgmGXgN4ptRhcbdqLxQYsFlQ5IR2nKmtVXvB0HHn0MQ5QFqd4BCowtJ0BcBKXFhXXoTBGmGkzt6uiohaw1R4PfGKS8hYRO6iUUgkJR0kCGppWeCW3bekGbrnbHD901mVDP5Trgh9J7AZJyzT98PLbi1z36Yeh9kTfN2y9AbYBHlHSOkIZr/Eap8gBbnDqDKrNCIkEopNoHTHxJKBCiXKQQD/RYpbpluxb8XMvZjNgjPFsWHMpKAL/Or20viKDVb0RozGX6N3zaM1avZMcQUfDesVzeIHeivU2SR5WSXy1x0P2W6FzGLM4vpuaUq4A3ea7UwNiCxdelsOs1U3CbhWBaXjC3KS32qiYwgjPYwOhIa/76+QzEtoyHFXJXPCyR11e0eFgFgTBg+dHPJtj0M7VXM0cuYfFwbD7J2fUmKDhdvBBNypJECRPJDhHW5pOvSZH1acKubT+UJ0GWMpSyy4k/Np8v5g3Om900hlNf2ku0GyGY66a0l2MgD7GdySfQJ0bWTE8q+o7jwIK8w3+JHPDGuEMbqoEtyeTtk0HL5pvK3PcbU9CM6VOalJqAMbIxOA1fsoUMQ+UZKiMHZlQx6GzxD2YE8HMW+SM6DzXm31PwAeTY7ZBsOiMnI4s+Gujkxhbb0EZ1py2uIs5jBg8b39qGV4FweMdGkPKy46F3faYBaTBePSznLcYZ 01hadZ+J Elxcd+5amgP71jzAk0qL53N6RfrwkOZgHE4vZIDusoAu3TrUWL1FeFyStZJqbjk10sxRwBexyP1m/6cw2KsjzOQgqhr+xfZ7wySdsB6Tr7f9ZsACPy4pTFladDnzMRS+5s53qji01fM8W85WWw5ia3DY7qpbks8KWr80pAJIg+r+xMJEnU8n2wXU8YbTRci75wUdntJZvVazWbTAP8j/dz2w2/yPhD0ujlNTSuaZVO8+0EHE= 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: List-Subscribe: List-Unsubscribe: If we add a migrate_folio operation, we can convert the writepage operation to writepages. Further, this lets us optimise by using the same write handle for multiple folios. The large folio support here is illusory; we would need to kmap each page in turn for proper support. But we do remove a few hidden calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- fs/vboxsf/file.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/fs/vboxsf/file.c b/fs/vboxsf/file.c index b780deb81b02..b492794f8e9a 100644 --- a/fs/vboxsf/file.c +++ b/fs/vboxsf/file.c @@ -262,40 +262,42 @@ static struct vboxsf_handle *vboxsf_get_write_handle(struct vboxsf_inode *sf_i) return sf_handle; } -static int vboxsf_writepage(struct page *page, struct writeback_control *wbc) +static int vboxsf_writepages(struct address_space *mapping, + struct writeback_control *wbc) { - struct inode *inode = page->mapping->host; + struct inode *inode = mapping->host; + struct folio *folio = NULL; struct vboxsf_inode *sf_i = VBOXSF_I(inode); struct vboxsf_handle *sf_handle; - loff_t off = page_offset(page); loff_t size = i_size_read(inode); - u32 nwrite = PAGE_SIZE; - u8 *buf; - int err; - - if (off + PAGE_SIZE > size) - nwrite = size & ~PAGE_MASK; + int error; sf_handle = vboxsf_get_write_handle(sf_i); if (!sf_handle) return -EBADF; - buf = kmap(page); - err = vboxsf_write(sf_handle->root, sf_handle->handle, - off, &nwrite, buf); - kunmap(page); + while ((folio = writeback_iter(mapping, wbc, folio, &error))) { + loff_t off = folio_pos(folio); + u32 nwrite = folio_size(folio); + u8 *buf; - kref_put(&sf_handle->refcount, vboxsf_handle_release); + if (nwrite > size - off) + nwrite = size - off; - if (err == 0) { - /* mtime changed */ - sf_i->force_restat = 1; - } else { - ClearPageUptodate(page); + buf = kmap_local_folio(folio, 0); + error = vboxsf_write(sf_handle->root, sf_handle->handle, + off, &nwrite, buf); + kunmap_local(buf); + + folio_unlock(folio); } - unlock_page(page); - return err; + kref_put(&sf_handle->refcount, vboxsf_handle_release); + + /* mtime changed */ + if (error == 0) + sf_i->force_restat = 1; + return error; } static int vboxsf_write_end(struct file *file, struct address_space *mapping, @@ -347,10 +349,11 @@ static int vboxsf_write_end(struct file *file, struct address_space *mapping, */ const struct address_space_operations vboxsf_reg_aops = { .read_folio = vboxsf_read_folio, - .writepage = vboxsf_writepage, + .writepages = vboxsf_writepages, .dirty_folio = filemap_dirty_folio, .write_begin = simple_write_begin, .write_end = vboxsf_write_end, + .migrate_folio = filemap_migrate_folio, }; static const char *vboxsf_get_link(struct dentry *dentry, struct inode *inode, From patchwork Wed Apr 2 14:59:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036143 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 8E732C36017 for ; Wed, 2 Apr 2025 15:00:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D830528000E; Wed, 2 Apr 2025 11:00:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBC2328000A; Wed, 2 Apr 2025 11:00:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE58428000E; Wed, 2 Apr 2025 11:00:21 -0400 (EDT) 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 8E0B428000A for ; Wed, 2 Apr 2025 11:00:21 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 276B1BB811 for ; Wed, 2 Apr 2025 15:00:22 +0000 (UTC) X-FDA: 83289414684.08.4A29070 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id 92F4410000A for ; Wed, 2 Apr 2025 15:00:20 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="R/MLFsPv"; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606020; h=from:from: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=5XW0b8o2GA0rXaRAcMoHAk0zi9Q3pqKKR/5ZrqK6isA=; b=0LzyZEfRZc1GdWEcxI0kP5TWlHe3oYbDVXN8C6x85/aj+oW+mT9S3YZzw0bRPE/IKd9hJl vsb0WnJOZyDN9s5REo3+vIiZowiA9udZP4x7lKMjABqJlHo+J9VihNDzDAXV02VgHD7Fhv kiHrVi+lNRGTHWu5NSP7FFf+tOdiWOY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="R/MLFsPv"; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606020; a=rsa-sha256; cv=none; b=sc7RjBX/PcjPwQCtcET8eriYXzc9Uykzuax+oYSYze/uvNSQ4FvtNHLfa/IVSQkW6ICGuB QqVHUs4pOB6cRi+oYaodaEO0oSyzw/e9IAC20C9YwQp9cCrwudXn+V5IBjmSgiADRFv0x6 OZ9cjCXr45lLjm2jJrMN+OKvZa5kz24= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=5XW0b8o2GA0rXaRAcMoHAk0zi9Q3pqKKR/5ZrqK6isA=; b=R/MLFsPvz24ooXP3n2jFFdaQXS M3AdX4NhgWKE+Ldr9ttHKD8qgG5GZYrzl4HoldQmoxWhsTna7sbeqGeV85qzgdBMglKSZcZo/qhDL 27mzrVxCjQJEvMLyNxePILgRc7e8EX9LjIZsx1RTe7+xFO4/WYXtZfFZp9QtaI2kspbnodfP3P44a fbnLduvq4PVvMS9Ka/aw11jUuI7aHj0yslB/pG7B/3rc6DfE161Izl44/4miE8Y+4cy2i60FQ4eM2 SOmtlICqt4DAxV3OBU6XtQ/ljD0WkgGJMiiWXQ4KH10ZgdKRajR1ONKHvVArn/PYczuOaMxhaNYYz gU7zsJJA==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gsB-18Xi; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 3/9] migrate: Remove call to ->writepage Date: Wed, 2 Apr 2025 15:59:57 +0100 Message-ID: <20250402150005.2309458-4-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 92F4410000A X-Stat-Signature: hu591ntbce6iscasap3tty8uzkzajshg X-HE-Tag: 1743606020-865967 X-HE-Meta: U2FsdGVkX1936Bjf9xvfeT/jDhXENVdFXn5Lj+iUThqffJ8QL08ybjYXEc2ZALS3PyWhgjPz7f7EDqBXTpn9M0GjktWOQRt7RvxOxtd66q87bRLkbSqjl77/RsCNZ2fALbxvs8o+uW3v5ees+OmU0E1PEB8/siz3coP2f0Wz79jIrjkHN/qAsVXkBNE7yPvf2qWPoRBOqjBvp0eKbv83tSkJFrDDCJIobKhG/0dNAgFfGiXkyAC0I+f1uMTB+Oj11yGBe6qMs2g7ZHHhKXFMm6BvFNQvX6xeMMyBBABxjGBfvyl0RnYZmh49/b5HqHNYbDrWAbp8HoHFfDaLzTkBBIpSfBSJwxTrbyrmujO1Hisvbp+aMDvxlm/wlDPz+CYKX3jYN0t+OeVEzNwdBJJ/nCRv5LkXsdXUrstWnyPX6xFpeYI2t2W3VnogFMllSwno/M0GrbF9PnCPLjeFuM3D0vlw/B8qXD/H04aIXcWk0hvZWja1CvoAFRIL5te0rxOUiwKUIREQJSyHdBhs4W0XX/HZD40qSAvF8ZVmJkZSWS3VdY+x2/9uO+smFI8EXE4/rq2HYdiSZNWawBqfsqPOB1oechtNZ1T1yLYLxUQVLuI8JHxwUfyq9kuDzE3zqq2PKMov2tk4K372+15SaYIzZL+nwEMDMkuFvcTOmU5g6jjCSeYIbbXcj4yOSIyXM7nB8fOm9AkSFABl/SmrCcPR9H+es6O32TAzqYyVcoYSOdUIPj7AlWKEfeTDEwxz6SKDO7h8fV3K9iezQ/i/1lPgdTX4BhB+DSmdia1y0WnbligOfLkRZEhG7PLuAjOFJPuWi61K5BVA+1AE3XSejhhII+McTpI8A+0ge/DTHBqiiBUnHMsJI2BrBxjyRKeD5Pr23ADkwD2FSuzhMqglRTyiw4Ht20G0/Rez8kQPPRMHjhjTbUarir42sKfVZkMIL4HoOMmDpDryG6XCDoP0HhU hOfpYE2Z jB9EB+rXv7cG0NMeTMzpwD+L1RfYSkEM/aktusN1LyOvtm55lwwrvZ9r51qyJc1pyLkumoQGirmp9C/mHYa8yoiz/VpRCjjULdp/957GHd9I7EsC/ViTTu4wZvbVNq5UWIsokBMJIUM5TD2mxnK+SupcobIL67eQPGEXoWQOKSlWrIBXgWsd6JGzvndd3MnQo8Tv5/abi0lwZvaV+0d9XpJN7f4I1rZnh0YpDaHQBIKRSGbA= 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: List-Subscribe: List-Unsubscribe: The writepage callback is going away; filesystems must implement migrate_folio or else dirty folios will not be migratable. Signed-off-by: Matthew Wilcox (Oracle) --- mm/migrate.c | 60 ++++++---------------------------------------------- 1 file changed, 7 insertions(+), 53 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index f3ee6d8d5e2e..6e2488e5dbe4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -944,67 +944,21 @@ int filemap_migrate_folio(struct address_space *mapping, } EXPORT_SYMBOL_GPL(filemap_migrate_folio); -/* - * Writeback a folio to clean the dirty state - */ -static int writeout(struct address_space *mapping, struct folio *folio) -{ - struct writeback_control wbc = { - .sync_mode = WB_SYNC_NONE, - .nr_to_write = 1, - .range_start = 0, - .range_end = LLONG_MAX, - .for_reclaim = 1 - }; - int rc; - - if (!mapping->a_ops->writepage) - /* No write method for the address space */ - return -EINVAL; - - if (!folio_clear_dirty_for_io(folio)) - /* Someone else already triggered a write */ - return -EAGAIN; - - /* - * A dirty folio may imply that the underlying filesystem has - * the folio on some queue. So the folio must be clean for - * migration. Writeout may mean we lose the lock and the - * folio state is no longer what we checked for earlier. - * At this point we know that the migration attempt cannot - * be successful. - */ - remove_migration_ptes(folio, folio, 0); - - rc = mapping->a_ops->writepage(&folio->page, &wbc); - - if (rc != AOP_WRITEPAGE_ACTIVATE) - /* unlocked. Relock */ - folio_lock(folio); - - return (rc < 0) ? -EIO : -EAGAIN; -} - /* * Default handling if a filesystem does not provide a migration function. */ static int fallback_migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, enum migrate_mode mode) { - if (folio_test_dirty(src)) { - /* Only writeback folios in full synchronous migration */ - switch (mode) { - case MIGRATE_SYNC: - break; - default: - return -EBUSY; - } - return writeout(mapping, src); - } + WARN_ONCE(mapping->a_ops->writepages, + "%ps does not implement migrate_folio\n", + mapping->a_ops); + if (folio_test_dirty(src)) + return -EBUSY; /* - * Buffers may be managed in a filesystem specific way. - * We must have no buffers or drop them. + * Filesystem may have private data at folio->private that we + * can't migrate automatically. */ if (!filemap_release_folio(src, GFP_KERNEL)) return mode == MIGRATE_SYNC ? -EAGAIN : -EBUSY; From patchwork Wed Apr 2 14:59:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036141 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 2BA39C3601A for ; Wed, 2 Apr 2025 15:00:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C655328000C; Wed, 2 Apr 2025 11:00:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0EA428000A; Wed, 2 Apr 2025 11:00:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAFCF28000C; Wed, 2 Apr 2025 11:00:15 -0400 (EDT) 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 8A4CC28000A for ; Wed, 2 Apr 2025 11:00:15 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4AAD959BFB for ; Wed, 2 Apr 2025 15:00:16 +0000 (UTC) X-FDA: 83289414432.19.426BB4F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id 96B1FA0003 for ; Wed, 2 Apr 2025 15:00:14 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=aldD+WzI; dmarc=none; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606014; a=rsa-sha256; cv=none; b=8QkNul+NpLOvvj5FW39tZHXvCf8i+7vhW4xN7KkFMl3+I6Iumqv4rVnrHtlW7ZooObNIgv oKt8CFbgBhj9bFjJM7JD622Ro1CST2PaHt48P0ChP11+olUqU3neT/pyKdvyPTaHeGi34b 0iT2hOufBbn0v4FHpCxFRZSeCUV6PeE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=aldD+WzI; dmarc=none; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606014; h=from:from: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=USN/8SwPxGkpN9iKStANYoZJi04hj3LODUnr4I2+Xx8=; b=eNSeAqg4fRQLu0fjZJx03/gdw3/N4Bf9iTkMm0RxeMBssRFeNJhLa68x95U9BwXrDKLx6+ U+14fvEMSHl/e/VlbU9hGrJi3eh7MuRPGyBTNCoZ3qqDEeKaW3C15MBW4SAjSNaPxypPAb qb9TTppd/it6CLQn7HDLAEuCXU+1WRk= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=USN/8SwPxGkpN9iKStANYoZJi04hj3LODUnr4I2+Xx8=; b=aldD+WzI/aKdQ2XEMrI1DtpAyB uXrZ5Dnx/rhBTcN/bbRRqfOX2YC53+ZpRz75qWLyq/1urNcEOc/sxxc6aRf1DOrWtUeZST0atwG6D rPDsdz3NfzG5svTviGHXM5+n0/M+CqRecB+4O3qugWSFiematCWWMs+IbVGc80UFwNmGMuDH5MNYP xHJ9/+9ozytW5lP9Ugm7M2e4JbX3WPxUGItRy7OKJVKFlWocD9Z5qGu77nJE/Lxq+pXQ3VXqtPTRP 36PRWYzQ4cZfAiVLx10GN+rhiM3tnzFQir5/15+eQigFcNP4ROxf+F6Sik872RulOVx8/DHDKhXYI kdfgkjLA==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gsD-1Wga; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/9] writeback: Remove writeback_use_writepage() Date: Wed, 2 Apr 2025 15:59:58 +0100 Message-ID: <20250402150005.2309458-5-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 96B1FA0003 X-Stat-Signature: wbdw7r79yn1ypfeqtcfwoi1hjhae8jjs X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1743606014-238059 X-HE-Meta: U2FsdGVkX19TaCIkZl1+C5NEkV0fufszvamMNHkBD03uHPPZz8kRJYOQkwFMljdKm7q32uwOdOO18uyqLbnEHv22tYBEA2xwRTIQSx57KkekNJpCvNxcIL8a5qblM7S22mv9ZcdI7nrLGhTOR5ixM2dxbYBQcPXM7IoXiJdpHwHDDQgBL+SFJHrb6XMuu+lp3qpQoBZSjacIDyRCRzUO57/4wVH/5Q+XrXwr2u1N/Q/+ZK6t6VVVQZzAAjoAVBWUMwAmgsZaGVPv+M85YROM9L89ZOJmr4giE3ByZr3p/BgjDZQHqa9Pj/yPdconIVlyNFTKePIqZJOUy159rmxVW4PIa3yvv4MlrJFJPo1bc4DmBGKQ2qqX9FqENPoBiR9hQsFl6PFP5HJSi5xBtt0R01V+kzIek8FZRh+Flp+lN++2r5vvmmniej5YVKdn0Rk6Jj1IHsK2kn4gn4cENeUInAXCYIcK1qZbamP3rh6iOrVpj/ljZ7qWe6AK/FjEj6QsqFdBp9OHFrFApnwxrOBJ54RUSJcbpGOK+/L3IgIOymTfqFuQ4/Izp+s97PstyD3oH/RcxfoAuopgd0iuTwOCUZ0vAN4A4yog04SUTIhZs8MJ7wj/5EgnfmHzbC1+kRcxuJQVRb+BHRY+6tymByYyBPmROpzBhzENBDpBk3DAJf4XdEQLucJp2CL9IhYeMCyZ2RK6UGwen3XDQWLHMxhRdJupOpvGL5Xn1UB8212vlMu3BhkmWgzkYs9ffaaSX4DLs3bgRRkoVIcTQkg8LZ0yWt5mC6RLcvhxhwDqCXCu2deC18OwHD5o2Yx0dshZyga6cY31IzXhIsN39/rfckT7vL6w5EXEQcUR8+Evd5PjxU+OfRGRhM02A4v9pfhUTvBBBki35L/ePb34B2UELoSjG5/R9zyJMlSOJM55iSpOMB8iTkorqWwTsivCYeS/VRj/GvBxniOaRo8j/HkHhQM 9si715La iUnfzf7v5eupqq8MwkzbefABcbuw4y9yxzFGcGlY1QfuIhhWxc3jHYGy39aW8O+MKy9DMoayu6KQIhOT9/KOb+gAEQhIk49J2/RzmoPmLK9HrWlbbsVIuFeuoJxoT7iqZn/O2D6LoOYtdDsuG6TKfsuqn1udXITRJwTRxmuFltyFW9tbLg4qxoM7M5/lI9R2tK2o9Ufou5lO9LqLMj/1kiIek0WarkLezkQXTZwnmSi9eqUdj/dr7VjxxqkxAPebLZOn6uJpJkyCRsfVfzwoPouPXLB/5aPkVRyUt 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: List-Subscribe: List-Unsubscribe: The ->writepage operation has been removed from all filesystems but shmem and swap, neither of which call in here. Remove this alternative to calling ->writepages. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 18456ddd463b..3cf7ae45be58 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2621,27 +2621,6 @@ int write_cache_pages(struct address_space *mapping, } EXPORT_SYMBOL(write_cache_pages); -static int writeback_use_writepage(struct address_space *mapping, - struct writeback_control *wbc) -{ - struct folio *folio = NULL; - struct blk_plug plug; - int err; - - blk_start_plug(&plug); - while ((folio = writeback_iter(mapping, wbc, folio, &err))) { - err = mapping->a_ops->writepage(&folio->page, wbc); - if (err == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - err = 0; - } - mapping_set_error(mapping, err); - } - blk_finish_plug(&plug); - - return err; -} - int do_writepages(struct address_space *mapping, struct writeback_control *wbc) { int ret; @@ -2652,14 +2631,11 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc) wb = inode_to_wb_wbc(mapping->host, wbc); wb_bandwidth_estimate_start(wb); while (1) { - if (mapping->a_ops->writepages) { + if (mapping->a_ops->writepages) ret = mapping->a_ops->writepages(mapping, wbc); - } else if (mapping->a_ops->writepage) { - ret = writeback_use_writepage(mapping, wbc); - } else { + else /* deal with chardevs and other special files */ ret = 0; - } if (ret != -ENOMEM || wbc->sync_mode != WB_SYNC_ALL) break; From patchwork Wed Apr 2 14:59:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036137 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 24394C36017 for ; Wed, 2 Apr 2025 15:00:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC529280007; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1C5828000A; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 994D6280007; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) 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 6B069280001 for ; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 810B5BB53E for ; Wed, 2 Apr 2025 15:00:11 +0000 (UTC) X-FDA: 83289414222.20.A39E830 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 3A98A4000A for ; Wed, 2 Apr 2025 15:00:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="XHNF/9U/"; dmarc=none; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606010; h=from:from: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=UNBvZu32+wbhgVGJ/9V2hTzAlK5EbvmAK/2hRd+u46M=; b=G4v7YFssMOrZc1IlPiFQM+iuBvs6fMGw795Z62YPaITRyliBG9BO59R76uT6M1KjmiAv8u CzpQ6PEdfpICqpy5J+Ej2p+bBmS3KIHwvwKWnU8yusZsd1znYQwe+7yuwIb+avK3NzdA3Q SSwsyzZeWtoDvUKlDbFZSkKc0zMUh9E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606010; a=rsa-sha256; cv=none; b=24D+ZdnkjlK6MZDGd3Ee/LPVbIXP5ScbiqOvJw4/WEL821veGV152y+h4Ux8p/sxKf9jtA o3uz6drpAUOd84nDEG7jsWQSB905qvQGE0D0ya17f1EZZKXV2sZHhuUV2gJq1muWPuk31C qZVqHot0FifoIQrXdSRSJybb0yRuzfU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="XHNF/9U/"; dmarc=none; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=UNBvZu32+wbhgVGJ/9V2hTzAlK5EbvmAK/2hRd+u46M=; b=XHNF/9U/du9de/iK9s+5I0zADe O+pcJekTrVv0miXdwnb2siiLrxPQ27obx126RH95lkiAfLPAAiw5DvsERoraJ1GxJ5zwc0OJN8MLJ mzz6kW7koritqrR8/48YFJXZ8pTDxscVtOMVpcZEwruRJWoZgw7wP6NWFJE+OwtsX98cnjHp30+IB mBwUPemgYHjyVvwXxn6n+4vuYbWzk0y5zi0LnKrLC/Wp2/1dvYNXnRqeKPpFabINxRCSZHqn+ho1y MGDRzGBrEvmxT/3g7p5MVUDU9NOB6UTqSjIzkQtteVdvzD7oY9ZCxp71gpUWpcba7+RjXi61HPi8L 4YWmojyQ==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gsH-1u8G; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 5/9] shmem: Add shmem_writeout() Date: Wed, 2 Apr 2025 15:59:59 +0100 Message-ID: <20250402150005.2309458-6-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3A98A4000A X-Stat-Signature: 6sjs9hz3cs74b4s3swk5y5ws71jdnut3 X-Rspam-User: X-HE-Tag: 1743606008-743506 X-HE-Meta: U2FsdGVkX1+cJPufA5blNQmyPQClnVW65B84VSujoUYNqBH1bPyLAZEaVjfSiJkTlQ6VpozurqLotlc6DMaQgIQ25Yzxl1MDGzM2X1eGIcxtkkAYShkiNCT+mAZF34ERScWzMOuQx5/iB7ocIxgtyimxOCQS1pRZ9jQMBVbut8348B8c4agJFqaEp9pLPcuTvkvhr/5sttxy8FLPhMb9QZAnRWE6O+Yy5lzaQ0x9wtTbwRoL31BAz7H0sohNUKOViRLMUqiWbvLTK2zo6p9+CUFhP6jUh3B2sDB43FwYF5ZIna/p4sUfTBUz94lxiYxBDKVffo+QjgNFo66kUgM4Qn8HkNKtgIVjYCkEC0gPeOjN+p/caCvAEOb2Cu/Me+FZ2oRctSnX5rDanR/MsfLRYCR1wQY4L1EbEhOygp3dc82VhgAlMrBtWfyue/g6UaJsx9gin2aEReWCcti0zCtcBFN+qT7MQelGikYr/Dnob+xgkgUjO5PiUBU35aFIQB5H1l3hmARQ4dhqOs0xj6c6kvSvtFPOdKV1sSFIsxyeBynZc2jt/rPI/wRbISOHyhtuX1ZJ/PhjTDEj4cnr4mfutpNu8KqespG3HS9K37rCb5indTVDfrDnWj2FQtt4awrKKadMu380mIZ486B573QykmrA9A6aJurr02NtVbDyuRn9+/x+wvrnK1U19TMuqg0XbPMbLAXNbow+Jqe/5HL85iW6FJpWaqv4AjCG/rUms7fBgD/VY84hHmYYrW64BGhh5N+FmuEzndKeYAy98j8P89X49EaEFt2uY3yz/rVrlB9vKa4cj11AJlfxYL0c0VBI5l6UWPKGGYLUF/59ErUSTr+Q++FnwErQxp13BAcJHUP2Gv7+jKAH+ISqeIHxNOr3a7xsu2o+IqtAHWrM6j64rtRGvaWlaq6a123+vBZkUDa15SeZeWsGGfkoP3S8drje6Iwy0th17nWpGjolSVO oIqk2Pc9 SNrGspL3GME3bezjN7EVq/3ZoNGggdbIaif+J9qUfdBRCdP8oBfHD0YHOGc44A/ENuDOx5iDdxd4kUA6Mud+7YlMke/vZ370aRhWv/GeK7xmYnWEfVDy8wKl3BULeupbvJZ4aRVOsNaVZjWaHeTf1w9lka40+STq7KQQFzRIYy0wiiPZITU8l4DfTOZqmEtAvCYLUJy+OVROazVqaNDMmtiMhjVo8HRyk+6BWsOI87/4X0gjQnG1iyv65Bg0dtb6frnVLycSrVxWwER4Kp1p1YMRnIkiSpS8rKC48 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: List-Subscribe: List-Unsubscribe: This will be the replacement for shmem_writepage(). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/shmem_fs.h | 7 ++++--- mm/shmem.c | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 0b273a7b9f01..5f03a39a26f7 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -104,10 +104,11 @@ static inline bool shmem_mapping(struct address_space *mapping) return false; } #endif /* CONFIG_SHMEM */ -extern void shmem_unlock_mapping(struct address_space *mapping); -extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, +void shmem_unlock_mapping(struct address_space *mapping); +struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, pgoff_t index, gfp_t gfp_mask); -extern void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); +int shmem_writeout(struct folio *folio, struct writeback_control *wbc); +void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end); int shmem_unuse(unsigned int type); #ifdef CONFIG_TRANSPARENT_HUGEPAGE diff --git a/mm/shmem.c b/mm/shmem.c index 99327c30507c..7d377ceae035 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1536,12 +1536,20 @@ int shmem_unuse(unsigned int type) return error; } -/* - * Move the page from the page cache to the swap cache. - */ static int shmem_writepage(struct page *page, struct writeback_control *wbc) { - struct folio *folio = page_folio(page); + return shmem_writeout(page_folio(page), wbc); +} + +/** + * shmem_writeout - Write the folio to swap + * @folio: The folio to write + * @wbc: How writeback is to be done + * + * Move the folio from the page cache to the swap cache. + */ +int shmem_writeout(struct folio *folio, struct writeback_control *wbc) +{ struct address_space *mapping = folio->mapping; struct inode *inode = mapping->host; struct shmem_inode_info *info = SHMEM_I(inode); @@ -1586,9 +1594,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) try_split: /* Ensure the subpages are still dirty */ folio_test_set_dirty(folio); - if (split_huge_page_to_list_to_order(page, wbc->list, 0)) + if (split_folio_to_list(folio, wbc->list)) goto redirty; - folio = page_folio(page); folio_clear_dirty(folio); } @@ -1660,6 +1667,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) folio_unlock(folio); return 0; } +EXPORT_SYMBOL_GPL(shmem_writeout); #if defined(CONFIG_NUMA) && defined(CONFIG_TMPFS) static void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol) From patchwork Wed Apr 2 15:00:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036135 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 D4072C3601A for ; Wed, 2 Apr 2025 15:00:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32A5C280003; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DA54280001; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B95C280007; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) 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 CB6A8280003 for ; Wed, 2 Apr 2025 11:00:10 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8A064ADBC6 for ; Wed, 2 Apr 2025 15:00:11 +0000 (UTC) X-FDA: 83289414222.07.074CBC8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 41DC314000D for ; Wed, 2 Apr 2025 15:00:09 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Rgpmie3P; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606010; h=from:from: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=HxorfBgE1Uv1byaGENr7pDp1WuWnctNAqk3G3c3CU84=; b=iAB6FVNJ1ZJ6ofjKSL9nEi0Gp1DVbv5ythHJWHrJmOtolhFVYaL0VxhPgH5ev6u9aIjXFZ 2yY9MYN1SvMKDNzZG+G7l6D2hGvm0KxLtD1K/PS/rMjsdSNDsa/JpBeWcpwA6ra2h1kF+j J+ON5OE750jWwwKNU+6o1WkbRDhiq/c= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Rgpmie3P; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606010; a=rsa-sha256; cv=none; b=L980fOXI3s14O5JGjkRT1DFnGYf64pDmWvTEXsM8srjac9BDkNbuk5YHLpgJtr0VvqP7aa h2ieTWMRzPgWahDqauPprB34pwqwVsqaCKIYBk+tCB1pjta6ImYhwGEHlDMeeDojhC+Z3u vW1+UyirnPUsw887JAo2NzekdikpKT8= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=HxorfBgE1Uv1byaGENr7pDp1WuWnctNAqk3G3c3CU84=; b=Rgpmie3PxYC1mfYW3w8XJdLFLM 68IZm5NGrCaClZqC3nKJYdIKGsB9h3JMsYOLPPY8ATYR0OcEt13uXZk9CS0jPSa/6/OEnVSnp+edn JtxL3K6k/cAaAPnIWeuw6+iwIVR25bAFZBbxqjronOrOtc8H5iobhcWmrZQdGWb2o0JqDsgecbGEB HfdWvIXKNnyRerhjAo32CuQy3pHoEKaBz0FHeCA9ZaSmapfUsfM+zxb2hRq+btwmZYOlie2LnekjW vQoPBKxXlold4/4j1Yc7w9yTYhuj1kWqrWw/hO7N07E6HYSJUOZHneXcoL9DAx1IweKyALy4yV8tG M75fmUIw==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gsR-2QUj; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 6/9] i915: Use writeback_iter() Date: Wed, 2 Apr 2025 16:00:00 +0100 Message-ID: <20250402150005.2309458-7-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 41DC314000D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: wdc1rjy63aw1z6nuwerxrx8a94otrusa X-HE-Tag: 1743606009-393146 X-HE-Meta: U2FsdGVkX18Ow5jtX/JFpN+R2cj/fft3kBhFoh6XtlAh3CUKuSJpiKkGC+oNXA7++cWFji6ooaof0h1Bn7X5rZVuNUBE1We1gBql+KVC/E5K1TrbaqChTRmn4j1zQ2lhu0cNdPp8Txh/AGDjfr8llCx+I99pEcR3OwX3/iyLgoopV/4SW40JEE5LEA5v2SkiKZO+jt5F/E4U+9OZ7DtRdkgEpyBB7uF+3gmCPB/wEMHml/0m4SCZSH48DRqhBk7mj2HgGyqBmt5om7lkIbJ7HjYSAQYuYoOWcuyJrNisqqo4/QH41XocrzUX6kIUCQQoBVDiq1WtvxyKykjNU/B4BdwKSX0g92aEkE6ZYgxbUPdqDPyThXRyxmWNqx235yt76MEszw/p1UM/C8xGgj5ijZ5R73Khn0hUtQjgyuSAJ3CMo06O4G4ECYek87w6g5IWe6Vhnws2CUU42ejnbayG6SWFW+A3HaYerkjvoQGLyiTvPmhf8m/EWyuVAPs4wQYwNBumELdh2qYZH2rujZ/HPwFEAjy8tlFkkVa7VFpYGL6MMPN2hnEsm7t8t4rS52XLeoqvjK9W8qB0bUz8ArRj0dVKnQqEg34tXHEBcdwCTLLtHsYouPC69mZB+SliP3xKdkmbYCQUWvUy/zcqrA5+MEvrDLKJ6EmKXvGF301LIdcFhtHmMGO241kxrYYOcQ1sEYDAlevbSl4uGXY+z07BPZAs6MTboKGBKS5nQUnPCyVSBQVH7yigcdvY9+4pImIyEd8RW5U7QT4hqhpP61/6fOprUL+mnJTifFrt5458BWWjBUZo11G+OPge3zC7RfS+qy+cbdiCS6M7vO9xyeheL7TCL96RKLXWsC2Ci2e8sa6KYcDtDLeIWZj6DNmfFW4ne5xZechEZpRod0RrR4XH6xRpk6YGKqvArtGhRPKEIUiPhZI+qvce6HG5yCK/lEXcWovi5cOzOKtRI1FRFc/ tXIeuRMI Ikedp/kEWDRjetPyfBZ569k3UsqQsh3dMpzcIgAMvvxz9WuQp31ZaijtAZTANAg7Bc8GsZ4qZoKtvFSW+Iah2ToCjj3DeltiOx4KuUymk+siU/1PA44SRnXKVUxE7GxehmN1Bo+CI8GhSEip20ap0JdJSX3aGIVR1ARChmFsQfq5EQtr7Z6LfwzSlff3P0kZRZsCqpwnaITyYB5VKOyNFQjZCZXs0oGBCPmXVLx9S0HU0Qwa0r0I6rXSnOstZLG8s5NVOsiTHGzpzfvJZhnz4oLs56tSs8QfTr8Qy 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: List-Subscribe: List-Unsubscribe: Convert from an inefficient loop to the standard writeback iterator. Signed-off-by: Matthew Wilcox (Oracle) --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 32 ++++++----------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index ae3343c81a64..5e784db9f315 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -305,36 +305,20 @@ void __shmem_writeback(size_t size, struct address_space *mapping) .range_end = LLONG_MAX, .for_reclaim = 1, }; - unsigned long i; + struct folio *folio = NULL; + int error = 0; /* * Leave mmapings intact (GTT will have been revoked on unbinding, - * leaving only CPU mmapings around) and add those pages to the LRU + * leaving only CPU mmapings around) and add those folios to the LRU * instead of invoking writeback so they are aged and paged out * as normal. */ - - /* Begin writeback on each dirty page */ - for (i = 0; i < size >> PAGE_SHIFT; i++) { - struct page *page; - - page = find_lock_page(mapping, i); - if (!page) - continue; - - if (!page_mapped(page) && clear_page_dirty_for_io(page)) { - int ret; - - SetPageReclaim(page); - ret = mapping->a_ops->writepage(page, &wbc); - if (!PageWriteback(page)) - ClearPageReclaim(page); - if (!ret) - goto put; - } - unlock_page(page); -put: - put_page(page); + while ((folio = writeback_iter(mapping, &wbc, folio, &error))) { + if (folio_mapped(folio)) + folio_redirty_for_writepage(&wbc, folio); + else + error = shmem_writeout(folio, &wbc); } } From patchwork Wed Apr 2 15:00:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036136 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 035CFC28B20 for ; Wed, 2 Apr 2025 15:00:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF812280008; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA829280009; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A8AF280008; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) 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 6B34E280007 for ; Wed, 2 Apr 2025 11:00:11 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 900AABB5B5 for ; Wed, 2 Apr 2025 15:00:11 +0000 (UTC) X-FDA: 83289414222.04.22716E3 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf19.hostedemail.com (Postfix) with ESMTP id 4C1B11A0016 for ; Wed, 2 Apr 2025 15:00:09 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UnwirFlG; spf=none (imf19.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606010; h=from:from: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=x5fMthl+YaILM39iz9o6tccRRw9/3DVe0YNJSzzz678=; b=P73oiCQMdG6YH2d232MQAnOgGWDapn1MiAUU45gmYh77a+gz8lX6OjcU4AiPONRCsYeXQs 3S/zMvbexVAFitQ3sbcakWLLUGxO0Y0tB/G1K22PZNhGdLJquRTt5MsfHzvpT7cGcFrwBk TetBVKHFKFM1GEqJnjBnXnaktvtisv4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606010; a=rsa-sha256; cv=none; b=XqKE8Y2XocfGJnbTVVlTGWsro5UO1L0vj6AmPPS1+zETHUr9AMZRdtQaLSgd9e9P4eP8TR fxpTrgyBoO8IcRrpLcApSyO8KrFMzLfgvFpTiJKez+PM6JALya1CV33tGmywudubqyiE7/ sOdYK13fe1eG9lVU6N+jXNsAOcli7gM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=UnwirFlG; spf=none (imf19.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=x5fMthl+YaILM39iz9o6tccRRw9/3DVe0YNJSzzz678=; b=UnwirFlGTRxdERwCdAhFqjsRYZ QoSUv85elJbet28sNBFxLnZYAHDmULxGIgfzgqPFxMCqUmRi/upx0/9/QDXW2BE8oS/QpNNoA1x5h p07RGrO2jfRAI4drMHFoURoaWDb1/B0jPKUN7Sd64RWmVdqDj4rm8hQsoNnTpxEpXm8fyubWc2VrX eiqEIVwY5723zFJd5POxZpsbkfU8xSLaGv0a8Px+rKDZVDIcfCHP2nOwILjdrTWfrAfrAAydB7KOR q5rOnmzK1YhElfHfdv0FsVGgt1vHLqsL1noYlitjyijpBXPKv7CIKBb0wChTCqjI7oejKaw7284Sn yzDMR8Lg==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gse-335e; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 7/9] ttm: Call shmem_writeout() from ttm_backup_backup_page() Date: Wed, 2 Apr 2025 16:00:01 +0100 Message-ID: <20250402150005.2309458-8-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4C1B11A0016 X-Stat-Signature: 119t1a4bcurd6h5utmddtu9wjjobpf53 X-HE-Tag: 1743606009-96595 X-HE-Meta: U2FsdGVkX1/YnxyNnyKADSXZuR+HaU8r2Fi6VgzCYKBORO7H4QuEviMEBB2i1f1FUdnV49/jgHEWMv4iavDXzo/aaz3HwPqgLq9fIlvMTcpwMc3CdTLAXN0br541d7C9PSnencoQLS5xzl5HPAO7L5tOpgpbMGXPqxyYKSI1AGY4LB3Vh+ZliLGOp0rDJuS7Old7QuOEJgaiMzDT99i620TBMBB1GE+EjdKjrX0HH6vxJFrIRszf0HOIn8SKhztIPs47G8jqIh3vhABofUE7sZBFD39G5EAa9RIdw3+m2rWQJHr6wHpq/k+8TAYMsun3S+ixaTNHE2bNc7jFxOTYw2G8XBYX2gT+Ld9shhINXQ3wUT0ipn7V2+5ArLB78140zlBQnhWdJrWR+kipAoPKQAJQ/vvel83Qp9L3awVSlB89Xp0+WhWLh/CQlkyAPC/+BoLKFAdHOcp09PH3JzKzU/gw3gMUPZHl3EVA4At9svBbG5SD5bUBYbIi5VXvAg47sT4BahHHsXQUEfUZ1jGgynWAlLK2djy9JoAmR4UA6gDFVFIhCkvSV3o6N8XOSAC2F8XTDZsF+d2A+nEv7ddsVEOo3WS05hMsChiwc7Wnh0VlxsbB6aovsTkjmogkY26iQjkwUhQoUXxnvuMtzMxrQzDKnIcEhOKqcMb8KxfIRCoub1i1o+aMjnxfYO4n1vn6FfMe7+6S3jVaWC/+S5lTT8K8eG/udOVMy5G0JiCaykeXlPcMIt2ex1xl5WTE/FY4KYGbqGEpz+52Sl0AvvDbdXNO1jR4vx9sNcnf+y1W1clneC9x1kupKt6MxCQW+ZXXLt3DqEAxYgEpTLIPK5IaimCTG4/KLkUDXU5xvhdovh6ZwLFRe/USc1glxs5CFXaFhwLNBUQl07a9c2hcLi7kOGcdx8+OPvu+BsHUKZXrMKp/BaLYRu2N3vc3LFb8+4PNLOezex22GwELvWnRl7x JwHC0Gvp SgtZ4qN2OdWsFDgMBXyQfn14tz+MVYlaRNEhCf6h6K3zkKqNBerE67UiRKG8A5+E46SzUS+BmeKsGZxcPb41zMCQf8uYdoyLc+mvk8WZSWZcuW9v5runcq4LCYCcHK4jWSCB7KUw3D+KhD8ZilfPk1Fg/H91AWVsNvCf2Ltl++z6TjVcOop1Pd0xF4S6Pr6FSRPllDKmbMcGkQ2BTwczQK/T5IApLN/zbvCnGTezDxx/Q8Hmlf1ANVZ4v8m7xkwKUKDzgWL5X38uPKnhQfdnRb6zrfanMVWlIlrQz 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: List-Subscribe: List-Unsubscribe: The ->writepage operation is being removed. Since this function exclusively deals with shmem folios, we can call shmem_writeout() to write it. Signed-off-by: Matthew Wilcox (Oracle) --- drivers/gpu/drm/ttm/ttm_backup.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_backup.c b/drivers/gpu/drm/ttm/ttm_backup.c index 93c007f18855..0d5718466ffc 100644 --- a/drivers/gpu/drm/ttm/ttm_backup.c +++ b/drivers/gpu/drm/ttm/ttm_backup.c @@ -136,13 +136,13 @@ ttm_backup_backup_page(struct ttm_backup *backup, struct page *page, .for_reclaim = 1, }; folio_set_reclaim(to_folio); - ret = mapping->a_ops->writepage(folio_file_page(to_folio, idx), &wbc); + ret = shmem_writeout(to_folio, &wbc); if (!folio_test_writeback(to_folio)) folio_clear_reclaim(to_folio); /* - * If writepage succeeds, it unlocks the folio. - * writepage() errors are otherwise dropped, since writepage() - * is only best effort here. + * If writeout succeeds, it unlocks the folio. errors + * are otherwise dropped, since writeout is only best + * effort here. */ if (ret) folio_unlock(to_folio); From patchwork Wed Apr 2 15:00:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036140 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 95D0DC369A1 for ; Wed, 2 Apr 2025 15:00:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F13B280001; Wed, 2 Apr 2025 11:00:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59FD828000A; Wed, 2 Apr 2025 11:00:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4420B280001; Wed, 2 Apr 2025 11:00:13 -0400 (EDT) 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 11F5828000A for ; Wed, 2 Apr 2025 11:00:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B4EC2161B78 for ; Wed, 2 Apr 2025 15:00:13 +0000 (UTC) X-FDA: 83289414306.21.4DFB60A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf18.hostedemail.com (Postfix) with ESMTP id AC65B1C0013 for ; Wed, 2 Apr 2025 15:00:11 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=itCQ22Ts; dmarc=none; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606011; a=rsa-sha256; cv=none; b=ihc8ptDIei+7Uv8CfVPgQI8jl00MkG7pttH4IoBA5mPbb309m+r3HkdW2ycv6OP5Y5xnIS agxrk8mi9KCfhstLpR98GbIvh87a2Z90C8Tg9ufMfqCwXXmjMWxbQjFe3s2MDOjGnq0TCL W8picpIFdZ8d7uMpadiHN3N6sLXVdM4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=itCQ22Ts; dmarc=none; spf=none (imf18.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606011; h=from:from: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=GVXJ9CoqQx/pIpf3FQPir+UyUtnBDDswwBlUb1tywgg=; b=jJRxS3kxQNhzZpFwTgO/RFwPcuvZkZEBoJ7Aev9p4VH92Jdc2C2JnM/GytzMrVakTdglQw 8EqXHUkRRtIZr7hqw3e5HkbQZnESfWY+v4rIcAVjTW+9hoNsyc1trc2rgdzzofM0V9hDej o0JNGPsoBkPclF8d/VRKMAg/mvnbn88= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GVXJ9CoqQx/pIpf3FQPir+UyUtnBDDswwBlUb1tywgg=; b=itCQ22TsKCGEi7SS+DASJiYifq igeU+PIWCAXoCeY9aQW7mYN6rQR/F3VX+s8opkz6QsiBHgVv6RCU0yfgomgAxXRFqWfsUxml63U1e /yPtClKJxj3hSw3An4t7+YmuqoQetQ9hZw0DNYF7r0HCkG7zczHgGIff4ho5yjhQAE9dxN7jE/Xb8 aOw9W4LEBIG/NVFL3ocpEkooBeLXfrtQJNLaFIuBlvWjlKsxDYcYk2L3su6bdaSx8Wr+k4/e79dLH //BCfezd5Gnxy6Ivcmd0q0Wmo8OHGop0Fky5PGKXe53HV6w4RWeZio6uabS4ebpCbXCEyt/3nPra9 16L1QOYA==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gsm-3XPn; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org, Baolin Wang Subject: [PATCH v2 8/9] mm: Remove swap_writepage() and shmem_writepage() Date: Wed, 2 Apr 2025 16:00:02 +0100 Message-ID: <20250402150005.2309458-9-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AC65B1C0013 X-Stat-Signature: wcbqb7dur5ue3py3qgh4rczibzsi38hm X-Rspam-User: X-HE-Tag: 1743606011-907775 X-HE-Meta: U2FsdGVkX18emrNb2J/XwxtwVqgKOswWLL0Hac8z1QIk1JnAxsG6f/crCSQ7cORrdpVaUPpj2kDGclr4rS1zlXBxUFEM6wEl1CgK38WWZxrZLmabO8QRxzq181MxWpBwVpB4f0vL9XKcaA+5GQOe5xL06sg9RX60lv7+UcdNOycI0duQCsB1o/fiMUN3+Rax+G+SinW+n0aZLRnKDeJbPeqCVh5hJl/c0FHCVlfA7+h/kcGVAhOQP3EXPAnjJo7bPJGgIOybRqm/BaK+ktX9GixQ/r5gs8h9i4znihP1/iSIthA5/Ke0MaXN/aFg+suRcZ3YJa6uDoGqNa8+TPxPgumrN3nTRFkKOHVAhS3ZQvXLs0JizjlAPrnBKHVkNxWYs+LLmHKzVjw2GP+tT+oYFlPQ9M9GeV3guH/fkfL+B2YheSPePSYRlfX9MIUnQPeDyz+racdqdh+aZ1MvSjtqoxiTif/FLfk6qX1aeaNr21U3dTitLOlamp7jWD90hRh+RPxNZK4xTadDWrwoEgXvpI3/04FIRW5YLEC8CJmfNjY23wnDgJCnVnR+A1kQvtKmiMtLr/g5HciQ1ArF84HNsOzvjgOGk0aKybNE6ZL65O0hiEdptemoyROBktgPBcvZtRY7GI+mG4sJ69ZbmqPDagephaA3lE/ddA4/u6b2KpuatIGyc0LxfLHZlOldeNKDrM0lpAZApn29i14kJiGNayDJEjpegdOoJ6ajZFDTw13yd4T5q9FrphhedlU7ISwCYwMUfbgTOlc7H8y4+fu433KL3J51fABKurrODwlxl0R3TSaMJoljBYJoIaMqdaA5ACikZQr7/JCBwuOnEamo1My6J40poRSsb1OyMgxHE/Ywcog0Ssn6Jx2cbyTn2++PxOg6tUMnuTWtNoV8xWJpWEUWRyZAa3m8BjIZ1aQO6UH46zBRT8yfTi0EN3v1xN3zOhSiHGRhzM3wgWa3cc8 bD69z3mE E5+B1m+CqqiC7aU7a8EWHnXf0f+Ytb/QaUu41EgCZY/pR/qW63ct6/xp0vbC9EHyULqPMIdTyrrKa8lJMHAkDeOBlo0nejwbn5abmi9+cHk47sbGp/Fw/CIWm8jXpdblgKgTUX3v2gk3LzvUX7mCNLa0hq2lv2r7xrO9925M8B83fIKAGsSdkiu1NwiiliehNhYMAIg1Y3J94vsptMLotxIa5T2IaCeBDTDNwdxMgWmEbh9gqRTKEjVZf68K9P9l49EbnM7wgLT0T+mKPE1bBiwmb3pLNfQzyWA38OYM7++fz8jwtXMHvATDCYg== 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: List-Subscribe: List-Unsubscribe: Call swap_writeout() and shmem_writeout() from pageout() instead. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Baolin Wang Tested-by: Baolin Wang --- block/blk-wbt.c | 2 +- mm/page_io.c | 3 +-- mm/shmem.c | 23 +++++------------------ mm/swap.h | 4 ++-- mm/swap_state.c | 1 - mm/swapfile.c | 2 +- mm/vmscan.c | 28 ++++++++++++++++------------ 7 files changed, 26 insertions(+), 37 deletions(-) diff --git a/block/blk-wbt.c b/block/blk-wbt.c index f1754d07f7e0..60885731e8ab 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -37,7 +37,7 @@ enum wbt_flags { WBT_TRACKED = 1, /* write, tracked for throttling */ WBT_READ = 2, /* read */ - WBT_SWAP = 4, /* write, from swap_writepage() */ + WBT_SWAP = 4, /* write, from swap_writeout() */ WBT_DISCARD = 8, /* discard */ WBT_NR_BITS = 4, /* number of bits */ diff --git a/mm/page_io.c b/mm/page_io.c index 4bce19df557b..f7716b6569fa 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -237,9 +237,8 @@ static void swap_zeromap_folio_clear(struct folio *folio) * We may have stale swap cache pages in memory: notice * them here and get rid of the unnecessary final write. */ -int swap_writepage(struct page *page, struct writeback_control *wbc) +int swap_writeout(struct folio *folio, struct writeback_control *wbc) { - struct folio *folio = page_folio(page); int ret; if (folio_free_swap(folio)) { diff --git a/mm/shmem.c b/mm/shmem.c index 7d377ceae035..858cee02ca49 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -98,7 +98,7 @@ static struct vfsmount *shm_mnt __ro_after_init; #define SHORT_SYMLINK_LEN 128 /* - * shmem_fallocate communicates with shmem_fault or shmem_writepage via + * shmem_fallocate communicates with shmem_fault or shmem_writeout via * inode->i_private (with i_rwsem making sure that it has only one user at * a time): we would prefer not to enlarge the shmem inode just for that. */ @@ -107,7 +107,7 @@ struct shmem_falloc { pgoff_t start; /* start of range currently being fallocated */ pgoff_t next; /* the next page offset to be fallocated */ pgoff_t nr_falloced; /* how many new pages have been fallocated */ - pgoff_t nr_unswapped; /* how often writepage refused to swap out */ + pgoff_t nr_unswapped; /* how often writeout refused to swap out */ }; struct shmem_options { @@ -446,7 +446,7 @@ static void shmem_recalc_inode(struct inode *inode, long alloced, long swapped) /* * Special case: whereas normally shmem_recalc_inode() is called * after i_mapping->nrpages has already been adjusted (up or down), - * shmem_writepage() has to raise swapped before nrpages is lowered - + * shmem_writeout() has to raise swapped before nrpages is lowered - * to stop a racing shmem_recalc_inode() from thinking that a page has * been freed. Compensate here, to avoid the need for a followup call. */ @@ -1536,11 +1536,6 @@ int shmem_unuse(unsigned int type) return error; } -static int shmem_writepage(struct page *page, struct writeback_control *wbc) -{ - return shmem_writeout(page_folio(page), wbc); -} - /** * shmem_writeout - Write the folio to swap * @folio: The folio to write @@ -1558,13 +1553,6 @@ int shmem_writeout(struct folio *folio, struct writeback_control *wbc) int nr_pages; bool split = false; - /* - * 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; @@ -1653,7 +1641,7 @@ int shmem_writeout(struct folio *folio, struct writeback_control *wbc) mutex_unlock(&shmem_swaplist_mutex); BUG_ON(folio_mapped(folio)); - return swap_writepage(&folio->page, wbc); + return swap_writeout(folio, wbc); } list_del_init(&info->swaplist); @@ -3776,7 +3764,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset, index--; /* - * Inform shmem_writepage() how far we have reached. + * Inform shmem_writeout() how far we have reached. * No need for lock or barrier: we have the page lock. */ if (!folio_test_uptodate(folio)) @@ -5199,7 +5187,6 @@ static int shmem_error_remove_folio(struct address_space *mapping, } static const struct address_space_operations shmem_aops = { - .writepage = shmem_writepage, .dirty_folio = noop_dirty_folio, #ifdef CONFIG_TMPFS .write_begin = shmem_write_begin, diff --git a/mm/swap.h b/mm/swap.h index 6f4a3f927edb..aa62463976d5 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -20,7 +20,7 @@ static inline void swap_read_unplug(struct swap_iocb *plug) __swap_read_unplug(plug); } void swap_write_unplug(struct swap_iocb *sio); -int swap_writepage(struct page *page, struct writeback_control *wbc); +int swap_writeout(struct folio *folio, struct writeback_control *wbc); void __swap_writepage(struct folio *folio, struct writeback_control *wbc); /* linux/mm/swap_state.c */ @@ -141,7 +141,7 @@ static inline struct folio *swapin_readahead(swp_entry_t swp, gfp_t gfp_mask, return NULL; } -static inline int swap_writepage(struct page *p, struct writeback_control *wbc) +static inline int swap_writeout(struct folio *f, struct writeback_control *wbc) { return 0; } diff --git a/mm/swap_state.c b/mm/swap_state.c index 68fd981b514f..ec2b1c9c9926 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -30,7 +30,6 @@ * vmscan's shrink_folio_list. */ static const struct address_space_operations swap_aops = { - .writepage = swap_writepage, .dirty_folio = noop_dirty_folio, #ifdef CONFIG_MIGRATION .migrate_folio = migrate_folio, diff --git a/mm/swapfile.c b/mm/swapfile.c index 2eff8b51a945..f9fa30ae13be 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2359,7 +2359,7 @@ static int try_to_unuse(unsigned int type) * Limit the number of retries? No: when mmget_not_zero() * above fails, that mm is likely to be freeing swap from * exit_mmap(), which proceeds at its own independent pace; - * and even shmem_writepage() could have been preempted after + * and even shmem_writeout() could have been preempted after * folio_alloc_swap(), temporarily hiding that swap. It's easy * and robust (though cpu-intensive) just to keep retrying. */ diff --git a/mm/vmscan.c b/mm/vmscan.c index b620d74b0f66..d172c998d592 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -653,16 +653,16 @@ typedef enum { static pageout_t pageout(struct folio *folio, struct address_space *mapping, struct swap_iocb **plug, struct list_head *folio_list) { + int (*writeout)(struct folio *, struct writeback_control *); + /* - * If the folio is dirty, only perform writeback if that write - * will be non-blocking. To prevent this allocation from being - * stalled by pagecache activity. But note that there may be - * stalls if we need to run get_block(). We could test - * PagePrivate for that. - * - * If this process is currently in __generic_file_write_iter() against - * this folio's queue, we can perform writeback even if that - * will block. + * We no longer attempt to writeback filesystem folios here, other + * than tmpfs/shmem. That's taken care of in page-writeback. + * If we find a dirty filesystem folio at the end of the LRU list, + * typically that means the filesystem is saturating the storage + * with contiguous writes and telling it to write a folio here + * would only make the situation worse by injecting an element + * of random access. * * If the folio is swapcache, write it back even if that would * block, for some throttling. This happens by accident, because @@ -685,7 +685,11 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping, } return PAGE_KEEP; } - if (mapping->a_ops->writepage == NULL) + if (shmem_mapping(mapping)) + writeout = shmem_writeout; + else if (folio_test_anon(folio)) + writeout = swap_writeout; + else return PAGE_ACTIVATE; if (folio_clear_dirty_for_io(folio)) { @@ -708,7 +712,7 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping, wbc.list = folio_list; folio_set_reclaim(folio); - res = mapping->a_ops->writepage(&folio->page, &wbc); + res = writeout(folio, &wbc); if (res < 0) handle_write_error(mapping, folio, res); if (res == AOP_WRITEPAGE_ACTIVATE) { @@ -717,7 +721,7 @@ static pageout_t pageout(struct folio *folio, struct address_space *mapping, } if (!folio_test_writeback(folio)) { - /* synchronous write or broken a_ops? */ + /* synchronous write? */ folio_clear_reclaim(folio); } trace_mm_vmscan_write_folio(folio); From patchwork Wed Apr 2 15:00:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036134 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 CEC97C28B20 for ; Wed, 2 Apr 2025 15:00:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9EF2280006; Wed, 2 Apr 2025 11:00:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4A7F280001; Wed, 2 Apr 2025 11:00:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2297280006; Wed, 2 Apr 2025 11:00:10 -0400 (EDT) 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 AEFAB280001 for ; Wed, 2 Apr 2025 11:00:10 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 62A00161B8C for ; Wed, 2 Apr 2025 15:00:11 +0000 (UTC) X-FDA: 83289414222.20.D72DC28 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id 732E6180003 for ; Wed, 2 Apr 2025 15:00:09 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OPxksYeY; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743606010; h=from:from: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=7cWI+SI5JEeVoho9MXmZZwCgZvtcT1k/amPvINb3fvA=; b=pXrCEq5lmpYptrnLRAKxxwGgUaT2k+JTinXK9ImD2LdKDye/JpviVLy8c0GnPzlYHjYm+O aV7DceGSds76Q2ut+kdde0lRWD4jTSNloebO6wYJEVDOCzCNmY6u87pNan+D2kPCu7BMKm lEkK1ntiR7Tj4TVFPsoPzSt3bRHEifQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OPxksYeY; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743606010; a=rsa-sha256; cv=none; b=SWakR9ka07R5gkDoTeGai/YAZqrIxp6MUsxu3ZJfxA6Zn86OXVmM0QvRwc6mXGVloraKPc 0jzXTQ3sxj7ndosgZl2iqu95ZnVwmiOo4+JUF3zZK+glp+4CnrkOatAZWc05JS7ST9+2/x 1rKfm2I3XVBvmFoiAzzCp/mJxHxEU08= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=7cWI+SI5JEeVoho9MXmZZwCgZvtcT1k/amPvINb3fvA=; b=OPxksYeYtpiSdpGlC9Z/Icv8+p k1C9g53t5nvxpZ2xY8RbXtO5qZTOXzY6iL4hPmIKqt+zMNfXTr+f9esxmwzkN1ixWY1k77sa/nXHx swUAjuXOYvCWpvkyJILbInMD+GiR+DY0Tj61dSctqPsn4EJN8set1MjoEClkkMaFIsPEIx15HivWM ZuyVw8hTuNsp+LRfOC9dGxcuMXmAw5+uTn2XlzY9qsS10qJI98gUys+XKXm++OakJVeVso3TwE9co Q9Qk55Fms99FnnpGhCnPNfZp3F3lt+TTtDAIfIrBQMFPLMaxI98V94oxDe/MU2KUqLA+SiIkG3lQj A1qL7Yzw==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzzZX-00000009gst-42OI; Wed, 02 Apr 2025 15:00:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 9/9] fs: Remove aops->writepage Date: Wed, 2 Apr 2025 16:00:03 +0100 Message-ID: <20250402150005.2309458-10-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402150005.2309458-1-willy@infradead.org> References: <20250402150005.2309458-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 732E6180003 X-Stat-Signature: qbj47grbfuysxu6x1pn9q7o74tcgsq13 X-HE-Tag: 1743606009-147485 X-HE-Meta: U2FsdGVkX18XYAvz7rTr+J32FlUPfHW1nVGAeun3U1upP2wJL7++/aqsbqG3zB2H6mIqisS9aP8OT6vgA2kXAqwaXYriXnewDSB2ci/NjkeqJ856LhMbSCjF+NquR9ZRvEsLwQvrWPQGukpAqKo4xJuvHPVc4WPZD8L1yC38/V+KR3+jfyEniuk/wYruP9/GatetAXj5dJbvx8B/caSCxvx+m9HcjLBdCQMJgugRWLfAxNWDduMUkRl4DsZUw++Cm8tWC2TM9L+bWsZjXA1qWYZ+Xr6LFKwNlqTI7cy6rgVOijK1CpzroFHOOyquOHfBntUjPrlAa7Ks4LYROs25XDOKas/8M9FYXtGBDXypYlDtDdS7gHIozLcb6t2k1a5/iXbyowJ1g7cb3HFPh7vGUm2RAkuXgXIJ0xiEYMEsHdq+1O5CTxtprxqvlikcujzBAAp+fn934PK/VFOLGMv8E4wy5gRSebUXfOKexeixis/v7TEcn9t2Z7NLH8A0uuRdqhR6H75CYnpC7eikvzSZudtL4SemlWmx73NagQWTq9qIQccdlbt+oqcV223X9NbRQWutV2tldFw++U2hQrnU2PignWbLGESAN3r1FpUpoSYx686otC8Wj82vRsOrfh2OKtkgIy73Z1T2uF3oclh7VBUvmFAsxjQoYgt56fkTi59GUU1h8Qm+Tur8BhPJ9QtSg3HkvB1p/eE6TX2D9urgfj26EBayVbVTwOfWTyKHwd1hAVLVUzn4NwoDuy+Uuf1QFHIMDMty7za//VJ5vmHyU4pEMwPRGAosP15Mqto/zlHR50+KwOJ4j1tQGxpUd+EaxQmMGdgk+PyWTgL7I3g13EhIif8A3yzo1Hhhx8ZhIsN4EN+HiSUHhI9M10ITkl4mgQauvwQWtCvujFVko6f0eA== 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: List-Subscribe: List-Unsubscribe: All callers and implementations are now removed, so remove the operation and update the documentation to match. Signed-off-by: Matthew Wilcox (Oracle) --- Documentation/admin-guide/cgroup-v2.rst | 2 +- Documentation/filesystems/fscrypt.rst | 2 +- Documentation/filesystems/locking.rst | 54 +------------------------ Documentation/filesystems/vfs.rst | 39 +++++------------- fs/buffer.c | 4 +- include/linux/fs.h | 1 - mm/vmscan.c | 1 - 7 files changed, 15 insertions(+), 88 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 1a16ce68a4d7..9e7de8e70048 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -3019,7 +3019,7 @@ Filesystem Support for Writeback -------------------------------- A filesystem can support cgroup writeback by updating -address_space_operations->writepage[s]() to annotate bio's using the +address_space_operations->writepages() to annotate bio's using the following two functions. wbc_init_bio(@wbc, @bio) diff --git a/Documentation/filesystems/fscrypt.rst b/Documentation/filesystems/fscrypt.rst index e80329908549..3d22e2db732d 100644 --- a/Documentation/filesystems/fscrypt.rst +++ b/Documentation/filesystems/fscrypt.rst @@ -1409,7 +1409,7 @@ read the ciphertext into the page cache and decrypt it in-place. The folio lock must be held until decryption has finished, to prevent the folio from becoming visible to userspace prematurely. -For the write path (->writepage()) of regular files, filesystems +For the write path (->writepages()) of regular files, filesystems cannot encrypt data in-place in the page cache, since the cached plaintext must be preserved. Instead, filesystems must encrypt into a temporary buffer or "bounce page", then write out the temporary diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesystems/locking.rst index 0ec0bb6eb0fb..2e567e341c3b 100644 --- a/Documentation/filesystems/locking.rst +++ b/Documentation/filesystems/locking.rst @@ -249,7 +249,6 @@ address_space_operations ======================== prototypes:: - int (*writepage)(struct page *page, struct writeback_control *wbc); int (*read_folio)(struct file *, struct folio *); int (*writepages)(struct address_space *, struct writeback_control *); bool (*dirty_folio)(struct address_space *, struct folio *folio); @@ -280,7 +279,6 @@ locking rules: ====================== ======================== ========= =============== ops folio locked i_rwsem invalidate_lock ====================== ======================== ========= =============== -writepage: yes, unlocks (see below) read_folio: yes, unlocks shared writepages: dirty_folio: maybe @@ -309,54 +307,6 @@ completion. ->readahead() unlocks the folios that I/O is attempted on like ->read_folio(). -->writepage() is used for two purposes: for "memory cleansing" and for -"sync". These are quite different operations and the behaviour may differ -depending upon the mode. - -If writepage is called for sync (wbc->sync_mode != WBC_SYNC_NONE) then -it *must* start I/O against the page, even if that would involve -blocking on in-progress I/O. - -If writepage is called for memory cleansing (sync_mode == -WBC_SYNC_NONE) then its role is to get as much writeout underway as -possible. So writepage should try to avoid blocking against -currently-in-progress I/O. - -If the filesystem is not called for "sync" and it determines that it -would need to block against in-progress I/O to be able to start new I/O -against the page the filesystem should redirty the page with -redirty_page_for_writepage(), then unlock the page and return zero. -This may also be done to avoid internal deadlocks, but rarely. - -If the filesystem is called for sync then it must wait on any -in-progress I/O and then start new I/O. - -The filesystem should unlock the page synchronously, before returning to the -caller, unless ->writepage() returns special WRITEPAGE_ACTIVATE -value. WRITEPAGE_ACTIVATE means that page cannot really be written out -currently, and VM should stop calling ->writepage() on this page for some -time. VM does this by moving page to the head of the active list, hence the -name. - -Unless the filesystem is going to redirty_page_for_writepage(), unlock the page -and return zero, writepage *must* run set_page_writeback() against the page, -followed by unlocking it. Once set_page_writeback() has been run against the -page, write I/O can be submitted and the write I/O completion handler must run -end_page_writeback() once the I/O is complete. If no I/O is submitted, the -filesystem must run end_page_writeback() against the page before returning from -writepage. - -That is: after 2.5.12, pages which are under writeout are *not* locked. Note, -if the filesystem needs the page to be locked during writeout, that is ok, too, -the page is allowed to be unlocked at any point in time between the calls to -set_page_writeback() and end_page_writeback(). - -Note, failure to run either redirty_page_for_writepage() or the combination of -set_page_writeback()/end_page_writeback() on a page submitted to writepage -will leave the page itself marked clean but it will be tagged as dirty in the -radix tree. This incoherency can lead to all sorts of hard-to-debug problems -in the filesystem like having dirty inodes at umount and losing written data. - ->writepages() is used for periodic writeback and for syscall-initiated sync operations. The address_space should start I/O against at least ``*nr_to_write`` pages. ``*nr_to_write`` must be decremented for each page @@ -364,8 +314,8 @@ which is written. The address_space implementation may write more (or less) pages than ``*nr_to_write`` asks for, but it should try to be reasonably close. If nr_to_write is NULL, all dirty pages must be written. -writepages should _only_ write pages which are present on -mapping->io_pages. +writepages should _only_ write pages which are present in +mapping->i_pages. ->dirty_folio() is called from various places in the kernel when the target folio is marked as needing writeback. The folio cannot be diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst index ae79c30b6c0c..bf051c7da6b8 100644 --- a/Documentation/filesystems/vfs.rst +++ b/Documentation/filesystems/vfs.rst @@ -716,9 +716,8 @@ page lookup by address, and keeping track of pages tagged as Dirty or Writeback. The first can be used independently to the others. The VM can try to -either write dirty pages in order to clean them, or release clean pages -in order to reuse them. To do this it can call the ->writepage method -on dirty pages, and ->release_folio on clean folios with the private +release clean pages in order to reuse them. To do this it can call +->release_folio on clean folios with the private flag set. Clean pages without PagePrivate and with no external references will be released without notice being given to the address_space. @@ -731,8 +730,8 @@ maintains information about the PG_Dirty and PG_Writeback status of each page, so that pages with either of these flags can be found quickly. The Dirty tag is primarily used by mpage_writepages - the default -->writepages method. It uses the tag to find dirty pages to call -->writepage on. If mpage_writepages is not used (i.e. the address +->writepages method. It uses the tag to find dirty pages to +write back. If mpage_writepages is not used (i.e. the address provides its own ->writepages) , the PAGECACHE_TAG_DIRTY tag is almost unused. write_inode_now and sync_inode do use it (through __sync_single_inode) to check if ->writepages has been successful in @@ -756,23 +755,23 @@ pages, however the address_space has finer control of write sizes. The read process essentially only requires 'read_folio'. The write process is more complicated and uses write_begin/write_end or -dirty_folio to write data into the address_space, and writepage and +dirty_folio to write data into the address_space, and writepages to writeback data to storage. Adding and removing pages to/from an address_space is protected by the inode's i_mutex. When data is written to a page, the PG_Dirty flag should be set. It -typically remains set until writepage asks for it to be written. This +typically remains set until writepages asks for it to be written. This should clear PG_Dirty and set PG_Writeback. It can be actually written at any point after PG_Dirty is clear. Once it is known to be safe, PG_Writeback is cleared. Writeback makes use of a writeback_control structure to direct the -operations. This gives the writepage and writepages operations some +operations. This gives the writepages operation some information about the nature of and reason for the writeback request, and the constraints under which it is being done. It is also used to -return information back to the caller about the result of a writepage or +return information back to the caller about the result of a writepages request. @@ -819,7 +818,6 @@ cache in your filesystem. The following members are defined: .. code-block:: c struct address_space_operations { - int (*writepage)(struct page *page, struct writeback_control *wbc); int (*read_folio)(struct file *, struct folio *); int (*writepages)(struct address_space *, struct writeback_control *); bool (*dirty_folio)(struct address_space *, struct folio *); @@ -848,25 +846,6 @@ cache in your filesystem. The following members are defined: int (*swap_rw)(struct kiocb *iocb, struct iov_iter *iter); }; -``writepage`` - called by the VM to write a dirty page to backing store. This - may happen for data integrity reasons (i.e. 'sync'), or to free - up memory (flush). The difference can be seen in - wbc->sync_mode. The PG_Dirty flag has been cleared and - PageLocked is true. writepage should start writeout, should set - PG_Writeback, and should make sure the page is unlocked, either - synchronously or asynchronously when the write operation - completes. - - If wbc->sync_mode is WB_SYNC_NONE, ->writepage doesn't have to - try too hard if there are problems, and may choose to write out - other pages from the mapping if that is easier (e.g. due to - internal dependencies). If it chooses not to start writeout, it - should return AOP_WRITEPAGE_ACTIVATE so that the VM will not - keep calling ->writepage on that page. - - See the file "Locking" for more details. - ``read_folio`` Called by the page cache to read a folio from the backing store. The 'file' argument supplies authentication information to network @@ -909,7 +888,7 @@ cache in your filesystem. The following members are defined: given and that many pages should be written if possible. If no ->writepages is given, then mpage_writepages is used instead. This will choose pages from the address space that are tagged as - DIRTY and will pass them to ->writepage. + DIRTY and will write them back. ``dirty_folio`` called by the VM to mark a folio as dirty. This is particularly diff --git a/fs/buffer.c b/fs/buffer.c index c7abb4a029dc..b99dc69dba37 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2695,7 +2695,7 @@ int block_truncate_page(struct address_space *mapping, EXPORT_SYMBOL(block_truncate_page); /* - * The generic ->writepage function for buffer-backed address_spaces + * The generic write folio function for buffer-backed address_spaces */ int block_write_full_folio(struct folio *folio, struct writeback_control *wbc, void *get_block) @@ -2715,7 +2715,7 @@ int block_write_full_folio(struct folio *folio, struct writeback_control *wbc, /* * The folio straddles i_size. It must be zeroed out on each and every - * writepage invocation because it may be mmapped. "A file is mapped + * writeback invocation because it may be mmapped. "A file is mapped * in multiples of the page size. For a file that is not a multiple of * the page size, the remaining memory is zeroed when mapped, and * writes to that region are not written out to the file." diff --git a/include/linux/fs.h b/include/linux/fs.h index 016b0fe1536e..f7beefb917a8 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -433,7 +433,6 @@ static inline bool is_sync_kiocb(struct kiocb *kiocb) } struct address_space_operations { - int (*writepage)(struct page *page, struct writeback_control *wbc); int (*read_folio)(struct file *, struct folio *); /* Write back some dirty pages from this mapping. */ diff --git a/mm/vmscan.c b/mm/vmscan.c index d172c998d592..6d56f4816171 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -648,7 +648,6 @@ typedef enum { /* * pageout is called by shrink_folio_list() for each dirty folio. - * Calls ->writepage(). */ static pageout_t pageout(struct folio *folio, struct address_space *mapping, struct swap_iocb **plug, struct list_head *folio_list)