From patchwork Mon Feb 19 06:27:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13562218 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 A1A5BC48260 for ; Mon, 19 Feb 2024 06:28:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1143A8D0014; Mon, 19 Feb 2024 01:28:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C4D98D0007; Mon, 19 Feb 2024 01:28:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E32FE8D0014; Mon, 19 Feb 2024 01:28:08 -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 CBD568D0007 for ; Mon, 19 Feb 2024 01:28:08 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A2C3080215 for ; Mon, 19 Feb 2024 06:28:08 +0000 (UTC) X-FDA: 81807573456.30.26F61BC Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP id 305A2140005 for ; Mon, 19 Feb 2024 06:28:06 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=K0ls48wK; spf=none (imf23.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; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708324087; 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=xrj4yc1TectagwrKRxl6KUlUJmMOtbHo6U4sVcgHs4o=; b=8Vszv3F8aAsO2K8FiaSXxhCDvlGKiYs1yTXvY0Bjd2Kcbuar6yaq31NZAKjHh6XujlL1WH nhUH6WQPNSqVzfOM3zjFhR1gEpzYoV5ycvjVl0DaYGNpDFN2UXn6ycyl5jXOV/8+yNu4s5 bBseGbrIoe8++ZWMdzw07FqBC2Ncgeg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=K0ls48wK; spf=none (imf23.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; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708324087; a=rsa-sha256; cv=none; b=Jjx2v/hvvCV6p1DLNYx2SSzCFAO24gh4riuJnbqh8jXND6H0A2CxluAe+AUpJUgxXR0l+a Xt2wxnJKqhT4Hps47A5Kqla75Er5sAHfprRu0iL25AMzPMFeNYAu5uuRIT4SGZwe89PueD 4NQEMzc/xn+YwOrT/E9477oJFkqPQWs= 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=xrj4yc1TectagwrKRxl6KUlUJmMOtbHo6U4sVcgHs4o=; b=K0ls48wK4VPl7lGplCByCy2qS2 geFAEADRgLi6t7LWg1z/FXMmJ0itwU1BYFTfhBdUH9pJPD+qLjtyUvdChARsW6pEBkFoARx2vIZrj SI/ss6kgcLRD8ATZVVVDNGFNS6D8/zXbBYfguetpuIAXflGOD589THOcp3aQd4gE+MU5mgH094zip 76Kbn1Ez8zG3yiCD7GJr/SgeVr4/4CYuVbfQAfFHLnTeY+//tQzyxvRSHiWQxp1NI/kXwDS+1zzBi LGz0boxbLaNP2imfGV9qDwsIF0bTjiqRdXR0CWqAyiQ4tOjeWgbDTupq5xQmALMldmiUlLZnjfmm7 9/E8/DgQ==; 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 1rbx8F-00000009FJm-3UmA; Mon, 19 Feb 2024 06:28:04 +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 16/22] xfs: use shmem_get_folio in xfile_obj_store Date: Mon, 19 Feb 2024 07:27:24 +0100 Message-Id: <20240219062730.3031391-17-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-Queue-Id: 305A2140005 X-Rspam-User: X-Stat-Signature: 935q631pu5oj6877e5dj9rki47cned7e X-Rspamd-Server: rspam01 X-HE-Tag: 1708324086-199179 X-HE-Meta: U2FsdGVkX1+zqjetwcC4XAf7LBbvSxKz4gmLKzGBfDA+GfvQk5EPWZzba41KaGYcy144Ey3ykFS6RmWcryPaAXlF5qanuqc5pKTsE6d51Vo/4Q1ooU0CIFDfZYT01VxH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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 009a760cb690a0..a4480f4020ae16 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. */