From nobody Sun Feb 8 12:14:41 2026 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.8]) (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 F0E88303C83 for ; Mon, 5 Jan 2026 15:34:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627245; cv=none; b=Zv+ZIP+u5ztSlKTN2j5Edyt2ER/lJ11l+ImOE6Afv/oO7QNFrHn7TTnLRAx0QL8Eu4dkJSsRcDT9b37x1GvNaTLMfwxStJljpTIAt964Aot7t40l7fhEesgzu5shBu2LnrE2+/HGTUEd3Pt/i5s3YjyFnnZdcPONdyo9+UW9euI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627245; c=relaxed/simple; bh=tW/GKEey4iCujCvi3D8XxSiMyBzBs+aPG3KcptCeZ+8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l0Giwa2X68aKI5DelsqimyGAGPAW8+taaRRQ3Acym/ggS3ZEDMobOVKF1OclapyeB6XshgkZdP5iPgk45Kke4WKSA/C+M300Rq+zqYRG2syuc12sPRtX/jL+KQjuOz4akVtZvS8ZZdY/wv1+P1GLprSvjFWs5cLbXD48dgz1hpY= 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=LELhmAWZ; arc=none smtp.client-ip=220.197.31.8 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="LELhmAWZ" 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=m1 S4iy66eHRyWo/r6WxSdeP3G8a/4YCzSxpE2sfnPHI=; b=LELhmAWZ0loSFBqqxd vwrpkQIWzDJR+tXrXIKxtKMl8uDtkd03MTW159GNhp9+PDuT4rQ3etwnoV2cxTXR PTdd23SRTPefPZDc8WkEuuqFV0cH1/ijyeBRN2WUf9iiQbAdJmmb3hoh5a+JR5xD 3b8arv2EWW7hyQyY/DcyJ13yk= Received: from YLLaptop.. (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD3t6092Vtp4nHABA--.665S3; Mon, 05 Jan 2026 23:31:11 +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 1/5] f2fs: Zero f2fs_folio_state on allocation Date: Mon, 5 Jan 2026 23:30:57 +0800 Message-Id: <20260105153101.152892-2-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--.665S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrZF48Wr48Cr15Wr43tFy3CFg_yoWDGrg_uw 18Jrn7WryrJF15A3WYy3y8trZagrn5Cr1I9a1xtr4SyFn8J3yIya4qvwn3ArnrW3yjy345 GrZFq3yfCr9rCjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRXJ5F7UUUUU== X-CM-SenderInfo: xq22xtbr6rjloofrz/xtbBsR+2hmlb2T9IwAAA3C Content-Type: text/plain; charset="utf-8" f2fs_folio_state is attached to folio->private and is expected to start with read_pages_pending =3D=3D 0. However, the structure was allocated from ffs_entry_slab without being fully initialized, which can leave read_pages_pending with stale values. Allocate the object with __GFP_ZERO so all fields are reliably zeroed at creation time. Signed-off-by: Nanzhe Zhao Reviewed-by: Barry Song Reviewed-by: Chao Yu --- fs/f2fs/data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 471e52c6c1e0..ab091b294fa7 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2389,7 +2389,7 @@ static struct f2fs_folio_state *ffs_find_or_alloc(str= uct folio *folio) if (ffs) return ffs; - ffs =3D f2fs_kmem_cache_alloc(ffs_entry_slab, GFP_NOIO, true, NULL); + ffs =3D f2fs_kmem_cache_alloc(ffs_entry_slab, GFP_NOIO | __GFP_ZERO, true= , NULL); spin_lock_init(&ffs->state_lock); folio_attach_private(folio, ffs); -- 2.34.1 From nobody Sun Feb 8 12:14:41 2026 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.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 4A8AD3009E1 for ; Mon, 5 Jan 2026 15:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627110; cv=none; b=hPIJN1SYpiP3mW1KUMfAH5cPy96G+mUbBvovdebBn8XVB8Z/osQl20GoS5QGz0LPVh5ES/P7kmhlV5K9YECCd7pwwStOtG+fSG4ZQDVHzqGlz1P75ZdDbmUBCkXsvIC5ATzsxtMRg8ePDs/z+vVsWJlI0cEkVhc4Tknj2UBxl1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627110; c=relaxed/simple; bh=4MTPNqmsn/1/9I1vC8JzuGOzpDnYy8JYscbjXvJwg8c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BXq/qIjYTlTvbdRg78hiyk6x9kl9rYDhU2Hqgc8YH7kxtw1QUnblVKjuB1nR/xLjSJFaJVBb2hP/1pfoMSgkt1xkxNpNsvqzq2oJgbPntjueppX5DpCSyKAN+m8jG0knPzZhwDKs1Nkrh7AclbV1NiCQW/gBrNE7LGslwyhE/rI= 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=TDW6e2XD; arc=none smtp.client-ip=220.197.31.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="TDW6e2XD" 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=SU OdomIt1y482dWB7e2fCoPWGq+lDcWVjtOVItf7/Ew=; b=TDW6e2XD7tk2LvpNvr paQJrAkOL8fTafefUczNNMaFbvfBG7IP2GPHeK/W/+S1vemhnEumtIuaCYopqH9s VuTpquDLUCF4bghpxyuyAETlLjSbBE3qSJ/p6IyyfW18Ir8W8anrYdn5qq5XFbH3 hQxgWUgyNg/ZfUzGHDT4ejIUM= Received: from YLLaptop.. (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD3t6092Vtp4nHABA--.665S4; Mon, 05 Jan 2026 23:31:11 +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 2/5] f2fs: Accounting large folio subpages before bio submission Date: Mon, 5 Jan 2026 23:30:58 +0800 Message-Id: <20260105153101.152892-3-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--.665S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZFy8tFW8Cry3Cw4xXFW8Zwb_yoW8Zr1fpF 95KF1FkFs5Xay09rnaq3Z8Xr1rt348Wa1UCFZ7Gw4fJ3Waqr9akr4ktryFvF1UtFZ7AF13 Xw4rtrn5u3WUXa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U2g4fUUUUU= X-CM-SenderInfo: xq22xtbr6rjloofrz/xtbBsR+2hmlb2T9IxAAA3G Content-Type: text/plain; charset="utf-8" In f2fs_read_data_large_folio(), read_pages_pending is incremented only after the subpage has been added to the BIO. With a heavily fragmented file, each new subpage can force submission of the previous BIO. If the BIO completes quickly, f2fs_finish_read_bio() may decrement read_pages_pending to zero and call folio_end_read() while the read loop is still processing other subpages of the same large folio. Fix the ordering by incrementing read_pages_pending before any possible BIO submission for the current subpage, matching the iomap ordering and preventing premature folio_end_read(). Signed-off-by: Nanzhe Zhao Reviewed-by: Chao Yu --- fs/f2fs/data.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index ab091b294fa7..4bef04560924 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2486,6 +2486,18 @@ static int f2fs_read_data_large_folio(struct inode *= inode, continue; } + /* We must increment read_pages_pending before possible BIOs submitting + * to prevent from premature folio_end_read() call on folio + */ + if (folio_test_large(folio)) { + ffs =3D ffs_find_or_alloc(folio); + + /* set the bitmap to wait */ + spin_lock_irq(&ffs->state_lock); + ffs->read_pages_pending++; + spin_unlock_irq(&ffs->state_lock); + } + /* * This page will go to BIO. Do we need to send this * BIO off first? @@ -2513,15 +2525,6 @@ static int f2fs_read_data_large_folio(struct inode *= inode, offset << PAGE_SHIFT)) goto submit_and_realloc; - if (folio_test_large(folio)) { - ffs =3D ffs_find_or_alloc(folio); - - /* set the bitmap to wait */ - spin_lock_irq(&ffs->state_lock); - ffs->read_pages_pending++; - spin_unlock_irq(&ffs->state_lock); - } - inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA); f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO, F2FS_BLKSIZE); -- 2.34.1 From nobody Sun Feb 8 12:14:41 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 From nobody Sun Feb 8 12:14:41 2026 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.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 D9FE3303C83 for ; Mon, 5 Jan 2026 15:31:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627112; cv=none; b=ph0K9X9j+km7RSeJ1qaCJ9cjIdcQkssOHJ9jviFLNuYeu+536muZpLEQLwZqJuByoSiuv1gpfH/tRNaEdQJI+Al8KTU9msmnhsMDANfS4xdVVlgQlZmCMkfMS8PYWCTZu2tFu7ddisXOFVv1xKnN0MCd0S4Hj8LrVv/R9dzoXzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627112; c=relaxed/simple; bh=RclqDzYOshdunGEdgy2OuyIlcMpf8NdEsURFgfoq9HU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=svCZm6tcd89vxiY6JHUuE2K7bxUw1/zscfTodtzfQSV9FR2zHc8Jri5h78bvgIQ4Y5vDpltY1UB2zpyVq7yqeEiX4zi1f1LMbg6On9P81uuo8//Lhes3f42waOFfPOtM+VvNtq9KlKKXWV4qoG3cYZWjrLxeXIQAQv7yEBAUYLk= 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=btf4AX9f; arc=none smtp.client-ip=220.197.31.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="btf4AX9f" 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=bF FmAVAmIX+RPOqrfHAqM7ezbKNEISuZL8Xxh41Ccqw=; b=btf4AX9fjc1P66WLjq otpUXAaoMUL3RMDHCCxt6p4B7BtzM8F+ByqjyurnLlB6j06LlGnVup6NpiUIw1rO d5ySJplZCIFiqR/MOmNVH2ComQ0NbXBm24z7dCCEF5fnU9gVAsvnCuN31+6NFU8i j0QriKjA38gITw1/SoJwye1H0= Received: from YLLaptop.. (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD3t6092Vtp4nHABA--.665S6; 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 4/5] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission Date: Mon, 5 Jan 2026 23:31:00 +0800 Message-Id: <20260105153101.152892-5-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--.665S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw4xurWrCw4DKryrXryUAwb_yoW8Cry8pr ykKF95KFZ8JFW8ur48t3Z0vw1Sk348Wa1UGFWfCw1fAasxXas5KFyvq3WY9F1UtFn5J3WI qF4FvryUWFsrtF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRkwIgUUUUU= X-CM-SenderInfo: xq22xtbr6rjloofrz/xtbBsAG3h2lb2UFHhQAA3p Content-Type: text/plain; charset="utf-8" f2fs_read_data_large_folio() can build a single read BIO across multiple folios during readahead. If a folio ends up having none of its subpages added to the BIO (e.g. all subpages are zeroed / treated as holes), it will never be seen by f2fs_finish_read_bio(), so folio_end_read() is never called. This leaves the folio locked and not marked uptodate. Track whether the current folio has been added to a BIO via a local 'folio_in_bio' bool flag, and when iterating readahead folios, explicitly mark the folio uptodate (on success) and unlock it when nothing was added. Signed-off-by: Nanzhe Zhao --- fs/f2fs/data.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 66ab7a43a56f..ac569a396914 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2430,6 +2430,7 @@ static int f2fs_read_data_large_folio(struct inode *i= node, unsigned nrpages; struct f2fs_folio_state *ffs; int ret =3D 0; + bool folio_in_bio =3D false; if (!IS_IMMUTABLE(inode)) return -EOPNOTSUPP; @@ -2445,6 +2446,7 @@ static int f2fs_read_data_large_folio(struct inode *i= node, if (!folio) goto out; + folio_in_bio =3D false index =3D folio->index; offset =3D 0; ffs =3D NULL; @@ -2530,6 +2532,7 @@ static int f2fs_read_data_large_folio(struct inode *i= node, offset << PAGE_SHIFT)) goto submit_and_realloc; + folio_in_bio =3D true; inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA); f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO, F2FS_BLKSIZE); @@ -2539,6 +2542,11 @@ static int f2fs_read_data_large_folio(struct inode *= inode, } trace_f2fs_read_folio(folio, DATA); if (rac) { + if (!folio_in_bio) { + if (!ret) + folio_mark_uptodate(folio); + folio_unlock(folio); + } folio =3D readahead_folio(rac); goto next_folio; } -- 2.34.1 From nobody Sun Feb 8 12:14:41 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 5A270316912 for ; Mon, 5 Jan 2026 15:34:05 +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=1767627250; cv=none; b=i2heYsCuzU4PnhhvafVcwjkI6UMsnLg1GtvEy3q2dob0vDuBFB0Mkh6k79r+tqVKw1z92ED/P1meFTd6RJVD9pn5IhPWLMdysF/TzRcksD/JAb+HjG/rpdC67t2ur/hrt75c+rGedxG3/T4xP0a5hc1x0onxCklwKzEoqDoxhDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767627250; c=relaxed/simple; bh=t+aEv+on32nkftfShcn5dGoGWtFRpGb20yVUYo8Ax4s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IBiwiEJGv7udvxcVr/Jq41NRIgKFePSxR8V13r6Bps/2MYsR2QXf6mnpZoXL4c4j8s3vAADcgeIH4lSnmGfU1+fZ1KkbG8C4ILlvelsXOYvxxes6yLsGpEnMJ8Qq3//0TbAmSSh3r0YFwvtkNjMAh1SA9z3VaXDOSzXIHRM7d8Y= 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=YAAnvHaW; 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="YAAnvHaW" 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=GO 3itdCPSkQnHkTqXXvHziXTo77mdzcUY7oiBvS+ZkM=; b=YAAnvHaW97WrvTlYfu OTnPAeRIcTWTEqFuXnjZvQxnHAVI/cO/gfn9rDj6yMholkwkqXc/qUMLOtl51XEz r7u+1No//ElGC+LDSvBNhBNkIjTdTZj9c1kVwjSdzQQ6fy2tQwv53kM4qCFbVsXH bAAZD9zv+G2OfGzDmuEVRlv60= Received: from YLLaptop.. (unknown []) by gzga-smtp-mtada-g0-1 (Coremail) with SMTP id _____wD3t6092Vtp4nHABA--.665S7; Mon, 05 Jan 2026 23:31:13 +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 5/5] f2fs: advance index and offset after zeroing in large folio read Date: Mon, 5 Jan 2026 23:31:01 +0800 Message-Id: <20260105153101.152892-6-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--.665S7 X-Coremail-Antispam: 1Uf129KBjvdXoW7JFy3KrW7Cw45Cr4rAFW5Jrb_yoWkCwb_Zr 1kArs7A3y09rW3Kr4qyw4rt3s2qw4kWr15uFWUJFWUCr98ZrWfAa90vFZ3Ar1kW3yayFsI 93ykXw1rA34DujkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xREuyI5UUUUU== X-CM-SenderInfo: xq22xtbr6rjloofrz/xtbBsQG3h2lb2UFI0wAA3x Content-Type: text/plain; charset="utf-8" In f2fs_read_data_large_folio(), the block zeroing path calls folio_zero_range() and then continues the loop. However, it fails to advance index and offset before continuing. This can cause the loop to repeatedly process the same subpage of the folio, leading to stalls/hangs and incorrect progress when reading large folios with holes/zeroed blocks. Fix it by incrementing index and offset in the zeroing path before continuing. Signed-off-by: Nanzhe Zhao --- fs/f2fs/data.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index ac569a396914..07c222bcc5e0 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2446,7 +2446,7 @@ static int f2fs_read_data_large_folio(struct inode *i= node, if (!folio) goto out; - folio_in_bio =3D false + folio_in_bio =3D false; index =3D folio->index; offset =3D 0; ffs =3D NULL; @@ -2483,6 +2483,8 @@ static int f2fs_read_data_large_folio(struct inode *i= node, ret =3D -EIO; goto err_out; } + index++; + offset++; continue; } else if((map.m_flags & F2FS_MAP_MAPPED)) { block_nr =3D map.m_pblk + index - map.m_lblk; -- 2.34.1