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 955AF3451CF for ; Tue, 17 Mar 2026 01:56:04 +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=1773712564; cv=none; b=F43AwtuRcy5YyqN5T6ijNjVY7/iPMRZo+KfMPz+jWaQW9qM79Ba7hk3nmScNffkWQ6W1wwnH0e2z1XyDN/STHBs72gyy0GmOO6P1AkQz5sK2gJrr+IPEXMYghc8e7ZJc24z5hlZv89jM2YPaSprbJ6atQoy1ckGxvSkL3q07C0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773712564; c=relaxed/simple; bh=bNzgCH1zcg1vaCTtDXv9WviZYRGhQjAkK1TxfRJrIqo=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=E7v163+DP7V64ZZ97kBE4XwrcmJ2zjhe89BmBuayzVfzLdPi9UWpAOnNq5zYKFl7OwgWlh4XPvxfoxNYYaVBLcp688G+vVofBM/SmX57/cnvuUYBtC6Izm8ooWwQym6aayyImOVUK7qdyt7oJ7yuTp8R9q6gTheyH2dRKuZrVBw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lvR9zDGa; 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="lvR9zDGa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE736C19421; Tue, 17 Mar 2026 01:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773712564; bh=bNzgCH1zcg1vaCTtDXv9WviZYRGhQjAkK1TxfRJrIqo=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=lvR9zDGaLl4ZxpOymtruRPo6HWH/dPrKDCqbN8DXjKLVUR/byP+zLmSV3cqifEzza ghV3SiDqbWOLOUf1W4Fa2IZTWWy6z7wVc52b0W3n1ZACwhNgxCfMYx+cuBxQlc+z6E azhC7p+d3so1qc7mXfKojkw2PCSJduWH6BSp2o+duH0/0H1MWcwLtCvL8GC12b2mCc dRxA3+R31uxne84BlrJCwf8CJxA51Vsbw49zG1zAoIxsb8w6imckUMwu/3t8tgrXTQ +qZ+ihtZ4bFaOwJCl9UVvbRnxqhVTpwMQ8mVGh3h9oLEQVmyTBHkVdoiXzqYdmop7P R/E7Qpn767PTQ== Message-ID: Date: Tue, 17 Mar 2026 09:56:00 +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, Daeho Jeong Subject: Re: [f2fs-dev] [PATCH v3] f2fs: fix to freeze GC and discard threads quickly To: Daeho Jeong , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com References: <20260316185954.2185806-1-daeho43@gmail.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20260316185954.2185806-1-daeho43@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026/3/17 02:59, 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 > --- > v3: removed unnecessary suspended check > v2: add freezing check in do_garbage_collect() > --- > fs/f2fs/gc.c | 10 ++++++++++ > fs/f2fs/segment.c | 12 +++++++++++- > 2 files changed, 21 insertions(+), 1 deletion(-) > > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c > index 246496fbe5e5..2305f16cbabb 100644 > --- a/fs/f2fs/gc.c > +++ b/fs/f2fs/gc.c > @@ -1889,12 +1889,18 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, > sbi->next_victim_seg[gc_type] = > (cur_segno + 1 < sec_end_segno) ? > cur_segno + 1 : NULL_SEGNO; > + > + if (unlikely(freezing(current))) { > + folio_put_refs(sum_folio, 2); > + goto stop; Do we need to return EBUSY or something like that to indicate GC was interrupted? > + } > } > next_block: > folio_put_refs(sum_folio, 2); > segno = block_end_segno; > } > > +stop: > if (submitted) > f2fs_submit_merged_write(sbi, data_type); > > @@ -1968,6 +1974,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) > goto stop; > } > retry: > + if (unlikely(freezing(current))) { > + ret = 0; Ditto. Thanks, > + goto stop; > + } > 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..0c4fb4270185 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,7 +1703,8 @@ 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; > } >