public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Daeho Jeong <daeho43@gmail.com>,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: chao@kernel.org, Daeho Jeong <daehojeong@google.com>
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to freeze GC and discard threads quickly
Date: Wed, 11 Mar 2026 22:59:27 +0800	[thread overview]
Message-ID: <2ab52a8d-a21b-4b74-a2a1-d7b51fb60ca6@kernel.org> (raw)
In-Reply-To: <20260310204916.1265736-1-daeho43@gmail.com>

On 2026/3/11 04:49, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@google.com>
> 
> 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 <daehojeong@google.com>
> ---
>   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.

>   	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?

Thanks,

>   		__wait_all_discard_cmd(sbi, dpolicy);
>   		goto retry;
>   	}


  reply	other threads:[~2026-03-11 14:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 20:49 [PATCH] f2fs: fix to freeze GC and discard threads quickly Daeho Jeong
2026-03-11 14:59 ` Chao Yu [this message]
2026-03-11 16:00   ` [f2fs-dev] " Daeho Jeong
2026-03-12  1:27     ` Chao Yu
2026-03-12 15:21       ` Daeho Jeong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2ab52a8d-a21b-4b74-a2a1-d7b51fb60ca6@kernel.org \
    --to=chao@kernel.org \
    --cc=daeho43@gmail.com \
    --cc=daehojeong@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox