Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3114227lqo; Tue, 14 May 2024 23:07:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeeD56B1BBkQpQfeEPUPe+V+xhuxOT8dAxK4SVMRawUvWq5q4qi8BQ5/RT9skJrRUVXwXEY1R3pPtaXQ5ME2dypJDZtFhFnij+rMiYyQ== X-Google-Smtp-Source: AGHT+IHMHmuJAA+trXKDXog32gL2DZypwlq5zZ1EhYRCsRb32cLvfyCCCFy4z+RX+DGgyM4CqRvd X-Received: by 2002:a05:6a00:1409:b0:6e7:4abe:85a0 with SMTP id d2e1a72fcca58-6f4e02c65b0mr18693968b3a.14.1715753224371; Tue, 14 May 2024 23:07:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715753224; cv=pass; d=google.com; s=arc-20160816; b=B1C7BBfgZ3btOk1jSNu9H7SBqTw/QX8UyFoccQ9mAf1QIlxH0BlaF2AXuYAa5vCAT9 WiZS3d1NMjdH9H3MmTsVM9Z64OaajiAqnQy+tYqi4kSi6QvBSDoOl8P0EpcEJuGW8Q3W Fr9dD5jQked4cPgM5/viYneQU/7EjeQ6fsYjAZVyrTtr+AOdWo5LLCI58lgpsdRGd7eo i3iNC+nMIEW7jmtpb0k3baMBxb6E456YSJ3rQt4zNU5XKinIfxrhLV06K+wLmlkciLYZ KUEIkm4FKrbLpcoAvM4s35zcFrp6fMTq7ZrEyzFwiYs+eYUVBuUGQgC+MWEUdIAFPn9w Uopg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:cms-type:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:content-transfer-encoding:content-language :accept-language:in-reply-to:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature:dkim-filter; bh=seKa6sjLynK9cdKjqPABBz7tIQiUkhLa6rE9aIXSk0U=; fh=boE2T1tfXWhPiAXKUEd+pJodvJpwHMz3xvNd2cVdM48=; b=V6EOx5MK8YYLipJ0mhxEOoCiAHx0LiqF5lWO+Y3s5C9TOSvMnfI9nU7sPoCSiN/r+0 viqxvMdGTBAGXOgoUWq7MP5IH9slh674x5fWLAAkUZX0W97+bCr9adBEMkf4ExxKgX7R NG/dPIB/z5gr+FdrMJYMITijXcGUWSTBrJWuGo8LnYJIy/dptGqZQPKw8aX7ppDShin9 qpfJttcvrgDvPHs7WZH1vXAkmvLdJdcoVMNzs3TQGTa45J6Tb7M57P8ctxJDOTwTC+yG 3s/HIEGYPt2v0ET8RQO0T5+pEyeUK33lOgHR1RIvHg7/1sMSrC7tEwhv+y6VsU5LetEU pi4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=q4A3cBzV; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-179508-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179508-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-63409e8266bsi13685822a12.74.2024.05.14.23.07.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 23:07:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179508-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=q4A3cBzV; arc=pass (i=1 spf=pass spfdomain=samsung.com dkim=pass dkdomain=samsung.com dmarc=pass fromdomain=samsung.com); spf=pass (google.com: domain of linux-kernel+bounces-179508-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179508-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DF6C5282C71 for ; Wed, 15 May 2024 06:06:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 469C13BBF6; Wed, 15 May 2024 06:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="q4A3cBzV" Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 160583BBD2 for ; Wed, 15 May 2024 06:06:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715753200; cv=none; b=TzkWr5lhip4/lBWGDshiogDQcRJrrXVI1VFJpSTCavhqw+CFSMsUXRRK61e4t3dsBgxfAKlYb2lwUIxmauwSlGDcWG+66gcb6nJgGlDYGeJB5ZZnxRn9yQwFpOz0+QQSI/9FPSIY4b9LUiYY+jv+7FIdgcQF1BQHoIBnh25w9/s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715753200; c=relaxed/simple; bh=3rCXLWBXfZfMLO9t81QDeCVXjTEwchdPf8WSGMNAQ1E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version:References; b=PFb1eLgVHPPbh/E+k35HgFnTyRWHETEfdpy9+Lnx64mVmZuEUXz2Q+pLN4kyBE2gOVGi/mKm3PD3gomw4NQv2w2XNtXiMFz07dD/+kTis5WayfCObMs1MQH8M7dI1ZyvxN3eS8i6VBaO84I6bWjToFreV8i+8XCFz/+fv7kuV+4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=q4A3cBzV; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240515055728euoutp012df0be609d88c87c1ca5e8cdcc712082~Pk-FlXEUx1508315083euoutp01c for ; Wed, 15 May 2024 05:57:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240515055728euoutp012df0be609d88c87c1ca5e8cdcc712082~Pk-FlXEUx1508315083euoutp01c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1715752648; bh=seKa6sjLynK9cdKjqPABBz7tIQiUkhLa6rE9aIXSk0U=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=q4A3cBzVn9KE2ydc+PwPCpAz6s/hUrGumb4IqYJW7f4Ed9Y3y7Eg2TL0CNMlxnV+N aV/2w1EHQIxJYkiie0OXg73ruCyKvawmsL0Qa8iNP1M+YkbXf1ybCmfIGNQb360oDW 8fRKS8sJ+PtJ9+0mqjKHY9TJhGyK9/GrYMbiDH1M= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20240515055727eucas1p1cce4046f8f5533c6eea17fae56ae77c7~Pk-FRrwRp2649226492eucas1p1m; Wed, 15 May 2024 05:57:27 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 48.BC.09624.7CE44466; Wed, 15 May 2024 06:57:27 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240515055727eucas1p2413c65b8b227ac0c6007b4600574abd8~Pk-E2YLc31177811778eucas1p2O; Wed, 15 May 2024 05:57:27 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20240515055727eusmtrp12a11692dcfa90fab16fe695c42ed0ffa~Pk-E1UwJs0390703907eusmtrp1z; Wed, 15 May 2024 05:57:27 +0000 (GMT) X-AuditID: cbfec7f2-c11ff70000002598-4f-66444ec7cb92 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id E6.F1.09010.7CE44466; Wed, 15 May 2024 06:57:27 +0100 (BST) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240515055727eusmtip2fc68020aac0eb188bacb160d886bb72a~Pk-EpQJBJ1596015960eusmtip2L; Wed, 15 May 2024 05:57:27 +0000 (GMT) Received: from CAMSVWEXC02.scsc.local (2002:6a01:e348::6a01:e348) by CAMSVWEXC01.scsc.local (2002:6a01:e347::6a01:e347) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 15 May 2024 06:57:26 +0100 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Wed, 15 May 2024 06:57:26 +0100 From: Daniel Gomez To: "hughd@google.com" , "akpm@linux-foundation.org" , "willy@infradead.org" , "jack@suse.cz" , "mcgrof@kernel.org" CC: "linux-mm@kvack.org" , "linux-xfs@vger.kernel.org" , "djwong@kernel.org" , "Pankaj Raghav" , "dagmcr@gmail.com" , "yosryahmed@google.com" , "baolin.wang@linux.alibaba.com" , "ritesh.list@gmail.com" , "lsf-pc@lists.linux-foundation.org" , "david@redhat.com" , "chandan.babu@oracle.com" , "linux-kernel@vger.kernel.org" , "brauner@kernel.org" , Daniel Gomez Subject: [PATCH 03/12] shmem: move folio zero operation to write_begin() Thread-Topic: [PATCH 03/12] shmem: move folio zero operation to write_begin() Thread-Index: AQHapozDwSlh4G2vDEmdcsveZO13yA== Date: Wed, 15 May 2024 05:57:25 +0000 Message-ID: <20240515055719.32577-4-da.gomez@samsung.com> In-Reply-To: <20240515055719.32577-1-da.gomez@samsung.com> Accept-Language: en-US, en-GB Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEKsWRmVeSWpSXmKPExsWy7djP87rH/VzSDOZeUrGYs34Nm8X/vccY LV4f/sRocemonMXZvt9sFl/X/2K2uPyEz+Lppz4Wi9nTm5ksLu+aw2Zxb81/Votdf3awW+x7 vZfZ4saEp4wWB091sFv8/gGU3b4r0kHQY+esu+weCzaVemxeoeWxaVUnm8emT5PYPU7M+M3i sfOhpcfkG8sZPT4+vcXi8X7fVTaPMwuOsHt83iQXwBPFZZOSmpNZllqkb5fAlXHrzD+mgueC FZt/LWNsYLzP18XIySEhYCLxYsNC5i5GLg4hgRWMEjPaFrGBJIQEvjBK9J2QhEh8ZpR4N+U0 M0zH8uYLUEXLGSV+n+KCK5r7azMjhHOGUWLOoh9QzkpGiXtvbrCCtLAJaErsO7mJHSQ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RootMTR: 20240515055727eucas1p2413c65b8b227ac0c6007b4600574abd8 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240515055727eucas1p2413c65b8b227ac0c6007b4600574abd8 References: <20240515055719.32577-1-da.gomez@samsung.com> Simplify zero out operation by moving it from write_end() to the write_begin(). If a large folio does not have any block uptodate when we first get it, zero it out entirely. Signed-off-by: Daniel Gomez --- mm/shmem.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 4818f9fbd328..86ad539b6a0f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -149,6 +149,14 @@ static inline bool sfs_is_fully_uptodate(struct folio = *folio) return bitmap_full(sfs->state, i_blocks_per_folio(inode, folio)); } =20 +static inline bool sfs_is_any_uptodate(struct folio *folio) +{ + struct inode *inode =3D folio->mapping->host; + struct shmem_folio_state *sfs =3D folio->private; + + return !bitmap_empty(sfs->state, i_blocks_per_folio(inode, folio)); +} + static inline bool sfs_is_block_uptodate(struct shmem_folio_state *sfs, unsigned int block) { @@ -239,6 +247,15 @@ static void sfs_free(struct folio *folio, bool force) kfree(folio_detach_private(folio)); } =20 +static inline bool shmem_is_any_uptodate(struct folio *folio) +{ + struct shmem_folio_state *sfs =3D folio->private; + + if (folio_test_large(folio) && sfs) + return sfs_is_any_uptodate(folio); + return folio_test_uptodate(folio); +} + static void shmem_set_range_uptodate(struct folio *folio, size_t off, size_t len) { @@ -2872,6 +2889,9 @@ shmem_write_begin(struct file *file, struct address_s= pace *mapping, if (ret) return ret; =20 + if (!shmem_is_any_uptodate(folio)) + folio_zero_range(folio, 0, folio_size(folio)); + *pagep =3D folio_file_page(folio, index); if (PageHWPoison(*pagep)) { folio_unlock(folio); @@ -2894,13 +2914,6 @@ shmem_write_end(struct file *file, struct address_sp= ace *mapping, if (pos + copied > inode->i_size) i_size_write(inode, pos + copied); =20 - if (!folio_test_uptodate(folio)) { - if (copied < folio_size(folio)) { - size_t from =3D offset_in_folio(folio, pos); - folio_zero_segments(folio, 0, from, - from + copied, folio_size(folio)); - } - } shmem_set_range_uptodate(folio, 0, folio_size(folio)); folio_mark_dirty(folio); folio_unlock(folio); --=20 2.43.0