From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37671C83F26 for ; Thu, 24 Jul 2025 08:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:MIME-Version:References:In-Reply-To: Message-ID:Date:To:Sender:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bjBBTtEthIv6fNQf4CXbtKHHZ0kOuEzl1aL0/ZsnI2w=; b=Bit2+t+k0WetEwtOaq6o4nzKT+ PKP2dUNXvCGh/P+7e432i3SWcEi2sFG5APFt3Xp9Zm47IKcUZdY7xpilZhkGHacmnVRbXaPJk8z9S w1X8LhDxXXMNoRI4Kr1T3u1S18Utuy13bJZxyPiyH8gMBFX966p+z4j+t0oeBGHtsY9o=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1uequB-0007mO-3c; Thu, 24 Jul 2025 08:02:19 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1uequ9-0007mA-SL for linux-f2fs-devel@lists.sourceforge.net; Thu, 24 Jul 2025 08:02:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=nS8xFyAD+UKgL/mUzRE5ARhStV4d2VAHdpN/83kpMME=; b=aYWfiztIwLRDNKo2PURfk1JahI AIabuBSz2p9geqgJvjKAf3YjVrajzgoZF5aV/lHcLkdql8lRUVEmcF/3y3Zg3/ioSzxbCyDFrW++m 84uMsOwmcn7inR9Jmyr6ujD06NrZYjjooigWcDc25tn0ONcfffkQ20QoZjgGqelx9X38=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=nS8xFyAD+UKgL/mUzRE5ARhStV4d2VAHdpN/83kpMME=; b=TMXN7O9EIrf7717zAzEybRoA2C SUD6YFU/COUDxr3LPwFM22GzVGWEJRMg+BlyerQ2impkp+8VzqmpeNlz/r5vP0Dp4A3hv7RxAAhZ3 qZ+gdDvNxkiMyEtjUgkpg0fXoOrHazYrw4slizmZTk+VGhRVuhAqXAyjmd4MenGtkPG0=; Received: from nyc.source.kernel.org ([147.75.193.91]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1uequA-0007nG-8C for linux-f2fs-devel@lists.sourceforge.net; Thu, 24 Jul 2025 08:02:18 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 9E986A55FD3; Thu, 24 Jul 2025 08:02:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52509C4CEED; Thu, 24 Jul 2025 08:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753344127; bh=fRw8i8MgDaa/zzz+GjX6hF/zrmeBnpKlxypHhTvVhO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s8owUmmZeNt0ePvr/wi77YEo5E8/bYUnl+kURZ0+4axx0KbSmu9x5yuiujJ7UvAL1 dDoSrXB1uP4fxehiuINAymABYtwBx1iCWpuJ+SmXM2KkyNj/xuL41IZ27zfC1+DHwG q2EHIKeGagVkTjtAy2SPYhxSC91aR6gc5iqP5mijB0tGij3XCQZMdxfELyxHqmrlIG b9xap2n3JOpcgltjDowCCOLkoS5q6coidBwV6Z3lN6HAczyne/mUj+SNAauOEaeUGm EutRU5qSLDoViVWC3iSBWKitB2gWiwzO8NbgnHOiJtLwvva6TE3oolmSAU8oAfndqG 20bNrQDNWO3xg== To: jaegeuk@kernel.org Date: Thu, 24 Jul 2025 16:01:44 +0800 Message-ID: <20250724080144.3689181-3-chao@kernel.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250724080144.3689181-1-chao@kernel.org> References: <20250724080144.3689181-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1uequA-0007nG-8C Subject: [f2fs-dev] [PATCH 3/3] f2fs: fix to trigger foreground gc during f2fs_map_blocks() in lfs mode X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Chao Yu via Linux-f2fs-devel Reply-To: Chao Yu Cc: Daeho Jeong , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net w/ "mode=lfs" 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=lfs mount option") Cc: Daeho Jeong Signed-off-by: Chao Yu --- 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 4e62f7f00b70..ffcaf91c1703 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1573,8 +1573,11 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag) end = pgofs + maxblocks; next_dnode: - if (map->m_may_create) + if (map->m_may_create) { + if (f2fs_lfs_mode(sbi)) + f2fs_balance_fs(sbi, true); f2fs_map_lock(sbi, flag); + } /* When reading holes, we need its node page */ set_new_dnode(&dn, inode, NULL, NULL, 0); -- 2.49.0 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel From mboxrd@z Thu Jan 1 00:00:00 1970 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 016B2272813 for ; Thu, 24 Jul 2025 08:02:07 +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=1753344128; cv=none; b=UnSIokRDQ1w7EoB1zLXwSQXm9DQeB2YY0Pkz888TpAhx4m49KaeTH8x/9CNafNZ1ZzwKdgFrW7Eony6SArW3F40iP7cfR8rlFYyOXyBpQ78NXJoF+pLmHIYvnDwqlu/JCIwuXKqOOO0M7ZMX5S4FTYCrMrnABofuZOMriq+uEwU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753344128; c=relaxed/simple; bh=fRw8i8MgDaa/zzz+GjX6hF/zrmeBnpKlxypHhTvVhO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I5VxBD3VOulvBK6Y7NQZk5gPW4QJAx99ptD/x9/r+XZGWGbyLTIhGliCB1mK/VXiHj8CcMDuatWH2bD/ByDd7h8vjBi6ju8ACSOy5iQ0JhRYEiZJpltxW8GsWPR5hTyASqGi71hmVpXpNQqdoDylrKjWdTf17Xm59gp9gxQXLpg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s8owUmmZ; 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="s8owUmmZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52509C4CEED; Thu, 24 Jul 2025 08:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753344127; bh=fRw8i8MgDaa/zzz+GjX6hF/zrmeBnpKlxypHhTvVhO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s8owUmmZeNt0ePvr/wi77YEo5E8/bYUnl+kURZ0+4axx0KbSmu9x5yuiujJ7UvAL1 dDoSrXB1uP4fxehiuINAymABYtwBx1iCWpuJ+SmXM2KkyNj/xuL41IZ27zfC1+DHwG q2EHIKeGagVkTjtAy2SPYhxSC91aR6gc5iqP5mijB0tGij3XCQZMdxfELyxHqmrlIG b9xap2n3JOpcgltjDowCCOLkoS5q6coidBwV6Z3lN6HAczyne/mUj+SNAauOEaeUGm EutRU5qSLDoViVWC3iSBWKitB2gWiwzO8NbgnHOiJtLwvva6TE3oolmSAU8oAfndqG 20bNrQDNWO3xg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , Daeho Jeong Subject: [PATCH 3/3] f2fs: fix to trigger foreground gc during f2fs_map_blocks() in lfs mode Date: Thu, 24 Jul 2025 16:01:44 +0800 Message-ID: <20250724080144.3689181-3-chao@kernel.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250724080144.3689181-1-chao@kernel.org> References: <20250724080144.3689181-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit w/ "mode=lfs" 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=lfs mount option") Cc: Daeho Jeong Signed-off-by: Chao Yu --- 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 4e62f7f00b70..ffcaf91c1703 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1573,8 +1573,11 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag) end = pgofs + maxblocks; next_dnode: - if (map->m_may_create) + if (map->m_may_create) { + if (f2fs_lfs_mode(sbi)) + f2fs_balance_fs(sbi, true); f2fs_map_lock(sbi, flag); + } /* When reading holes, we need its node page */ set_new_dnode(&dn, inode, NULL, NULL, 0); -- 2.49.0