From patchwork Thu Apr 3 23:21:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "yohan.joung" X-Patchwork-Id: 14037783 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 CD0EAC3600C for ; Thu, 3 Apr 2025 23:21:44 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1u0TsU-00054L-FA; Thu, 03 Apr 2025 23:21:42 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1u0TsT-00054B-8W for linux-f2fs-devel@lists.sourceforge.net; Thu, 03 Apr 2025 23:21:41 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=G1V6PwqH7BMQ97XkG02pq4AsLycT0KN5p+U2RGdD7zQ=; b=aJvtCxsOyNOcY8q7n9hkJTFaf+ P4iwU56XFdowrJ9X4GsqYM6vRzEVZVdbxQfOVNxZ64uuuV72jUAw1oyPrwTlsUKYBa7HAFLaT9mBM becAAa526HmYAOEbXQTLZWhNi3/ojfviJX/mM1GKB55nrIfKjstoDhaah3Ud+UPshfzc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=G1V6PwqH7BMQ97XkG02pq4AsLycT0KN5p+U2RGdD7zQ=; b=H O3qtJoQIG1WFLwPUpcPmT3j1/FI4kRGKVmV/v709c0HoZ0/I7N8ngIRaFnLKS73weZjkGJy19QoP/ fqKlNBgAV+VwpEIXo6fEENYi7ZyEEAiVdrqF1Kn4EWD2BKOQiCvIQTlLO6o/m7YHjp7qDbxZYLjPu smdeUhD5YBFkCKC8=; Received: from exvmail3.skhynix.com ([166.125.252.90] helo=invmail3.skhynix.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtp (Exim 4.95) id 1u0TsC-0000Jl-2U for linux-f2fs-devel@lists.sourceforge.net; Thu, 03 Apr 2025 23:21:41 +0000 X-AuditID: a67dfc59-057ff7000000aab6-5c-67ef17e8b7e0 From: "yohan.joung" To: jaegeuk@kernel.org, chao@kernel.org Date: Fri, 4 Apr 2025 08:21:06 +0900 Message-ID: <20250403232107.2960-1-yohan.joung@sk.com> X-Mailer: git-send-email 2.49.0.windows.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnluLIzCtJLcpLzFFi42LhesuzSPeF+Pt0g10b2SxOTz3LZPFk/Sxm i0uL3C0u75rD5sDisWlVJ5vH7gWfmTw+b5ILYI7isklJzcksSy3St0vgyjh74gJ7wT++it8n prA2MB7h6WLk5JAQMJHYOHs6I4y9aNIlMJtNQEPiT28vM4gtIqApcaRzJjuIzSxQJrHnzxEW EFt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U27tHH3rX/Wbfxd6Cn09USh6/PbH8ujLFv3r7lUAp76ocUtvlfhc0P BCgqsRRnJBpqMRcVJwIA72O5/wwCAAA= X-CFilter-Loop: Reflected X-Headers-End: 1u0TsC-0000Jl-2U Subject: [f2fs-dev] [PATCH v5] f2fs: prevent the current section from being selected as a victim during GC 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: , Cc: pilhyun.kim@sk.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net When selecting a victim using next_victim_seg in a large section, the selected section might already have been cleared and designated as the new current section, making it actively in use. This behavior causes inconsistency between the SIT and SSA. F2FS-fs (dm-54): Inconsistent segment (70961) type [0, 1] in SSA and SIT Call trace: dump_backtrace+0xe8/0x10c show_stack+0x18/0x28 dump_stack_lvl+0x50/0x6c dump_stack+0x18/0x28 f2fs_stop_checkpoint+0x1c/0x3c do_garbage_collect+0x41c/0x271c f2fs_gc+0x27c/0x828 gc_thread_func+0x290/0x88c kthread+0x11c/0x164 ret_from_fork+0x10/0x20 issue scenario segs_per_sec=2 - seg#0 and seg#1 are all dirty - all valid blocks are removed in seg#1 - gc select this sec and next_victim_seg=seg#0 - migrate seg#0, next_victim_seg=seg#1 - checkpoint -> sec(seg#0, seg#1) becomes free - allocator assigns sec(seg#0, seg#1) to curseg - gc tries to migrate seg#1 Signed-off-by: yohan.joung Signed-off-by: Chao Yu Reviewed-by: Chao Yu --- fs/f2fs/segment.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 0465dc00b349..0773283babfa 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -474,8 +474,15 @@ static inline void __set_test_and_free(struct f2fs_sb_info *sbi, next = find_next_bit(free_i->free_segmap, start_segno + SEGS_PER_SEC(sbi), start_segno); if (next >= start_segno + usable_segs) { - if (test_and_clear_bit(secno, free_i->free_secmap)) + if (test_and_clear_bit(secno, free_i->free_secmap)) { free_i->free_sections++; + + if (GET_SEC_FROM_SEG(sbi, sbi->next_victim_seg[BG_GC]) == secno) + sbi->next_victim_seg[BG_GC] = NULL_SEGNO; + + if (GET_SEC_FROM_SEG(sbi, sbi->next_victim_seg[FG_GC]) == secno) + sbi->next_victim_seg[FG_GC] = NULL_SEGNO; + } } } skip_free: