From patchwork Fri Feb 9 14:29:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Gomez X-Patchwork-Id: 13551414 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 87D19C4829D for ; Fri, 9 Feb 2024 14:29:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EBBE6B008A; Fri, 9 Feb 2024 09:29:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BDEF6B0088; Fri, 9 Feb 2024 09:29:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE5886B0093; Fri, 9 Feb 2024 09:29:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9F3AA6B0087 for ; Fri, 9 Feb 2024 09:29:11 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 74C9E1210BE for ; Fri, 9 Feb 2024 14:29:11 +0000 (UTC) X-FDA: 81772497702.02.0CDF227 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by imf05.hostedemail.com (Postfix) with ESMTP id 6B31510000E for ; Fri, 9 Feb 2024 14:29:08 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=iNLm28Q5; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf05.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707488948; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5EX9mww1Yf0rOpRLklIYKmjmJtYHS5jxFy+jU2z9Pew=; b=wlIfd2BgKxoVNWp3Oni67A76pLKTYWFVpKfmHj2gZQMPuMxqPm6V8PoPeOXN7Z4Gnp2Hj+ 4HAQOR3gVjbHw71vtQMO6Menx3sVWghj6zYETlrl9P5QaISmL3ya7wiXNBDz0Q42HqYc17 WTPoo9lFHmZi8u14if0kqjRXHB66DNo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=iNLm28Q5; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf05.hostedemail.com: domain of da.gomez@samsung.com designates 210.118.77.11 as permitted sender) smtp.mailfrom=da.gomez@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707488948; a=rsa-sha256; cv=none; b=bhiu8bUOX8448q2mEadwz2WRNEls+WwDJEDpLtmvr+VcTNXxxXXBNg5Ybxtf8vU5/oAKcT TEW2Mx08zEsLfmsENTXeQdXKrEtHsb2kK33pOz9Xt0c65jxlMxjlBUH3lNWOWtu/4iGRhh mo1WDs4p7TgxiloXRnky1jyU5MTU1os= Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20240209142905euoutp0140e3fb5e22791c18770833777b982c57~yOCZS00cg2778527785euoutp01c for ; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20240209142905euoutp0140e3fb5e22791c18770833777b982c57~yOCZS00cg2778527785euoutp01c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1707488946; bh=5EX9mww1Yf0rOpRLklIYKmjmJtYHS5jxFy+jU2z9Pew=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=iNLm28Q52eLnCOfv8G9K1mU0dX3bnVJ7nTJpdf1iOu6zrWSahXzu798GPGN2uutw3 dH9S2x4Fe0vbb3SYya8z7xMMwS4Tf9T4HQ5lzJx9Z0blo8q3MI7YDC/s9JKhNpAGMI ea1TZ65+ON5c7yQwpys2kl8OdcvYvuKc4Kq8T3Io= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20240209142905eucas1p2901cf7d34b6c0b8739cc8cd9c806d0b4~yOCY8xfYl2314723147eucas1p2o; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id DA.F5.09814.1B636C56; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4~yOCYgKpDC0208802088eucas1p2M; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240209142905eusmtrp2d681160c1113aac64263cd808d288845~yOCYfYvDM2110121101eusmtrp2a; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) X-AuditID: cbfec7f4-711ff70000002656-39-65c636b16a2a Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 48.6F.09146.0B636C56; Fri, 9 Feb 2024 14:29:05 +0000 (GMT) Received: from CAMSVWEXC01.scsc.local (unknown [106.1.227.71]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20240209142904eusmtip2518107333d642b9a564504242782a9dc~yOCYU-zq50196001960eusmtip2M; Fri, 9 Feb 2024 14:29:04 +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; Fri, 9 Feb 2024 14:29:04 +0000 Received: from CAMSVWEXC02.scsc.local ([::1]) by CAMSVWEXC02.scsc.local ([fe80::3c08:6c51:fa0a:6384%13]) with mapi id 15.00.1497.012; Fri, 9 Feb 2024 14:29:04 +0000 From: Daniel Gomez To: "viro@zeniv.linux.org.uk" , "brauner@kernel.org" , "jack@suse.cz" , "hughd@google.com" , "akpm@linux-foundation.org" CC: "dagmcr@gmail.com" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "willy@infradead.org" , "hch@infradead.org" , "mcgrof@kernel.org" , Pankaj Raghav , "gost.dev@samsung.com" , "Daniel Gomez" Subject: [RFC PATCH 3/9] shmem: move folio zero operation to write_begin() Thread-Topic: [RFC PATCH 3/9] shmem: move folio zero operation to write_begin() Thread-Index: AQHaW2RUQo5uE9Fs4EG+AkzmtoGKGQ== Date: Fri, 9 Feb 2024 14:29:02 +0000 Message-ID: <20240209142901.126894-4-da.gomez@samsung.com> In-Reply-To: <20240209142901.126894-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 x-originating-ip: [106.110.32.67] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPKsWRmVeSWpSXmKPExsWy7djP87obzY6lGly5o2gxZ/0aNovXhz8x Wpzt+81mcXrCIiaLp5/6WCxmT29mstiz9ySLxeVdc9gs7q35z2pxY8JTRovzf4+zWvz+MYfN gcdj56y77B4LNpV6bF6h5bFpVSebx6ZPk9g9Tsz4zeJxZsERdo/Pm+Q8Nj15yxTAGcVlk5Ka k1mW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IvyJ9QJNp/4F95iroSS3FGoqEWc1FxIgDA8rDp3QMAAA== X-CMS-MailID: 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4 X-Msg-Generator: CA X-RootMTR: 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20240209142905eucas1p2df56a08287a84a5fa004142100926bb4 References: <20240209142901.126894-1-da.gomez@samsung.com> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6B31510000E X-Stat-Signature: wnde1qh58f3pz8ogrbsywz1z1nrj1u3r X-HE-Tag: 1707488948-147150 X-HE-Meta: U2FsdGVkX1878NKHaxkfuVeSKC9ZxWArFvQz2hJFq/Xd6nGTjfdNM2Yu45fD4L4iBKdL2UlIuEAh9lfvHe+3bD2n82YyhNiIH6vQGrfRbG1b8Y/FRFubYXtnTn11C86x00x1cJDg32XwZWfrQEihlKeSm/yvBpledT9dACUqrrxY9Vnj0qQy+hjWYZMnoNmeH6dF/LpbN3Ivowe+5r+pUIVFzdVeyNKu7GFERuTBVjCWvWD9N8G1nh6cwSj3LESF726Z67wgeK1AyPyaoi4Z4BanVB5V7MTT0ID7dhM+liV/5RF/X90JsGb2RXTyj/g4zPGUdq57ulL7lc5vHpW3X+qhPQ0JB6UvS8aQ3QDa9X7icvLqVUujkgcONlaZAlQSP1j+zNxvJDMvZ3ezKwDVeK/HbfZZlwFND/2rWuC7YvQN4K3bCHmWiV7V3IZhoLyQMs2RG9WK1Xb4mnWkcCwaVjBoee5LjaxQoHcHxpkZ1KCEhH+C/tE3m5+6xoceTIKSQp/YIBPYmEJ/9dHDEqNLZiBM9It637dyQtI1QxwvSHn1ZiqlfFmViAWZa6dhA0GEucZO5q/oiqUiySrLvnTGB8V/PspdqbKp6PRjTmMUqod5tzWhr5VGvPmpLJW27VKtEUgiw8v748eL2WERszaeMHbzB3sX/9drCWLPvsAAJuh7FNYSfAYd546pbbDI4UBQEY1G7fbdBV96+yVvvk5+2Yb6YrmDITQjyzvotuLZ/xXGgtqqcQa7LI6uQ3IKeR5w1aSN+itBh6tynsSINIBfjchWicimbqsQ3rC00YV2GWy9WDz738s6qVRfh9yEA50HqgTIFgW95SItd/WgxI0B772RiOs7+BPP0oCLPaOUdXWHGZ8Xv9gZ6IpMtaarTj/EtmjPxTrQx426DaTzpjiUdPfViXOWLtbh0fbHAT9jilUC1t527jfP4ZCauyAzoc1Wcd0zs7cgNJ8k4hc/WBy cJXWO/Cj lNcwDC7xgJo7V5bZ+zrA4RrwlpCr0Vt/VmhkKMgSScKHh0INMkyFBfn1nH5Cp0G0ZF4sTzMN8i+NW1WCb4VejW2dnNJbAJZvS8kmV+fFyc+5X0stfewvxv8KFBpTQ1ZJO3K5N274e/J44PZ8tIFgXr7gWaci4HXh9ts7PMYRVVVsnyNARBSSbUvbLcppzLTm+c4Whyt5RfW38auKWJejnd/Lgog== 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: 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 5980d7b94f65..3bddf7a89c18 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)); } +static inline bool sfs_is_any_uptodate(struct folio *folio) +{ + struct inode *inode = folio->mapping->host; + struct shmem_folio_state *sfs = 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)); } +static inline bool shmem_is_any_uptodate(struct folio *folio) +{ + struct shmem_folio_state *sfs = 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) { @@ -2845,6 +2862,9 @@ shmem_write_begin(struct file *file, struct address_space *mapping, if (ret) return ret; + if (!shmem_is_any_uptodate(folio)) + folio_zero_range(folio, 0, folio_size(folio)); + *pagep = folio_file_page(folio, index); if (PageHWPoison(*pagep)) { folio_unlock(folio); @@ -2867,13 +2887,6 @@ shmem_write_end(struct file *file, struct address_space *mapping, if (pos + copied > inode->i_size) i_size_write(inode, pos + copied); - if (!folio_test_uptodate(folio)) { - if (copied < folio_size(folio)) { - size_t from = 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);