From nobody Thu Apr 9 20:25:37 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (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 2B78818787A; Fri, 6 Mar 2026 01:20:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772760042; cv=none; b=ocdpmjb1LWaqVOjvyzZb6O63yQGi2tCfO5jdqBFw26yt4LE0aZEGJOGTjuE80dEUm8T1zbXpYqJcGxiyRmXIQLTzpkcf6DrX1xvI401eF7PYqt9AM8qkrmkBHBnQlGq+HlTKr0v5h4HF7Xo18ua765E0xJFv/HS6ezpA0yHnOog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772760042; c=relaxed/simple; bh=G8xMg+dHh7Q7YYjZj+frfC1bz39kvTI3ZM2ulotZHjc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=MkGqB9dHE4wXL5lWijHHG0dPgsidbSmQHbb1AYSZRS4vPsSPW+nWKWPujW7guvLw2QH6Uy+1NiZJbQLj/ppPzexxFTj56jwXRQnKvtALlYv0ZvzU9vmp790Z82xUqrUlfNdEOHYtM7Z4+sGAEVsd0asHfGP2MR4d/6R0Lj3Fbf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=aFfhSfVC; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="aFfhSfVC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=dj +Uy0sWdEVWPDc9iRqVFRbCP32ax8YRlWPoL++LMto=; b=aFfhSfVCKVMKiCO4Hr eAGzUv2HwRiXaVzP9MmOP8qIVHnrYdL/x0aInPGTbSrboBnBp4NNJm4aRsD8h/K0 LYBDIE/0oEvmSZFDA1OQzmRM97dHcZbJYO82r7NF1bUep93B0RO/ot07WzeJON+3 1o0DrtyenMLm01MxsbSw0wug4= Received: from pek-lpg-core6.wrs.com (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wB3rPnRK6ppe+uJOA--.18846S2; Fri, 06 Mar 2026 09:20:18 +0800 (CST) From: Rahul Sharma To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Chao Yu , Daeho Jeong , Jaegeuk Kim , Rahul Sharma Subject: [PATCH 6.1.y] f2fs: fix to trigger foreground gc during f2fs_map_blocks() in lfs mode Date: Fri, 6 Mar 2026 09:20:14 +0800 Message-Id: <20260306012014.1948914-1-black.hawk@163.com> X-Mailer: git-send-email 2.34.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 X-CM-TRANSID: _____wB3rPnRK6ppe+uJOA--.18846S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tF1fCw4UZr1xXr47Xw17trb_yoW8tr1Dpr 9xG3WfGr15Wr1rWa1vga1ruryFk3yqga1UXa97Ww1rA3srZr1fWw1vva4fWay7trZrJr4U XFyqkryrt3Z8AFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0z_WrWxUUUUU= X-CM-SenderInfo: 5eoduy4okd4yi6rwjhhfrp/xtbC3RIEnWmqK9KhwAAA3N Content-Type: text/plain; charset="utf-8" From: Chao Yu [ Upstream commit 1005a3ca28e90c7a64fa43023f866b960a60f791 ] w/ "mode=3Dlfs" mount option, generic/299 will cause system panic as below: ------------[ cut here ]------------ kernel BUG at fs/f2fs/segment.c:2835! Call Trace: f2fs_allocate_data_block+0x6f4/0xc50 f2fs_map_blocks+0x970/0x1550 f2fs_iomap_begin+0xb2/0x1e0 iomap_iter+0x1d6/0x430 __iomap_dio_rw+0x208/0x9a0 f2fs_file_write_iter+0x6b3/0xfa0 aio_write+0x15d/0x2e0 io_submit_one+0x55e/0xab0 __x64_sys_io_submit+0xa5/0x230 do_syscall_64+0x84/0x2f0 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0010:new_curseg+0x70f/0x720 The root cause of we run out-of-space is: in f2fs_map_blocks(), f2fs may trigger foreground gc only if it allocates any physical block, it will be a little bit later when there is multiple threads writing data w/ aio/dio/bufio method in parallel, since we always use OPU in lfs mode, so f2fs_map_blocks() does block allocations aggressively. In order to fix this issue, let's give a chance to trigger foreground gc in prior to block allocation in f2fs_map_blocks(). Fixes: 36abef4e796d ("f2fs: introduce mode=3Dlfs mount option") Cc: Daeho Jeong Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim [ The context change is due to the commit 2f51ade9524c ("f2fs: f2fs_do_map_lock") in v6.3 which is irrelevant to=20 the logic of this patch. ] Signed-off-by: Rahul Sharma --- fs/f2fs/data.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 0e13b01db06a..9bc66ead42d0 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1537,8 +1537,11 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs= _map_blocks *map, int flag) end =3D pgofs + maxblocks; =20 next_dnode: - if (map->m_may_create) + if (map->m_may_create) { + if (f2fs_lfs_mode(sbi)) + f2fs_balance_fs(sbi, true); f2fs_do_map_lock(sbi, flag, true); + } =20 /* When reading holes, we need its node page */ set_new_dnode(&dn, inode, NULL, NULL, 0); --=20 2.34.1