From nobody Mon Feb 9 02:15:44 2026 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 E70C622424C for ; Fri, 16 Jan 2026 10:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768559033; cv=none; b=EHlgUawZwGcV01rCe/QfM6HVFcE2HHabCqyTbhXxMUS3HvKumq0iuUvNkhbPojBPFyVcp07fdq6+JEzFoz1lY18XAa8uSnietWOph9sz4lmTkU7gukpoz1LWS5NMXyO3mKJzHgrFEgzn4lPQIU//byCtKtTILdnXXqqwWxNol74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768559033; c=relaxed/simple; bh=bLNkiBDv3DNMCpUfH2bXEzyg1Fxeosidddkp68LbAVQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: References; b=OOMhNW+jl8KynqFz2tXFFl3KWpB0sue098JCwtejq4V2+KEf613ViWpITHKtWo2ruZU7SI1ZBj3H8Wftl7A6qg3/uOe2sVZXhFQk6mEh1+hhzewBMJcEeuUvw0IU/akvlT10hbluv+doeqts4XMbGl3LPkPxPH/BKjqfZd0vyPA= 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=cJNDmr/A; arc=none smtp.client-ip=203.254.224.24 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="cJNDmr/A" Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20260116102348epoutp0110782ad90a7129bd1e05c8688cf09a0d~LLxELXGkl2576225762epoutp01Y for ; Fri, 16 Jan 2026 10:23:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20260116102348epoutp0110782ad90a7129bd1e05c8688cf09a0d~LLxELXGkl2576225762epoutp01Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1768559028; bh=H5AI9BVpXvlAG2uSM9VJSAe53L3/3Kh2i8Vgsuw9k8U=; h=From:To:Cc:Subject:Date:References:From; b=cJNDmr/AHt0KRGlnEck2Q1QAe0+ZO6kqyPlbAwIYI0pmZR1IHdgmxklhoStrxW9ad wh5SDIcjHk6p/eUYM/Lc7Pa4f2s/jC0q/77cApAhY6oDlbGXcb0AX9tK5K2oZxNRVa H8N0uVVIpa2I5oT80Tcz4Si8hwPDbkSEEvjGKIPg= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPS id 20260116102348epcas1p170a2d1d5c064b47fd760de44737d47cb~LLxDsZ0Gv0199901999epcas1p1T; Fri, 16 Jan 2026 10:23:48 +0000 (GMT) Received: from epcas1p3.samsung.com (unknown [182.195.38.191]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dswtX1LT6z3hhT3; Fri, 16 Jan 2026 10:23:48 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20260116102347epcas1p46ed8360e1a69831f382dcf9d9ee486b0~LLxC8pSFq2177121771epcas1p4w; Fri, 16 Jan 2026 10:23:47 +0000 (GMT) Received: from mypc.. (unknown [10.253.98.103]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20260116102347epsmtip1144a3c2be566684f0d9c302cee848560~LLxC5sPxq0242902429epsmtip1v; Fri, 16 Jan 2026 10:23:47 +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 RESEND] f2fs: optimize f2fs_overwrite_io() for f2fs_iomap_begin Date: Fri, 16 Jan 2026 19:23:46 +0900 Message-ID: <20260116102346.992546-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: 20260116102347epcas1p46ed8360e1a69831f382dcf9d9ee486b0 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: 20260116102347epcas1p46ed8360e1a69831f382dcf9d9ee486b0 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 --- fs/f2fs/data.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 2e133a723b99..bfbd717e628a 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; @@ -1877,6 +1878,11 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t p= os, size_t len) 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 +4449,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