From nobody Mon May 25 07:30:55 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 77CE828C5B1 for ; Sat, 16 May 2026 03:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778903413; cv=none; b=oTzC1tlXD0CHDFk17A6awgIo8f2+LUFrmfVHEfhUd/+kQRG1X2jOXaccHMq2nDkXCMIZu2bHUBoN09It79w0XIhP1vtnoZuNcKj9+lty0pCij5nLu/VtEmDKEB74kr1CUx5n9v2gDtj2+C4Xfjul6wOIXtgQCB/Ipgl8f7t+KZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778903413; c=relaxed/simple; bh=6JdOTquf89/G0aVyaoOOf49+ldT6ycdJK+IxgphJxjo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=S0HbYqewMbt12YL+jHLVesN2pG/rFZ01vgxRk9xrVMtpBkBqn0DOpI/l8tWoE7hv/u7ZxOe+u0wj4WzAs+m6IUyR3zS+4fr9hxJKnvQcIlr2wV+xrFFc20Gf6gW8ny2zdZN8DicPBif8pLzXCtH9kUDB5bn2GTFr8T6pDieZln4= 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=o+f+7u7C; arc=none smtp.client-ip=209.85.214.179 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="o+f+7u7C" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2bc6e4556d8so837385ad.1 for ; Fri, 15 May 2026 20:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778903412; x=1779508212; 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=D3InZjJXzh6o9PPA8Dqvz6fSczpvregHfJlC221mW1Y=; b=o+f+7u7CACcAlNkE7dad+7P4JNIqmmAgCGJOzYAdA4v8DbdM0wRc1wljmhq6678JjW Et9ByCCarODAli4t/PYeGLug06HMTa/9A7BlioF4mfH8so02XnOriFpsJSJTVFpF+u58 wlCEAPKRCsgzrCE+tdPmqf3IyqKohb7FcPZshRbBJVNdbcyT5l/SOHpxIApj9R/koR08 e4xdD7nHxH86p4FNl0ht9ChBz2TqBdK1uRq60+rhmT6hgaIb9cpiRVRlsWaOBvp/If2f s6RtlMjD3xj1tss19huNua2au3f5xb8JCquNe5BNUJ+548ekHUU3xS6r2RCcnV5k0euT GvYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778903412; x=1779508212; 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=D3InZjJXzh6o9PPA8Dqvz6fSczpvregHfJlC221mW1Y=; b=dBuhviLTN1i8WgDHHE4I56FSsaXQFTDoaATpFur6b9Lw3ZoOgYh7e6kFZ1phcplhOp YX61rxiHu2wWdNkLB/nN53gmVHRXAMp1dl5GYyDfuntp/+a4CpuUdiK+Ux/1ttwUo4fz s0eADOuidvQwc9wD39GmOMlxueisOeVGObTA/UT8PPSzRcdUlyluXmbK7KhCRoGoS6K6 C1kZ8Xaz+yhFd90zKgSiVN8LUoSeZz7YrNfpAQjMcmtPznLfkKE6SuyCK2rh8QdQzP96 6RuEY2cYSQkPl75VcuolVb86BZ3ZkiWLznui6NPtBFXxyd6XgXFJOrLzOcsr5tI5GESB 63fA== X-Forwarded-Encrypted: i=1; AFNElJ/6uMH1bzOTz83ZUvwwH0E8hNTTLLjAqAH024d5W6dJc6BKJ+peFoeVln3xnVRiuxCqvIixVVdH/AMlWT4=@vger.kernel.org X-Gm-Message-State: AOJu0YzkcoCynJUfm6Cq7PrG3kHs4fuRz92MhbTo+DL2/PKw/Rye498u 0ZdcvdJ2RMO376y6e9bmIAvUlMcvN0gty85jef24yyiGI3aCxBcBlg5r X-Gm-Gg: Acq92OFkAUtjGvK0P/7JIP/1DfYpnCJNKXEBPsuYM3DoujgbsIg0K8yMgFV1xWTDmgx p4KUch6cmtSDDykHPYHwtzJ2OBdmf3Fm9g87kjCKLVoS3BWNej4OPy+pLSzIERx37wp/syYhaqP ZiaI34vali/FXErM9h6agDJzwm7H/B7DzgJY2XpZ04VzrmIiXbGWIocfmdT/IU0d/CwXSaJ7B+x PF/l8SYx5C9WwW8LvqM7w7zlLH1A7MeSiVFnjFaVVtu2lnEj5WTRObfhoN2/JcbrqDTL1BaHeXM 1MqK3PKX1ZD+3SR2s6Fxtg75V1RjErv1wySwy/gllu6HlbufJ4r9dUOVAULuy9FfX+2dT9fXrNc y8wMkEQbiLoNuhmQBpSDtVKbLK4L2ulT4GcAkf8WKsSItJihOth97yKzU6q80x1HsE5zMGa/+FO DaCCu9oaX0I4IUmcx/5OH6v665KbzvbcV1tjAhkk7oKQ== X-Received: by 2002:a17:90a:fe17:b0:369:7421:8926 with SMTP id 98e67ed59e1d1-36974221529mr267195a91.7.1778903411654; Fri, 15 May 2026 20:50:11 -0700 (PDT) Received: from b330-MS-7D46.. ([122.192.219.205]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-369512424a6sm5491095a91.1.2026.05.15.20.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 20:50:11 -0700 (PDT) From: Ziyu Zhang To: Jaegeuk Kim , Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, r33s3n6@gmail.com, gality369@gmail.com, zhenghaoran154@gmail.com, hanguidong02@gmail.com, zzzccc427@gmail.com, Ziyu Zhang Subject: [PATCH] f2fs: make gc_wake test-and-clear atomic Date: Sat, 16 May 2026 11:50:01 +0800 Message-ID: <20260516035001.272335-1-ziyuzhang201@gmail.com> X-Mailer: git-send-email 2.43.0 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" gc_thread_func() tests gc_th->gc_wake and then clears it with separate plain accesses. sysfs gc_urgent writes set the same flag and wake the GC thread. If a sysfs writer stores true between the GC thread's load and store, the later store false can clear the new wake request. Store gc_wake as an atomic_t. Use atomic_read() for the wait condition, atomic_xchg(..., 0) in the GC thread, and atomic_set(..., 1) in the sysfs trigger paths. This makes the consume-and-clear operation atomic with respect to new wake requests: a set before the exchange is consumed by the current iteration, while a set after the exchange stays pending for the next wait. Fixes: d9872a698c39 ("f2fs: introduce gc_urgent mode for background GC") Signed-off-by: Ziyu Zhang --- fs/f2fs/gc.c | 7 +++---- fs/f2fs/gc.h | 2 +- fs/f2fs/sysfs.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 098e9f71421e..71e40e4083ad 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -49,15 +49,14 @@ static int gc_thread_func(void *data) wait_event_freezable_timeout(*wq, kthread_should_stop() || waitqueue_active(fggc_wq) || - gc_th->gc_wake, + atomic_read(&gc_th->gc_wake), msecs_to_jiffies(wait_ms)); =20 if (test_opt(sbi, GC_MERGE) && waitqueue_active(fggc_wq)) foreground =3D true; =20 /* give it a try one time */ - if (gc_th->gc_wake) - gc_th->gc_wake =3D false; + atomic_xchg(&gc_th->gc_wake, 0); =20 if (f2fs_readonly(sbi->sb)) { stat_other_skip_bggc_count(sbi); @@ -214,7 +213,7 @@ int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) gc_th->boost_zoned_gc_percent =3D 0; } =20 - gc_th->gc_wake =3D false; + atomic_set(&gc_th->gc_wake, 0); =20 sbi->gc_thread =3D gc_th; init_waitqueue_head(&sbi->gc_thread->gc_wait_queue_head); diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h index 24e8b1c27acc..65e5b062a0d3 100644 --- a/fs/f2fs/gc.h +++ b/fs/f2fs/gc.h @@ -56,7 +56,7 @@ struct f2fs_gc_kthread { unsigned int no_gc_sleep_time; =20 /* for changing gc mode */ - bool gc_wake; + atomic_t gc_wake; =20 /* for GC_MERGE mount option */ wait_queue_head_t fggc_wq; /* diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index f736052dea50..6ca5943450d5 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -586,7 +586,7 @@ static ssize_t __sbi_store(struct f2fs_attr *a, } else if (t =3D=3D 1) { sbi->gc_mode =3D GC_URGENT_HIGH; if (sbi->gc_thread) { - sbi->gc_thread->gc_wake =3D true; + atomic_set(&sbi->gc_thread->gc_wake, 1); wake_up_interruptible_all( &sbi->gc_thread->gc_wait_queue_head); wake_up_discard_thread(sbi, true); @@ -596,7 +596,7 @@ static ssize_t __sbi_store(struct f2fs_attr *a, } else if (t =3D=3D 3) { sbi->gc_mode =3D GC_URGENT_MID; if (sbi->gc_thread) { - sbi->gc_thread->gc_wake =3D true; + atomic_set(&sbi->gc_thread->gc_wake, 1); wake_up_interruptible_all( &sbi->gc_thread->gc_wait_queue_head); } --=20 2.43.0