From nobody Mon Feb 9 02:15:19 2026 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 455D033C52A for ; Thu, 22 Jan 2026 10:45:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769078737; cv=none; b=E7VZLojQ1gPlamD3xbihBbU2Oig34T8nkO9mNzUXWbqA9rpLJ4i6AhOuC54jF1m42mPUSQAy07I2j13ARzWdpWPY1rkPJiRZkPllOMdpT9ld73jbCRPhFYo/Ei/dzbM2yqTtuJwMKuNGuLEKav+kt/9JEqHofJsd/eHLDFt8mwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769078737; c=relaxed/simple; bh=OQ/14+21E3rYPVvuExbXefOINWO0Mspa46Q274FShas=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: References; b=aBXFxV+TuqMPHqB1EH7t0KBcAshm/uCXqUPBkk8BytU6VHZk9/wmGJ/qmADvmA40y4YKIashMmVEzf322s8a3LkYeyjKIaffIYDVOPFclbvlBRhfBzq3VOrlHhhEplvzBW2AGBGyvrjpbQYr5E4Bj9NJkN971otyvajgC8Nh73Y= 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=ZpDNioPP; arc=none smtp.client-ip=203.254.224.33 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="ZpDNioPP" Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20260122104530epoutp03a86811e48e0987d3b34612a81ea20275~NB7uXRjcf3276432764epoutp03z for ; Thu, 22 Jan 2026 10:45:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20260122104530epoutp03a86811e48e0987d3b34612a81ea20275~NB7uXRjcf3276432764epoutp03z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769078730; bh=g1ZzHHIazvqQ8EVOQ6O1Uz7npkVii8J0s0Sohl8LpwY=; h=From:To:Cc:Subject:Date:References:From; b=ZpDNioPPHZgFxxX8mpTn9xQZzdGo12q+6ItbUCysN2eqecE7M59J37n2R+uK/5+x4 LvxmZ5Jbb9nt6ISeeNec2rAsrzRLnuELlezWcKOPPfzns0WNst7JDqAw1rc5Nfdkif yTJ2lZWvuzE7wAiE+1aJqG/v6/awV8QarW13/gHM= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPS id 20260122104530epcas1p1b9d1fe4258abad16ecf165759e16e312~NB7uHwQbd1545315453epcas1p1N; Thu, 22 Jan 2026 10:45:30 +0000 (GMT) Received: from epcas1p4.samsung.com (unknown [182.195.38.192]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dxd4p2yfzz3hhT4; Thu, 22 Jan 2026 10:45:30 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20260122104529epcas1p4ea35d60de87ef7ed53c5a02b0ce921b2~NB7tUqcVX3212532125epcas1p4J; Thu, 22 Jan 2026 10:45:29 +0000 (GMT) Received: from mypc.. (unknown [10.253.98.103]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260122104529epsmtip239ee9e17bfd43b0cb9851badab11a583~NB7tSGW6C0460404604epsmtip2O; Thu, 22 Jan 2026 10:45:29 +0000 (GMT) From: Yeongjin Gil To: jaegeuk@kernel.org, chao@kernel.org, jyh429@gmail.com, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: Yeongjin Gil , Sungjong Seo , Sunmin Jeong Subject: [PATCH v2] f2fs: optimize f2fs_overwrite_io() for f2fs_iomap_begin Date: Thu, 22 Jan 2026 19:45:27 +0900 Message-ID: <20260122104527.416871-1-youngjin.gil@samsung.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CMS-MailID: 20260122104529epcas1p4ea35d60de87ef7ed53c5a02b0ce921b2 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 101P cpgsPolicy: CPGSC10-711,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260122104529epcas1p4ea35d60de87ef7ed53c5a02b0ce921b2 References: When overwriting already allocated blocks, f2fs_iomap_begin() calls f2fs_overwrite_io() to check block mappings. However, f2fs_overwrite_io() iterates through all mapped blocks in the range, which can be inefficient for fragmented files with large I/O requests. This patch optimizes f2fs_overwrite_io() by adding a 'check_first' parameter and introducing __f2fs_overwrite_io() helper. When called from f2fs_iomap_begin(), we only check the first mapping to determine if the range is already allocated, which is sufficient for setting map.m_may_create. This optimization significantly reduces the number of f2fs_map_blocks() calls in f2fs_overwrite_io() when called from f2fs_iomap_begin(), especially for fragmented files with large I/O requests. Fixes: 351bc761338d ("f2fs: optimize f2fs DIO overwrites") Reviewed-by: Sungjong Seo Reviewed-by: Sunmin Jeong Signed-off-by: Yeongjin Gil Reviewed-by: Chao Yu --- fs/f2fs/data.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 2e133a723b99..11c262afad65 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1851,7 +1851,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_= map_blocks *map, int flag) return err; } =20 -bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len) +static bool __f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t le= n, + bool check_first) { struct f2fs_map_blocks map; block_t last_lblk; @@ -1873,10 +1874,17 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t = pos, size_t len) if (err || map.m_len =3D=3D 0) return false; map.m_lblk +=3D map.m_len; + if (check_first) + break; } return true; } =20 +bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len) +{ + return __f2fs_overwrite_io(inode, pos, len, false); +} + static int f2fs_xattr_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo) { @@ -4443,7 +4451,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff= _t offset, loff_t length, * f2fs_map_lock and f2fs_balance_fs are not necessary. */ if ((flags & IOMAP_WRITE) && - !f2fs_overwrite_io(inode, offset, length)) + !__f2fs_overwrite_io(inode, offset, length, true)) map.m_may_create =3D true; =20 err =3D f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_DIO); --=20 2.43.0