From patchwork Fri Jan 26 13:28:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13532577 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 5A885C47DDF for ; Fri, 26 Jan 2024 13:30:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3A3D6B008A; Fri, 26 Jan 2024 08:30:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DEB316B008C; Fri, 26 Jan 2024 08:30:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB39A6B0092; Fri, 26 Jan 2024 08:30:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BB59A6B008A for ; Fri, 26 Jan 2024 08:30:13 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 86EFC160F42 for ; Fri, 26 Jan 2024 13:30:13 +0000 (UTC) X-FDA: 81721545906.25.4CF675C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf03.hostedemail.com (Postfix) with ESMTP id DA2502001B for ; Fri, 26 Jan 2024 13:30:11 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Uon45Ynj; dmarc=none; spf=none (imf03.hostedemail.com: domain of BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706275811; 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=PN3djP3juVhL/KNUknZcP0OIUVZdWEXnGZgCPDCtRNQ=; b=m/ztaG76RCh+7C+Ec8uZ21dCocrbz2LE1ehT/9xnxUG6QOruXcTPXod21Tb0uop8mx4jNv 8Bl49GHru6kBjbBEgnfjCmF03uxkvNgTPiICcMo1gFIHxKEC2HK1G6SJMa2yACOHj0zZi7 p0XwQtNvQ8ozltEGiOOhV9VxlpQd1N8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Uon45Ynj; dmarc=none; spf=none (imf03.hostedemail.com: domain of BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+8230b42af99c397292d7+7460+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706275811; a=rsa-sha256; cv=none; b=H3CWu3LzntAt6tCAVZWu1LsmggUGV4tmqa8CmyOhUAbxUJCPyyweOgkPibVyJyWC8W42FV 6/6Zb9KTxV/hDqPn/B9eByHenGpcflpc0KwAQEg8lnxODZhRylRRtWHbDjjhj6T2SjpG3O k37aOf1KhE+EnbircTQHds3aahAumcM= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=PN3djP3juVhL/KNUknZcP0OIUVZdWEXnGZgCPDCtRNQ=; b=Uon45YnjXTuIOePuwZJX0gy+k5 KIaB3xbNpNu4+wx4OaU1k7IpfEOKnpm6VpR0Eu/ao9enWMc9/Kstx1dr14gx1XLhmrg4BApGb5blJ xsVMXblOjihwDPnPlAFbh9GlfRVMwVC1ikMaysmGRdwwdV5Q+7yFDf7yHnDJTjm4qxnWgXOB5yZek kdVj/WJSQCHa6EgUtd1cSQRp+34iSJMZCoqztZ1AJTmgBVcxPTA6vqX+fJMCHJ4wvIwcTiqv4mk2/ 0otUImdgTldDWzM/7f7qVBuLhO46e6+yeT2noDysOOoFvuwWttwM/yeeRU6/AGUj/C6I9auF/tYtC 5qx2wKOQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTMHY-00000004Cr7-38VI; Fri, 26 Jan 2024 13:30:09 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 14/21] xfs: use shmem_get_folio in xfile_obj_store Date: Fri, 26 Jan 2024 14:28:56 +0100 Message-Id: <20240126132903.2700077-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240126132903.2700077-1-hch@lst.de> References: <20240126132903.2700077-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: DA2502001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: by9qbekezxhezf1zzow9e66ra641wj85 X-HE-Tag: 1706275811-141343 X-HE-Meta: U2FsdGVkX19/bEukzdO788q5OpNPLV9QZwOVhuw4ViYXI4QFNz1yemythrMX2EOy/zTsTSaapcXyh9uN5EkpcWNQ4C/pepGlzEexTDn3EOiHlCLryQuTKHmHmwhjXFEQMpmunuqlefop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zPjY/1ZMhcu0APlMmAn3wFOMdH7t+tmx3nHNb1QWNNOLMV88XAtEyEfUJUewYT4vHztLfbvTb51dbCU0u5Bb9mMnn4YjaWVMTzZ1EmQ5KWv/EVWtsJfLOhECZTrsp0D2F5aRLVgiE+1YKjGMIL/LkPq3O9vDgGaJuWqUckOTnKKLUtrqAQmfDzIRhFTLjttLUScT/dsI9zf0zLPaPxB3HQFKB0jpczeEt39YXLf8M5pT/PxNbW/cXTyq6eFennivjTzHnipeii+6weUejP0i3P+f7kFfwFrSQgZC0HAOnDJfR5G0= 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: Switch to using shmem_get_folio and manually dirtying the page instead of abusing aops->write_begin and aops->write_end in xfile_get_page. This simplifies the code by not doing indirect calls of not actually exported interfaces that don't really fit the use case very well, and happens to get us large folio support for free. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/scrub/xfile.c | 75 +++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c index 623bbde91ae3fe..c71c853c9ffdd7 100644 --- a/fs/xfs/scrub/xfile.c +++ b/fs/xfs/scrub/xfile.c @@ -183,11 +183,7 @@ xfile_store( loff_t pos) { struct inode *inode = file_inode(xf->file); - struct address_space *mapping = inode->i_mapping; - const struct address_space_operations *aops = mapping->a_ops; - struct page *page = NULL; unsigned int pflags; - int error = 0; if (count > MAX_RW_COUNT) return -ENOMEM; @@ -196,60 +192,47 @@ xfile_store( trace_xfile_store(xf, pos, count); + /* + * Increase the file size first so that shmem_get_folio(..., SGP_CACHE), + * actually allocates a folio instead of erroring out. + */ + if (pos + count > i_size_read(inode)) + i_size_write(inode, pos + count); + pflags = memalloc_nofs_save(); while (count > 0) { - void *fsdata = NULL; - void *p, *kaddr; + struct folio *folio; unsigned int len; - int ret; + unsigned int offset; - len = min_t(ssize_t, count, PAGE_SIZE - offset_in_page(pos)); - - /* - * We call write_begin directly here to avoid all the freezer - * protection lock-taking that happens in the normal path. - * shmem doesn't support fs freeze, but lockdep doesn't know - * that and will trip over that. - */ - error = aops->write_begin(NULL, mapping, pos, len, &page, - &fsdata); - if (error) { - error = -ENOMEM; + if (shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio, + SGP_CACHE) < 0) break; - } - - /* - * xfile pages must never be mapped into userspace, so we skip - * the dcache flush. If the page is not uptodate, zero it - * before writing data. - */ - kaddr = page_address(page); - if (!PageUptodate(page)) { - memset(kaddr, 0, PAGE_SIZE); - SetPageUptodate(page); - } - p = kaddr + offset_in_page(pos); - memcpy(p, buf, len); - - ret = aops->write_end(NULL, mapping, pos, len, len, page, - fsdata); - if (ret < 0) { - error = -ENOMEM; + if (folio_test_hwpoison(folio) || + (folio_test_large(folio) && + folio_test_has_hwpoisoned(folio))) { + folio_unlock(folio); + folio_put(folio); break; } - if (ret != len) { - error = -ENOMEM; - break; - } + offset = offset_in_folio(folio, pos); + len = min_t(ssize_t, count, folio_size(folio) - offset); + memcpy(folio_address(folio) + offset, buf, len); + + folio_mark_dirty(folio); + folio_unlock(folio); + folio_put(folio); - count -= ret; - pos += ret; - buf += ret; + count -= len; + pos += len; + buf += len; } memalloc_nofs_restore(pflags); - return error; + if (count) + return -ENOMEM; + return 0; } /* Find the next written area in the xfile data for a given offset. */