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 3E25C3537D4 for ; Thu, 12 Mar 2026 01:27:14 +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=1773278834; cv=none; b=n5lcUfbgrziWj8wiFs0foygD/xjOhPFV87z2anreBh1y0wTB1In+o4F8yLql5U8GK9GWmvFxJlRUgLioSa/mgmomh3SO5x/Www1SPp2uCSWopR4NELV/wM9U7r3Ot05uCw80hXC3qTG09D66c0ahTpJFyEQoBM32w70UF5Cs8xY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773278834; c=relaxed/simple; bh=ZpLJ1m4d1eOZgxraCRSxLeTyI9+/BQSTxualWHc+TuY=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=bbKvOVRjIauydCplOgpCogC5+NY3qzdT9/sEHSbHlDAmH0ZGpTU2ItC0Kh8v/MuBOTK6aqbpPb5sa7T1z8ERv19+IOnKWV3ZAbpXy5FjmFY9kmLKbStz+KLiWX+G27C4LZW18BrC5viwEIaxfP3aHcJsshoqR9LXotLhFbFDm50= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L2O7DZdG; 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="L2O7DZdG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AF91C4CEF7; Thu, 12 Mar 2026 01:27:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773278833; bh=ZpLJ1m4d1eOZgxraCRSxLeTyI9+/BQSTxualWHc+TuY=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=L2O7DZdGLMsirBa+nrPfOcfEdmd3dfAog2vjsQr8uVgI8x4lLcDO9NTg4kY3E/twZ V8FZqmyw5xJAoL3xjFKzZQQOVWjZ4V1P8EbCUiMG5CiUNSRbLkIfbjxZHT9cgkwcrg D4GzspdkfvGTSz3aalD65VghK8tBjF/WlFEfLeWrEqkk8wFdu/3H2qucAScK2FJQyQ 2RYloOqt00cOkvI/Ku0RNi5P54D2yLdQcJh8zOzX+Wu2T+9eKf/Qp3iEhNkFL9pxzl VQBhY3txHoxHQHkFelmJFQU7Kqnw/AKFcpULbDvP3sSf2KMp/KmMmK4omfTDhFQnQy e6FOlnuBhLvag== Message-ID: Date: Thu, 12 Mar 2026 09:27:09 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Daeho Jeong Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to freeze GC and discard threads quickly To: Daeho Jeong References: <20260310204916.1265736-1-daeho43@gmail.com> <2ab52a8d-a21b-4b74-a2a1-d7b51fb60ca6@kernel.org> Content-Language: en-US From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026/3/12 00:00, Daeho Jeong wrote: > On Wed, Mar 11, 2026 at 7:59 AM Chao Yu wrote: >> >> On 2026/3/11 04:49, Daeho Jeong wrote: >>> From: Daeho Jeong >>> >>> Suspend can fail if kernel threads do not freeze for a while. >>> f2fs_gc and f2fs_discard threads can perform long-running operations >>> that prevent them from reaching a freeze point in a timely manner. >>> >>> This patch adds explicit freezing checks in the following locations: >>> 1. f2fs_gc: Added a check at the 'retry' label to exit the loop quickly >>> if freezing is requested, especially during heavy GC rounds. >>> 2. __issue_discard_cmd: Added a 'suspended' flag to break both inner and >>> outer loops during discard command issuance if freezing is detected >>> after at least one command has been issued. >>> 3. __issue_discard_cmd_orderly: Added a similar check for orderly discard >>> to ensure responsiveness. >>> >>> These checks ensure that the threads release locks safely and enter the >>> frozen state. >>> >>> Signed-off-by: Daeho Jeong >>> --- >>> fs/f2fs/gc.c | 4 ++++ >>> fs/f2fs/segment.c | 14 ++++++++++++-- >>> 2 files changed, 16 insertions(+), 2 deletions(-) >>> >>> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c >>> index 981eac629fe9..fdc3366c4db3 100644 >>> --- a/fs/f2fs/gc.c >>> +++ b/fs/f2fs/gc.c >>> @@ -1962,6 +1962,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) >>> goto stop; >>> } >>> retry: >>> + if (unlikely(freezing(current))) { >>> + ret = 0; >>> + goto stop; >>> + } >> >> Do we need to check freezing() during multiple segments migration? >> especially in large section, e.g. zufs case. > > Otherwise, we can't meet the 1 second suspend requirement for Android. > This logic mainly targets zufs proactive GC cases. > Plus, aren't the remaining segments in the section the next victims of > GC for the next round? Sorry, I didn't get the point, could you please explain more about your concern? Actually, what I mean is if we missed freezeing() check condition in f2fs_gc(), in do_garbage_collection(), after we migrated one segment of section, and before migrate next segment in section, we can check freezing() condition at this time? I meant maybe we can add more check spots in do_garbage_collection(). Thanks, > >> >>> ret = __get_victim(sbi, &segno, gc_type, gc_control->one_time); >>> if (ret) { >>> /* allow to search victim from sections has pinned data */ >>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c >>> index e9b6d774b985..a6c82ab28288 100644 >>> --- a/fs/f2fs/segment.c >>> +++ b/fs/f2fs/segment.c >>> @@ -1606,6 +1606,9 @@ static void __issue_discard_cmd_orderly(struct f2fs_sb_info *sbi, >>> if (dc->state != D_PREP) >>> goto next; >>> >>> + if (*issued > 0 && unlikely(freezing(current))) >>> + break; >>> + >>> if (dpolicy->io_aware && !is_idle(sbi, DISCARD_TIME)) { >>> io_interrupted = true; >>> break; >>> @@ -1645,6 +1648,7 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi, >>> struct blk_plug plug; >>> int i, issued; >>> bool io_interrupted = false; >>> + bool suspended = false; >>> >>> if (dpolicy->timeout) >>> f2fs_update_time(sbi, UMOUNT_DISCARD_TIMEOUT); >>> @@ -1675,6 +1679,11 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi, >>> list_for_each_entry_safe(dc, tmp, pend_list, list) { >>> f2fs_bug_on(sbi, dc->state != D_PREP); >>> >>> + if (issued > 0 && unlikely(freezing(current))) { >>> + suspended = true; >>> + break; >>> + } >>> + >>> if (dpolicy->timeout && >>> f2fs_time_over(sbi, UMOUNT_DISCARD_TIMEOUT)) >>> break; >>> @@ -1694,11 +1703,12 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi, >>> next: >>> mutex_unlock(&dcc->cmd_lock); >>> >>> - if (issued >= dpolicy->max_requests || io_interrupted) >>> + if (issued >= dpolicy->max_requests || io_interrupted || >>> + suspended) >>> break; >>> } >>> >>> - if (dpolicy->type == DPOLICY_UMOUNT && issued) { >>> + if (dpolicy->type == DPOLICY_UMOUNT && issued && !suspended) { >> >> If we're umounting data partition, it doesn't need to consider suspend? > > Makes sense. > >> >> Thanks, >> >>> __wait_all_discard_cmd(sbi, dpolicy); >>> goto retry; >>> } >>