From nobody Mon Feb 9 16:17: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