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 22B4BD232D5 for ; Fri, 9 Jan 2026 03:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Type:Content-Transfer-Encoding:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:In-Reply-To:References:To:MIME-Version:Date: Message-ID:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pzw3o6dj60bzKoXTOFBuphY0QuqklpuYsL/AGMmw80A=; b=iY+YY44IIF/G9OeR39rDZV1F/g VqDpB9bETh6EzzUgtV6eEd0I6OIzpPpZX+qQlnIIcTJRR5wo0N/dZN7fs6KIxCg0cQgbLSxbUsEiw Gi+5sdoavCCzrAb6Vt9Wux/XnYpaR9/Dl/XfgSAcrsc8jjhVS674m7Q6wOeGFpbAKc4w=; 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 1ve3Y1-00051M-T9; Fri, 09 Jan 2026 03:52:26 +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 1ve3Y1-00051A-5N for linux-f2fs-devel@lists.sourceforge.net; Fri, 09 Jan 2026 03:52:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: From:References:To:Subject:Cc:MIME-Version:Date:Message-ID:Sender:Reply-To: 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=veC7eNyrW4m2oPM7MR6GO2JF2w2MvkNY+hf59UURlec=; b=CFfOe8kfvN/wvelW+xVyxmGjmy kJnOse9cnEaYBjfchj5clxtCZ2FOHBKWsaOGocxNicFRWMBl9hULy1waPNW2SfABsYBNCcryFApHV /5jDy6x+v8g07xp5HNSKJec4Ncdugqm0jk0nxBv3IXVzikTHRc9QjCxzaazBruiczHyw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:To: Subject:Cc:MIME-Version:Date:Message-ID:Sender:Reply-To: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=veC7eNyrW4m2oPM7MR6GO2JF2w2MvkNY+hf59UURlec=; b=Cy+FglfnDeijMbCRxtP8wxZLPz gBIqdM/FK+PkIX6u5Rx68emBFE7GwWkpVHb4B/T/IopEECASGoYwGOHU+bsvjX8C7/Gn/B7AWOROP 6SKGT0M4QN+RvV1qawLVqoZil4+y8tpzfjfgQ0Tbvvcr+wJakSh5pf6qq4uIBLasax50=; Received: from tor.source.kernel.org ([172.105.4.254]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1ve3Y1-000120-D1 for linux-f2fs-devel@lists.sourceforge.net; Fri, 09 Jan 2026 03:52:25 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 9BE3F6014C; Fri, 9 Jan 2026 03:52:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CCD6C19423; Fri, 9 Jan 2026 03:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767930734; bh=RihT2wPIG8UG2lraqVOyS4CV5JAmK2fr/T2nG15hWkQ=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=kfsAtZ3ViPBCCf2/KehyTc6ks+87Vp25Rwv/8cDwfkN9cot0u1eFLwWnDnzMA+tXG m3cv7z7AodeXYoC6uIysofUoipcoQw27tUzTVtb0Ry1ATE9gspr8yD+NRzhu306M4S gMolJM+fw2HWNYeaQHgg3i52zI8Ib0KBgZx3pJZy6Qh2cP5mdweEQbPiA06f8y7VnP VVGo+WJmQQvbTskh/eTJxBjK8O3Nnn3aycQFuwv6QlK46FfRytKqaeg5iS52S9Eu5b tBFV6lNkHsRC9EiVGDEaSVBDlJIiJd83q8Nd5aA6gBS3O6zg+1uBu3jFJlkusBc71p J1Avjq1evx9Hg== Message-ID: Date: Fri, 9 Jan 2026 11:52:26 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: liujinbao1 , jaegeuk@kernel.org References: <20260107131543.3492385-1-jinbaoliu365@gmail.com> Content-Language: en-US In-Reply-To: <20260107131543.3492385-1-jinbaoliu365@gmail.com> X-Headers-End: 1ve3Y1-000120-D1 Subject: Re: [f2fs-dev] [PATCH] [PATCH] f2fs:Fix incomplete search range in f2fs_get_victim when f2fs_need_rand_seg is enabled 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: liujinbao1 , linux-f2fs-devel@lists.sourceforge.net Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 1/7/2026 9:15 PM, liujinbao1 wrote: > From: liujinbao1 > > During the f2fs_get_victim process, when the f2fs_need_rand_seg is enabled in select_policy, > p->offset is a random value, and the search range is from p->offset to MAIN_SECS. > When segno >= last_segment, the loop breaks and exits directly without searching > the range from 0 to p->offset.This results in an incomplete search when the random > offset is not zero. What about updating sm->last_victim[p.gc_mode] as well when p->offset is not zero in select_policy()? select_policy() ... /* let's select beginning hot/small space first. */ if (f2fs_need_rand_seg(sbi)) { p->offset = get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); if (p->offset) sm->last_victim[p.gc_mode] = p->offset; } Then we can expect p->offset being reset to zero, and last_segment being reset to sm->last_victim[p.gc_mode] in below logic? if (segno >= last_segment) { if (sm->last_victim[p.gc_mode]) { last_segment = sm->last_victim[p.gc_mode]; sm->last_victim[p.gc_mode] = 0; p.offset = 0; continue; } break; } Thanks, > > Signed-off-by: liujinbao1 > --- > fs/f2fs/gc.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c > index 384fa7e2085b..100b8fc3e65a 100644 > --- a/fs/f2fs/gc.c > +++ b/fs/f2fs/gc.c > @@ -781,6 +781,7 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result, > unsigned int valid_thresh_ratio = 100; > bool is_atgc; > int ret = 0; > + unsigned int original_offset; > > mutex_lock(&dirty_i->seglist_lock); > last_segment = MAIN_SECS(sbi) * SEGS_PER_SEC(sbi); > @@ -799,6 +800,7 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result, > p.min_segno = NULL_SEGNO; > p.oldest_age = 0; > p.min_cost = get_max_cost(sbi, &p); > + original_offset = p.offset; > > is_atgc = (p.gc_mode == GC_AT || p.alloc_mode == AT_SSR); > nsearched = 0; > @@ -859,11 +861,11 @@ int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result, > p.offset / p.ofs_unit); > segno = unit_no * p.ofs_unit; > if (segno >= last_segment) { > - if (sm->last_victim[p.gc_mode]) { > - last_segment = > - sm->last_victim[p.gc_mode]; > - sm->last_victim[p.gc_mode] = 0; > + if (original_offset != 0) { > + last_segment = original_offset; > p.offset = 0; > + if (sm->last_victim[p.gc_mode]) > + sm->last_victim[p.gc_mode] = 0; > continue; > } > break; _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel