From patchwork Mon Jan 29 14:34: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: 13535773 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 EF619C47DB3 for ; Mon, 29 Jan 2024 14:36:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 851F96B00B4; Mon, 29 Jan 2024 09:36:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 80B3E6B00B5; Mon, 29 Jan 2024 09:36:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A35A6B00B6; Mon, 29 Jan 2024 09:36:03 -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 5722B6B00B4 for ; Mon, 29 Jan 2024 09:36:03 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3172016047E for ; Mon, 29 Jan 2024 14:36:03 +0000 (UTC) X-FDA: 81732598206.12.F901141 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf04.hostedemail.com (Postfix) with ESMTP id 876B340017 for ; Mon, 29 Jan 2024 14:36:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xd4dyVir; spf=none (imf04.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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706538961; 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=3bl9Vn2yOyKHb24tVNHqKgoHaJ5sWqc0dgEDrV96FhM=; b=t/qtjmxwIBXJ9M8biKUhvLmb37NBvMGgCrdZmb1VnJal8xWtKVl3HC+7Icw5CMgYBOLYNE P8nGA9lnJfgEhBcOFLLx/ErLAjc1e7Qnb3+T3KwV/uh8jdyD0FMz7fm6Iafn0lh+jLgpWU ra6CfG9vseLpKs4Ng0sys+DwjdkuEOU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xd4dyVir; spf=none (imf04.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; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706538961; a=rsa-sha256; cv=none; b=Xd6p4oyKrXAO/8Sku4/M9QYCQ8IIYcOCTiV9QTpAh9FLD7OKsyo/WGPI7LequMqvLhYIQM cOheN0UcG4HZt3jZhodx73EIhnRDDFx8zZpQWSyDi4h2qYvH9nnLGYEb40jsG19mpr9NNf g7Jcg2sFIl/pR+0Q9mZ77Pd1BHH7JN0= 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=3bl9Vn2yOyKHb24tVNHqKgoHaJ5sWqc0dgEDrV96FhM=; b=xd4dyVir7JMUrm1jb9NZE9GgiO tdiEXqjRTLQoFC1KU3rmyQeK8lKBa/w7bbKGzeZuFsG4IApi8pnzm+nFnLvYUdLkPVgK6NWDxp5B+ YPABBsW/JNftl/Hd6sn9zwpZ6uSgC/Sq3Py+OnYLYEdVdW/OBryAYG3Oc5URqlBe0lTECzwna+bQY ejhdJuVVpcMZ93ewqWYBT+Dj97w1Oc9ihWNJ1RJPbaCLMrcWmjE8ZP7ynq98reE4jRWI4LPh0GWmh /KUpAOCpF5MJRMsnD261C+fQdiJvWD932ekEZmquQzujHqTLs59C4bFNCGVbGYDIs3yJcuLqTARpa fDwI9xng==; 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 1rUSjt-0000000D6Os-3AWh; Mon, 29 Jan 2024 14:35:59 +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/20] xfs: use shmem_get_folio in in xfile_load Date: Mon, 29 Jan 2024 15:34:57 +0100 Message-Id: <20240129143502.189370-16-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: 876B340017 X-Rspam-User: X-Stat-Signature: 3ief1okebyz9hpmd81shxcjh1gm98ite X-Rspamd-Server: rspam01 X-HE-Tag: 1706538961-642591 X-HE-Meta: U2FsdGVkX18hEzYq4PPJxfyzEA5MIPoJNpODKBY4qUL4FcTvRh496SB2WdZKCiyhjX3ZDd8bxhetCZr+fw8NKbIMBfGbkCFfE2PQQVCuwyYIINaT6jHOw+yvusdxEEY//VXuKCuLr9cyenzRPPZy+H/z5X3yg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GKckZOW4XsuTWEOF+F1jC5kHDPk8mrrZa4QODwgaSibyxmCwLQRRTGJGxrdjLfG2whCbhRF/4CM4O/IAHBnhvLjiEwhfaZZLINJYUyxo9rQ5xJ9fdwTIU/2QMju0VJ9CPwBlc66mp7hf4dG97lP1DPmsbu/mIq4dz/XZhwhFsVWzKtkxuc29CeJQqXVeAu37MRqEnyQkIfgllVpQslQ+hX0LXzDzWPzSGC68iFv97ZB8WsUGGrcDqoDHl2yxjqRYme51d9LOaXdy6GN3tWA5kF7oNRw+cExZdeWzeXDL9bl/OTQXSSi2P1Jj1WWqz2Q0sG5U= 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 2b4819902b4cc3..c524fe9980fea2 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; } /*