From nobody Mon Feb 9 16:17:47 2026 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.7]) (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 B6AF131A812 for ; Mon, 5 Jan 2026 15:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627260; cv=none; b=FUszsce9p+lSLYzA9Q2h1rhm34UffJ7lWm2yNzdF7BUB85ZupEXGKw+VkvaSbZN/2qgcs1/q+AIzM/93j5thBUlhnIb/dNwTTdQcE+jFiza+ypd4Z0qt3qOtPzZI78S6lWdnFa7OZOuWlNTiqNvTxkinvUXIQ5SkeF1q0irTwbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627260; c=relaxed/simple; bh=arf3GZFlmxWeKojHzYfWjOsX+S4rljUXnEf+HZIkk68=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZHiOud+YYViJwcTcybMNzFhMQhdLpbgnstdU0rEiMP1ViLPCZFcziHJTVQ4c3+TEigGedekhR4ACBBra0Pm5UsLeh3BrUXQAUv+DrBe7BF8e7AHX/LRFZVVeZ+l8zwaejCVzJ47g16xGeN5H7AJKO4uKw5pXQ33WwHQR1YPCxOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b=S3lbzwaz; arc=none smtp.client-ip=117.135.210.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="S3lbzwaz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ti YLZz94d9LLQaDgoW6RxRSXj1GY6myv0dr2n31N658=; b=S3lbzwazwBjl+OviT0 x/cOP0ZvC3s0wO1wMtTQNLxCS3xwTfRLbgUhs8qgfZydNanRjVCOou6DhoUkKN02 SSwUq8Ub1gc1nunuxtht6BbLluROa1JiZ4bQ+h0+jRI40yAg1VmKl2oCMLn6lRWr 3qjSL4WheQMiP+Tygi/tjcNVw= Received: from YLLaptop.. (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD3t6092Vtp4nHABA--.665S5; Mon, 05 Jan 2026 23:31:12 +0800 (CST) From: Nanzhe Zhao To: Kim Jaegeuk Cc: Chao Yu , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Nanzhe Zhao Subject: [PATCH v1 3/5] f2fs: add f2fs_block_needs_zeroing() to handle hole blocks Date: Mon, 5 Jan 2026 23:30:59 +0800 Message-Id: <20260105153101.152892-4-nzzhao@126.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260105153101.152892-1-nzzhao@126.com> References: <20260105153101.152892-1-nzzhao@126.com> 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-CM-TRANSID: _____wD3t6092Vtp4nHABA--.665S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF1fWw1xZw4DWFy3CryDJrb_yoW5Jr1DpF y7Gr15Grs3GF4IgF4xJ3Z8uFn09348Kw4UuFZ3A34fWayYqr9agFnYya45uF1Y9rZ7XFn2 qF48K34kCa45taDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U2NtxUUUUU= X-CM-SenderInfo: xq22xtbr6rjloofrz/xtbBsQC3h2lb2UBIxwAA3l Content-Type: text/plain; charset="utf-8" f2fs_read_data_large_folio() relies on f2fs_map_blocks() to decide whether a subpage should be zero-filled or queued to a read bio. However, f2fs_map_blocks() can set F2FS_MAP_MAPPED for NULL_ADDR and NEW_ADDR in the non-DIO, no-create path. The large folio read code then treats such hole blocks as mapped blocks, and may account them in read_pages_pending and attempt to build bios for them, which can leave tasks stuck in readahead for heavily fragmented files. Add a helper, f2fs_block_needs_zeroing(), which detects NULL_ADDR and NEW_ADDR from struct f2fs_map_blocks. Use it to prioritize the zeroing path by checking f2fs_block_needs_zeroing() before (map.m_flags & F2FS_MAP_MAPPED) under got_it: label. Signed-off-by: Nanzhe Zhao --- fs/f2fs/data.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 4bef04560924..66ab7a43a56f 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2413,6 +2413,11 @@ static void ffs_detach_free(struct folio *folio) kmem_cache_free(ffs_entry_slab, ffs); } +static inline bool f2fs_block_needs_zeroing(const struct f2fs_map_blocks *= map) +{ + return map->m_pblk =3D=3D NULL_ADDR || map->m_pblk =3D=3D NEW_ADDR; +} + static int f2fs_read_data_large_folio(struct inode *inode, struct readahead_control *rac, struct folio *folio) { @@ -2468,14 +2473,7 @@ static int f2fs_read_data_large_folio(struct inode *= inode, if (ret) goto err_out; got_it: - if ((map.m_flags & F2FS_MAP_MAPPED)) { - block_nr =3D map.m_pblk + index - map.m_lblk; - if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr, - DATA_GENERIC_ENHANCE_READ)) { - ret =3D -EFSCORRUPTED; - goto err_out; - } - } else { + if ((f2fs_block_needs_zeroing(&map))) { folio_zero_range(folio, offset << PAGE_SHIFT, PAGE_SIZE); if (f2fs_need_verity(inode, index) && !fsverity_verify_page(folio_file_page(folio, @@ -2484,6 +2482,13 @@ static int f2fs_read_data_large_folio(struct inode *= inode, goto err_out; } continue; + } else if((map.m_flags & F2FS_MAP_MAPPED)) { + block_nr =3D map.m_pblk + index - map.m_lblk; + if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr, + DATA_GENERIC_ENHANCE_READ)) { + ret =3D -EFSCORRUPTED; + goto err_out; + } } /* We must increment read_pages_pending before possible BIOs submitting -- 2.34.1