From patchwork Fri Jan 26 13:28:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13532578 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 D076EC47DDF for ; Fri, 26 Jan 2024 13:30:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E8BE6B008C; Fri, 26 Jan 2024 08:30:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6973E6B0092; Fri, 26 Jan 2024 08:30:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5603F6B0093; Fri, 26 Jan 2024 08:30:17 -0500 (EST) 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 46F636B008C for ; Fri, 26 Jan 2024 08:30:17 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 241B0C0F90 for ; Fri, 26 Jan 2024 13:30:17 +0000 (UTC) X-FDA: 81721546074.09.A3E4851 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 806FB1C001E for ; Fri, 26 Jan 2024 13:30:15 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=etgfs9Cw; dmarc=none; spf=none (imf18.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=1706275815; 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=G4dvPmDhKQKKA7EvO7oOePDM7y3n+zoGGSb2RNyoFKM=; b=G3wTjDF1+2TbQNMYIEgq1OADa3m4gdM4x973RpdMI8UJn4pQB1L49NRh0RViP0xOJloxe/ 1XwLmiVc0ES7TaGVOHRmAEwhf0TxtAdfQBVPxX1hee8ZlQolIDknYZz6Ajg8jOv7bxYxFL L6JTpeoR3/ne4WbXZam+GfY4m5GT7nU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=etgfs9Cw; dmarc=none; spf=none (imf18.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=1706275815; a=rsa-sha256; cv=none; b=DwjxNHAKZHPOWVznJI8t198e2Uu1+/TAd2I99WmQ+gNjh60lMlsoPfiCbVM7hiLZHyoNjt fYIkf4DIiRQLskDsHndzyECCbEd1E6CWBrYR/l7OypXQknNOzRkQW+W7Kw/ByEd9W47QVg 2U/fwq5TlemhT3QjR1Oy+yTgeorxjRE= 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=G4dvPmDhKQKKA7EvO7oOePDM7y3n+zoGGSb2RNyoFKM=; b=etgfs9CwZeMJnpY//1CFGpRXzQ m41dHwbhFTFDpvLigQ3wXMdssEfgRfx0CAvm2jPGFCQuXWAbazyl+lChXtSsIYhbWy3V6TKzyKWah 5NnSr6fnWlBFxVRuvAAA1sqxZtVWp+SX8nzldsmg4M/ZsfW6S+oaFoyWQXdaCcZmi5ZhsItVFFxO3 gk5efBkEpFDP8n7Lz26bVYwrTKqVKSc6iMudbRzvxJ3BCzctRF7Ig6AEP9bfI7Dj6TDIf053wMnpI 4OicIB9TJowMoYh+rk1FNw8cozNfvdpVT4nB3gcbJV/bBmqaaeUsAI8fAzW3zM73RmqT4fnkTHUlT aENs/zjA==; 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 1rTMHc-00000004CtJ-2CJD; Fri, 26 Jan 2024 13:30:13 +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 15/21] xfs: use shmem_get_folio in in xfile_load Date: Fri, 26 Jan 2024 14:28:57 +0100 Message-Id: <20240126132903.2700077-16-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: 806FB1C001E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: a5hptjuopra695p535kegurown3eft7c X-HE-Tag: 1706275815-374200 X-HE-Meta: U2FsdGVkX1/ckkNeeo3y3IPjzEHvUzTnlvQ6tHCnlAXCLuVhIrb1uMf0rJt1+y2dMWRjg8K6Om6Jxj8joktVqo9neVnJlS8Y9B52g/KQS2g2pysErb7q9pdxBP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Ss9NtzRE166Th/GnEUx3mc+vwg4ToumlWmbQna7zjGFX+fhZ5q6sZVeWobrgR0hIsEfwy2KMel6NQXMXSWyu2voxBUk+zGjK9TDVlGz2Dwzg3U08QraWgcCSpXP03GB6hVcnpvtroGsRrj8DKzm7dtQehYyq1/YHrln0w5bjpL/e0mbPXHaXUZyw739uzI8r1FlcAKExOJFVBLI5PcTOK+8VD7dLySAUHDjrxjTKt98o/CuTeUoMHrbNJXG2+W/d4pt/wyK2oy46V9IUMkZ4V8naSeqYzHdZ9wR2qh0Bgm5vAoiiFGu+akTshUD2fqzwan4lk= 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 | 63 ++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c index c71c853c9ffdd7..077f9ce6e81409 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,46 @@ 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 (folio_test_hwpoison(folio) || + (folio_test_large(folio) && + folio_test_has_hwpoisoned(folio))) { + 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; } /*