From nobody Sun Feb 8 05:27:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E72E8500948 for ; Mon, 12 Jan 2026 01:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768181608; cv=none; b=uZXatADueogB/0TErOd6i7GRgsAWRX+5ipdyEfGWtfjsmmd3Ex1hnvR6WwPNPpdb7QfokWTs6m7bs/rRj8W5FDvGlrqTQdqS6z9xkqwoblyPTj/2STaKOs58MWpjbd05eRsIw4mGbsbc+dZUjOpWjTPH2M9Z7f6wwTFTvr32HIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768181608; c=relaxed/simple; bh=mhuJOGzZrMJ/ECVDq/vAmVEkdec5v0izbjLsdSSnEI4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=IWqPDOrE6MZNKgocw/r1rrsIYFq0KK59wN2o/pzWruttgXiAUsMu4szdyC0E21arBT/gnUoKln4+WeW2l/yad9WdvlZMd02nYCJaXLVm9U01MzGKpK65cRjQOtNVKZhprD0S6BhUPVrUgQhaHE2lWdrOgwh98DdX51PGdYI0k/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U25qqbWA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U25qqbWA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66444C4CEF7; Mon, 12 Jan 2026 01:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768181607; bh=mhuJOGzZrMJ/ECVDq/vAmVEkdec5v0izbjLsdSSnEI4=; h=From:To:Cc:Subject:Date:From; b=U25qqbWAoV5SLKoMJTVcYUMnXf2XNs+cpmaLIdrhehWjeXWpUn0+oqARjQDbl1qXO 0kkS5q5apAG/s48HKs/UhKaCnz7aiDDk/mqCgJd2Hxxh/RD1HQz10mzHSCP/4BhI5A PNxTd6IDNtVZEWJ1aGC7kAE0nEZrC+gyRr6q3d92oF4eQvtBubLoBFURBuA+UYLD3d b+cQYgROftMmtIq0+f4aV8Qbys3faMH+6XKwCodJQA+OcwGrh8inezekfeUwRsXAmI hnzjAlj5Ax1gq2b8a3QEEH7OM83iJtafSS+ZIQL2BTzPhJUfz81KQjsyHOsKVZUCBz fxuhcP9+HvVOg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH] f2fs: avoid f2fs_map_blocks() for consecutive holes in readpages Date: Mon, 12 Jan 2026 09:33:20 +0800 Message-Id: <20260112013320.8028-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 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 Content-Type: text/plain; charset="utf-8" For consecutive large hole mapping across {d,id,did}nodes , we don't need to call f2fs_map_blocks() to check one hole block per one time, instead, we can use map.m_next_pgofs as a hint of next potential valid block, so that we can skip calling f2fs_map_blocks the range of [cur_pgofs + 1, .m_next_pgofs). 1) regular case touch /mnt/f2fs/file truncate -s $((1024*1024*1024)) /mnt/f2fs/file time dd if=3D/mnt/f2fs/file of=3D/dev/null bs=3D1M count=3D1024 Before: real 0m0.706s user 0m0.000s sys 0m0.706s After: real 0m0.620s user 0m0.008s sys 0m0.611s 2) large folio case touch /mnt/f2fs/file truncate -s $((1024*1024*1024)) /mnt/f2fs/file f2fs_io setflags immutable /mnt/f2fs/file sync echo 3 > /proc/sys/vm/drop_caches time dd if=3D/mnt/f2fs/file of=3D/dev/null bs=3D1M count=3D1024 Before: real 0m0.438s user 0m0.004s sys 0m0.433s After: real 0m0.368s user 0m0.004s sys 0m0.364s Signed-off-by: Chao Yu --- fs/f2fs/data.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index a2c4769d0ae1..5b0642cd27ff 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2176,10 +2176,13 @@ static int f2fs_read_single_page(struct inode *inod= e, struct folio *folio, /* * Map blocks using the previous result first. */ - if ((map->m_flags & F2FS_MAP_MAPPED) && - block_in_file > map->m_lblk && + if (map->m_flags & F2FS_MAP_MAPPED) { + if (block_in_file > map->m_lblk && block_in_file < (map->m_lblk + map->m_len)) + goto got_it; + } else if (block_in_file < *map->m_next_pgofs) { goto got_it; + } =20 /* * Then do more f2fs_map_blocks() calls until we are @@ -2454,7 +2457,7 @@ static int f2fs_read_data_large_folio(struct inode *i= node, struct bio *bio =3D NULL; sector_t last_block_in_bio =3D 0; struct f2fs_map_blocks map =3D {0, }; - pgoff_t index, offset; + pgoff_t index, offset, next_pgofs =3D 0; unsigned max_nr_pages =3D rac ? readahead_count(rac) : folio_nr_pages(folio); unsigned nrpages; @@ -2487,16 +2490,21 @@ static int f2fs_read_data_large_folio(struct inode = *inode, /* * Map blocks using the previous result first. */ - if ((map.m_flags & F2FS_MAP_MAPPED) && - index > map.m_lblk && + if (map.m_flags & F2FS_MAP_MAPPED) { + if (index > map.m_lblk && index < (map.m_lblk + map.m_len)) + goto got_it; + } else if (index < next_pgofs) { + /* hole case */ goto got_it; + } =20 /* * Then do more f2fs_map_blocks() calls until we are * done with this page. */ memset(&map, 0, sizeof(map)); + map.m_next_pgofs =3D &next_pgofs; map.m_seg_type =3D NO_CHECK_TYPE; map.m_lblk =3D index; map.m_len =3D max_nr_pages; @@ -2617,6 +2625,7 @@ static int f2fs_mpage_readpages(struct inode *inode, pgoff_t nc_cluster_idx =3D NULL_CLUSTER; pgoff_t index; #endif + pgoff_t next_pgofs =3D 0; unsigned nr_pages =3D rac ? readahead_count(rac) : 1; struct address_space *mapping =3D rac ? rac->mapping : folio->mapping; unsigned max_nr_pages =3D nr_pages; @@ -2637,7 +2646,7 @@ static int f2fs_mpage_readpages(struct inode *inode, map.m_lblk =3D 0; map.m_len =3D 0; map.m_flags =3D 0; - map.m_next_pgofs =3D NULL; + map.m_next_pgofs =3D &next_pgofs; map.m_next_extent =3D NULL; map.m_seg_type =3D NO_CHECK_TYPE; map.m_may_create =3D false; --=20 2.40.1