From patchwork Mon Jan 29 14:34: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: 13535772 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 B630BC47DB3 for ; Mon, 29 Jan 2024 14:35:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4341A6B00B3; Mon, 29 Jan 2024 09:35:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 397446B00B4; Mon, 29 Jan 2024 09:35:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2109D6B00B5; Mon, 29 Jan 2024 09:35:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 092AE6B00B3 for ; Mon, 29 Jan 2024 09:35:59 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D60B0A139D for ; Mon, 29 Jan 2024 14:35:58 +0000 (UTC) X-FDA: 81732597996.27.040D8EF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id 257D814002B for ; Mon, 29 Jan 2024 14:35:56 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ESJmh4m+; dmarc=none; spf=none (imf26.hostedemail.com: domain of BATV+95c35c30fd22f84c25d9+7463+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+95c35c30fd22f84c25d9+7463+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=1706538957; 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=nAo5bw02V9iJ+IEFLiAcFuHre/6jVBRPkcUqDrM/TzU=; b=qS24uA6JbUmVwz7/7VOpgmSBWAiZoNfTFVHURek9V3WUoSS0Jc1v5yAzmjuksVlLz+wIeZ lZW1/Helqg5QF5zilYLjdf2szMgttNSUb4pHnAqD0gq33Tji4SVArMvIYfjwSwjFXk2z4X G3blLbEFh4CdTkMK2z4ylDQtkCiJUZg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=ESJmh4m+; dmarc=none; spf=none (imf26.hostedemail.com: domain of BATV+95c35c30fd22f84c25d9+7463+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+95c35c30fd22f84c25d9+7463+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706538957; a=rsa-sha256; cv=none; b=nX57BLDRtOrjwHqj+n788W5woYJ3DmelIwnCpPmKzfuPXTlmXFAfJgAC6D3FMCpwZvSiE2 6TKqwqCb8PZI2hc1/dXd4PIlt2M1rXCJkHnNXokpajQMLvCW8PJXnkRbfWqO3ZZoVZ3Ov3 spdSOHZ3fee0jDLwQy3IpVRU4PJfrQ8= 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=nAo5bw02V9iJ+IEFLiAcFuHre/6jVBRPkcUqDrM/TzU=; b=ESJmh4m+XvuhJ6apgjdWVYbSVY N4ryfai2FPtx4Wpip6S3CTa5kgs80PjCDDvGslPw2JEo398x1r/Y4iGceJjonN1kCr5Ep6cTW0uxZ PI37QgXu5KBJCR3af4rO/WQZkOM/PTQpGFZ5XgzqNih4TRD1aCm+fTlrZyeD5ZRZrE49eh7ok/1FA THQ18sSsBbR7zpH6Jx366zYIf7tNopG3SmINd4bwOqzmH6LmOEY6fZAe58223NfEhgvVPljL50WEX MgM5p+MKE1+5QInkOV8DDb8qpjwSQfFrCbDP3krjKfR82H7Dr7mbJxTvSbyJOWJZH1rON7KnHW673 qLrdYKvA==; Received: from [2001:4bb8:182:6550:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rUSjq-0000000D6Ns-2GN2; Mon, 29 Jan 2024 14:35:55 +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/20] xfs: use shmem_get_folio in xfile_obj_store Date: Mon, 29 Jan 2024 15:34:56 +0100 Message-Id: <20240129143502.189370-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240129143502.189370-1-hch@lst.de> References: <20240129143502.189370-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: 257D814002B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: r9uacn8t54yggeod4sf4qsy9ydyuo6fq X-HE-Tag: 1706538956-154066 X-HE-Meta: U2FsdGVkX1909JfJkqSWetZqxF4TrRl7I727CN4dOqif8E0p6LdAc7FQ3NoNv/aiL5QZZDtxnJGbU54ZxXjBpRvykwB7ljBS21QBkk765GlcecQy7CthF6zGCvSt28yMvew78yr9s4Y1cAIZNBY3+kBNth4yQ8CtMfaBxDJargQnx66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wt/VpZrUbsct4nKhgliYoq2iG/JuXM265nPJLizIVsus6fsHuxwZU6DUPzIkhDp/k4ZcN6XMqRUMZATHyI7g2lRcIlKBXonqtsOBqJlptMv8xZ9Rx1a7iIu50YnBuamjLlZ8zd2GlX9oQJ2jmdbWCELb894ET634HtHYFYIuqKb+Y/xmcMYa/SNc/6Z0Z+F3B3xpRSRwtThW4YGRJtgb5YxIIA6pqv+9HMbSu1hHlriznqbshlSRVKQaAodRG58D2eK12a5CogPw= 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 | 73 ++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 46 deletions(-) diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c index a669ebbbc02d1d..2b4819902b4cc3 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,45 @@ 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 (filemap_check_wb_err(inode->i_mapping, 0)) { + 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. */