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,