From nobody Tue Apr 7 14:36:44 2026 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A57E53C13F5 for ; Thu, 12 Mar 2026 15:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773330816; cv=none; b=VJZvB5qn7tXPlHKUyJRAeyslmomVEfpZjBK++7DgxqOQt8YJRp6bHT147RfjZmZzdLJK+6ih+G4+BpnM0hnIwwgJx87J9CtE/8u5G6Pgy7PHv98+NWReZ9gFrThOgnQE4h7+gq5PYvD+bD0hwZQkSyExzB3o4RyhOvxvu5yYtVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773330816; c=relaxed/simple; bh=JRJZcdEdt1OVtd8pl4ha6iflpo6SKy+fOMcOvSJi2Bo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hyBkPe+9zWMzgn0tRGdJ3sgas3Sonhs+7yerUjWb07BmcFjSxJn+3mcwMhgfVhQKMjiX4km7GZP8yARJUnSJh8z1Eg66Gy+1s4xdaz2RmlhF082JoV+OOZ9BroReyEkIjk6Qdml64VdGYaxgen0qDsEfYvtzkSXCEzHjPRYCksk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QQePpI6A; arc=none smtp.client-ip=74.125.82.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QQePpI6A" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-128d7db88b9so1326158c88.0 for ; Thu, 12 Mar 2026 08:53:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773330815; x=1773935615; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=m8bHFQ4Hqw5Jo3nJk+5oSn35D5MYhuZiBEaMfgGAEa0=; b=QQePpI6AamNQeTwKfK71kk7xf4tcT7lzNMQI6ppffHhtvV/ZcnOtO9zzV37c3dxlRe fwJlyBMcVafGpDxPE2nr4+DQyjwK31ytL/HK4g9FpiFDDhydrhABl6i3fa/2vbtErD7p FrMepYQTEnll4asOpDWU/viYcUWv2T5H2PVgJrHvVMd34VJFYXoUvH65KPEtjMcWKPyt htu5xhEMy7RaubZfSh7wfsaxcYJHFpNwrBCJJBH/JI+NjtDpwZdAWEo1OlFlvEGh2USA njPL3E25GMlD6BtNWC0FTbDsk/rkwcBj3fiCnm77b77YgUAzrmX0wRc7G2J8EJK/uTPf G2IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773330815; x=1773935615; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=m8bHFQ4Hqw5Jo3nJk+5oSn35D5MYhuZiBEaMfgGAEa0=; b=ajl7QGl7xoiAdsVIwyNlaVAJOaJ6Ljq9+UVw0eSeGa7ZbnwWnhUMiXWP29DOGWlXyA uJJYhJybxufiKp4MJYYgVGquy3HhYKx9aq2BFZuUkrGmxBnq9OKIFhSUrJwonefkRtIq 9PyCVrwqCyq4Wi3epyE46J32cJGcZkAk+ioH/BbTn3z42L+7IEROYC5oFUNUDFjCP7tv mTKVgWkICKd/dnEcvbvj2hD2DidWbnmgnGfFHIfGDYZQCzz0Ew8bujLJBt8AvplQvJ25 iFlCyUOk3tkpNOKdtATpZ2dJ3a9Qp0nbqovkKxchTOcC1Bo1gl30+JO95vCDWjJUs17/ qfzQ== X-Gm-Message-State: AOJu0Yzk9gzvZIN5zIE/cyuFmS9rbtMrrOpOEHNrtL61yMeoJyq65P5N SYLVsxTfdatfYSKOtR58vpyhi4cGfRfO3ldfC+hpufsXEmXGmSYeSoIZP6U6MQ== X-Gm-Gg: ATEYQzxr+EsNwEDtG1uyjZt+yIjjPNrAnPyQK9g/pEC6CiaNBlD3G+8KMHI49bRKJ9o /cAuAlqwiYmPIiVPAWjDVSPtpU1HK5P/PFrpXb77WSpIl8IiDrwk4f6oHvTWyzBCmX3BPuJEKlf UFBM/q07+nQ3GlPYiVxrk7VhRFBoYjmYOHzBG1mFlYNREGeheK0PlHRSAQZFlo01c3LLLdCfJbx 9p30Qc/EU8mqv1gM6Hwen1CFPAa60FahuURGcWrfu8TOESwla0v2OjLG7iq+WY0aqgSb1kXChKx QdLvdfkEQq/tGb/MlmxD6GDy2HrufW6Bj0/210C+2kXF1HjM+38ja2rwtx4dX2yx6eQ18fuyrz1 fGbsiLNkxj68hAYOoTdQFQfz8SmY08mZxF8d1LICLLpGrdhOH6s7EYcioUi+wQe83A33sdcJPlm P7fwNheXWvviWpSzA4Mq0NnXZ8U8CENEBX06wupENKkdLo0bINkfVbuxbgdQtCosYDSoQv3gJCj Km4/gfIevL2HaxC1f8Ji6kRH2kRFfKZWU3KnR5v8s0y6XzWBas= X-Received: by 2002:a05:7301:4188:b0:2be:83a5:44fe with SMTP id 5a478bee46e88-2bea573a339mr62008eec.34.1773330814505; Thu, 12 Mar 2026 08:53:34 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2a00:79e0:2e7c:8:2c6f:9e91:24da:13fd]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2be8aa74450sm6881247eec.27.2026.03.12.08.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 08:53:34 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH v2] f2fs: fix to freeze GC and discard threads quickly Date: Thu, 12 Mar 2026 08:53:29 -0700 Message-ID: <20260312155330.2670199-1-daeho43@gmail.com> X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- v2: add freezing check in do_garbage_collect() --- fs/f2fs/gc.c | 10 ++++++++++ fs/f2fs/segment.c | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 981eac629fe9..f07746a14aa4 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1883,12 +1883,18 @@ static int do_garbage_collect(struct f2fs_sb_info *= sbi, sbi->next_victim_seg[gc_type] =3D (cur_segno + 1 < sec_end_segno) ? cur_segno + 1 : NULL_SEGNO; + + if (unlikely(freezing(current))) { + folio_put_refs(sum_folio, 2); + goto stop; + } } next_block: folio_put_refs(sum_folio, 2); segno =3D block_end_segno; } =20 +stop: if (submitted) f2fs_submit_merged_write(sbi, data_type); =20 @@ -1962,6 +1968,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc= _control *gc_control) goto stop; } retry: + if (unlikely(freezing(current))) { + ret =3D 0; + goto stop; + } ret =3D __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_s= b_info *sbi, if (dc->state !=3D D_PREP) goto next; =20 + if (*issued > 0 && unlikely(freezing(current))) + break; + if (dpolicy->io_aware && !is_idle(sbi, DISCARD_TIME)) { io_interrupted =3D true; break; @@ -1645,6 +1648,7 @@ static int __issue_discard_cmd(struct f2fs_sb_info *s= bi, struct blk_plug plug; int i, issued; bool io_interrupted =3D false; + bool suspended =3D false; =20 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 !=3D D_PREP); =20 + if (issued > 0 && unlikely(freezing(current))) { + suspended =3D 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); =20 - if (issued >=3D dpolicy->max_requests || io_interrupted) + if (issued >=3D dpolicy->max_requests || io_interrupted || + suspended) break; } =20 - if (dpolicy->type =3D=3D DPOLICY_UMOUNT && issued) { + if (dpolicy->type =3D=3D DPOLICY_UMOUNT && issued && !suspended) { __wait_all_discard_cmd(sbi, dpolicy); goto retry; } --=20 2.53.0.851.ga537e3e6e9-goog