From patchwork Mon Feb 19 06:27:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13562219 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 AB2AEC48BC3 for ; Mon, 19 Feb 2024 06:28:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC0B08D0015; Mon, 19 Feb 2024 01:28:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4A418D0007; Mon, 19 Feb 2024 01:28:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B735F8D0015; Mon, 19 Feb 2024 01:28:11 -0500 (EST) 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 988A78D0007 for ; Mon, 19 Feb 2024 01:28:11 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 72CCFC017A for ; Mon, 19 Feb 2024 06:28:11 +0000 (UTC) X-FDA: 81807573582.21.B5BC942 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf05.hostedemail.com (Postfix) with ESMTP id C5A1310000C for ; Mon, 19 Feb 2024 06:28:09 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=e2uivlW0; dmarc=none; spf=none (imf05.hostedemail.com: domain of BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+994827af29a55d2021e7+7484+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=1708324089; 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=4yvOV2MFFDBEYH3fUNbndLoOzOA31/axOU+QN+8ByXE=; b=AWVMgYqDz2CossLDpCiL+yIAa3ZztMC9X7RgbU2S9zfTVdQrj2oPK0Sh38qfLoKaRHVBcB j01vrlve+JWBM3e3dnKOQ8gvRmPFs5L1sVPtzOfivEuvyb5hyUtYl/zDWTDRdpNeWXROBd a/EKk5Y9Dqc+8OTsAfVG21ThopLmL5U= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=e2uivlW0; dmarc=none; spf=none (imf05.hostedemail.com: domain of BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+994827af29a55d2021e7+7484+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708324089; a=rsa-sha256; cv=none; b=ItKp5qky9MgE4emY0TD+R9NU5yrr4h31fagKQJnSSgf7ER8JvGp8Bey/BJ8daxrvKKr2HR cbq/YaNw3zZo6x3lEmbKMM9VttguUlq2VJNAC3HDmTbPw8OTVZu07h9u989Xez9x3iByGS lUxnXadADtCJ74m4U8Mjht8p0HnUdNo= 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=4yvOV2MFFDBEYH3fUNbndLoOzOA31/axOU+QN+8ByXE=; b=e2uivlW03g1+8GmPK2PN83ONDb 8r2sIyKWw55ly82HcTFXQ3kifK+iVITq1bZuyY4AGlqCN3lGKOmYotnk+DiQFqbJw8nBSpHTp1akr SG0I6RDyp6qQP4VegoxnWaOfTFOLB1wpkazAM5VDuh4Waq6h8Be2PRV4KeVXXKSXrEXj8+6nTiLL6 AUiomGcGpS8RyBeDMThtqT4Jj7U0srNcyPcchaLWs4pkpDq4OHqzQaraEVnyCTJqZhUajtp8t39M/ R+77fnfIKA9dsgJ7unLxvnmm7IVQAwscrzyN+5fwMgDmdrTLenopCMcujqXKDOCn07o8A2nse68l8 zmfUA8rA==; 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 1rbx8I-00000009FKl-1Xb6; Mon, 19 Feb 2024 06:28:06 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" , Hugh Dickins , Andrew Morton Cc: Hui Su , linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 17/22] xfs: use shmem_get_folio in in xfile_load Date: Mon, 19 Feb 2024 07:27:25 +0100 Message-Id: <20240219062730.3031391-18-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240219062730.3031391-1-hch@lst.de> References: <20240219062730.3031391-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-Server: rspam09 X-Rspamd-Queue-Id: C5A1310000C X-Stat-Signature: j8tb1e3xd1x8rjguqez98fxym5aea1rn X-Rspam-User: X-HE-Tag: 1708324089-319647 X-HE-Meta: U2FsdGVkX18ehr0CtrH6RVGbJz5lTZyXS+JDi49GGKGWFCtBudCVZ1PRVgfJTALzfoP+D/fS2uC8wp7WGTi/PTPG5d35LB6NFPGdYWA1+uywS0guo9dyjcUpbeVep1xvsYvMfD16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4KGhyJtFWuxfPy/wjJ0/u45uBn/cMdaSqOnDulDLA4zFHjazM5KQCtctsbUNXPx2MVHcnEd6PrdJE9qNShPOFuqroHGsAeDclDly//Flzl8v2QHZ2JT0B+F0O/Cgj7YBO99ScZwxiW3mtXtKMcm6jgTn4phMv54Jk2ZzJK8ZAj1kMaGe0d2zqyqpLXRVJsq5YlCyqPAfoCJptFqBxbAKjf8F0m59UUZ3Ujh/G9GLs8vOjdRNEN+loXF4yrDNcpi+aYNZMUz4XZoj0caRlDmFq3zWQE8GuNgfL7HGGthSX62d2rJ+Lwr4crC3BDZZl2A3PpzgIDIkgRWa1/pR76J44yjBw== 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 in xfile_load instead of using shmem_read_mapping_page_gfp. This gets us support for large folios and also optimized reading from unallocated space, as shmem_get_folio with SGP_READ won't allocate a page for them just to zero the content. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/scrub/xfile.c | 61 +++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c index a4480f4020ae16..2229f0b7f9ca49 100644 --- a/fs/xfs/scrub/xfile.c +++ b/fs/xfs/scrub/xfile.c @@ -34,13 +34,6 @@ * xfiles assume that the caller will handle all required concurrency * management; standard vfs locks (freezer and inode) are not taken. Reads * and writes are satisfied directly from the page cache. - * - * NOTE: The current shmemfs implementation has a quirk that in-kernel reads - * of a hole cause a page to be mapped into the file. If you are going to - * create a sparse xfile, please be careful about reading from uninitialized - * parts of the file. These pages are !Uptodate and will eventually be - * reclaimed if not written, but in the short term this boosts memory - * consumption. */ /* @@ -118,10 +111,7 @@ xfile_load( loff_t pos) { struct inode *inode = file_inode(xf->file); - struct address_space *mapping = inode->i_mapping; - struct page *page = NULL; unsigned int pflags; - int error = 0; if (count > MAX_RW_COUNT) return -ENOMEM; @@ -132,43 +122,44 @@ xfile_load( pflags = memalloc_nofs_save(); while (count > 0) { + struct folio *folio; unsigned int len; + unsigned int offset; - len = min_t(ssize_t, count, PAGE_SIZE - offset_in_page(pos)); - - /* - * In-kernel reads of a shmem file cause it to allocate a page - * if the mapping shows a hole. Therefore, if we hit ENOMEM - * we can continue by zeroing the caller's buffer. - */ - page = shmem_read_mapping_page_gfp(mapping, pos >> PAGE_SHIFT, - __GFP_NOWARN); - if (IS_ERR(page)) { - error = PTR_ERR(page); - if (error != -ENOMEM) { - error = -ENOMEM; + if (shmem_get_folio(inode, pos >> PAGE_SHIFT, &folio, + SGP_READ) < 0) + break; + if (!folio) { + /* + * No data stored at this offset, just zero the output + * buffer until the next page boundary. + */ + len = min_t(ssize_t, count, + PAGE_SIZE - offset_in_page(pos)); + memset(buf, 0, len); + } else { + if (filemap_check_wb_err(inode->i_mapping, 0)) { + folio_unlock(folio); + folio_put(folio); break; } - memset(buf, 0, len); - goto advance; - } - - /* - * xfile pages must never be mapped into userspace, so - * we skip the dcache flush. - */ - memcpy(buf, page_address(page) + offset_in_page(pos), len); - put_page(page); + offset = offset_in_folio(folio, pos); + len = min_t(ssize_t, count, folio_size(folio) - offset); + memcpy(buf, folio_address(folio) + offset, len); -advance: + folio_unlock(folio); + folio_put(folio); + } count -= len; pos += len; buf += len; } memalloc_nofs_restore(pflags); - return error; + if (count) + return -ENOMEM; + return 0; } /*