Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp834025lqj; Mon, 3 Jun 2024 02:05:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXwbARklMto1Sr/KkUTrLRWNelrIWNAodCK0i95kxFzaKfHtjsjw+7kbx1eRPhRSbM73aLV2jUDpZITT1ivhxNFXo/YWinZQ97fkYrjAw== X-Google-Smtp-Source: AGHT+IEKtMwY6lZ3YpkE/u/3KFAXxVv5TJa7mWIHxSzB944TJznFWe6gUxSYE4noh1OnAmTlPNlk X-Received: by 2002:a17:903:495:b0:1f4:6093:66c with SMTP id d9443c01a7336-1f63705c436mr68603635ad.30.1717405558392; Mon, 03 Jun 2024 02:05:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717405558; cv=pass; d=google.com; s=arc-20160816; b=xLfKgPMBmZ9xFqfwqBhfJhpjHXI2B3FkdJT9561bLZs6cRLt7Yw9nLevCce/J5Ozgp 0W6zGavVURXENVRKAOlmmccJDbM/1Q1+wpdisn9cfI1tdkZs8s0Hbj0qNHJdoRayVca5 qoAtoJO1qBNwz40PXuovYxu3d0dadFryMNMXKUlSvv/vlD/dhXNjMPdFmWLsOQOHKMOd bnofUkAJw5JaVaizQ5ucVJ8YHuEpkOdFFZh1h+c3fE0bja/HDrvz683JzZEV6swyP96P EVeR0gYAtHg6V4uz2n4Ajr0lsPEhuZ/zC3JyG/XvNUVyhbK8OdPgN8doN4lxkZCfHHpY XpRQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=xSQVPnz7myYAOgmYIoz+PW++0ntehkTkLHzuX99TEyc=; fh=6tSF0Zm+R6ayXjR9i70SqBuUCp76v6AB09yCZ6HpSZ8=; b=EEK0HIVcqkTr0MUhxWMs0I/waTeKArj9Yq2GI9ueNf0hZqQ9SZCqQaVhWGceUYBUM1 fEAtNa8AH8v9+NL1BrJjnCTA1V8eEKeCVHEtmLShPs+P6Ucxr4mSfaFLu8BFh5u6DHW6 wNKY6OejRIGzkojrgfPNr0F5AKPbW8BAZdobgGxQDuOPNKVX6VKQETlCP6jGxF7++hZS M9Ghf7y3M353e4l2UHgcRF3T6n57iGxAKXS+EMIOOVXLIr1c/JqMJGZT/sCrbUIyibmV a9azfXLqJg+kCVRG6uKvhFybi3CFEjFqqsPO/orW8OfW06JF5B4gj/KuoOeajcXrPlCf 3b9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kky3hHnt; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-198832-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198832-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f6780dc875si17167045ad.197.2024.06.03.02.05.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 02:05:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198832-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kky3hHnt; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-198832-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198832-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 034462837ED for ; Mon, 3 Jun 2024 09:05:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E6F6770F1; Mon, 3 Jun 2024 09:05:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kky3hHnt" Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 DEF233BBF3 for ; Mon, 3 Jun 2024 09:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717405551; cv=none; b=n0uMc0Vsl561+b/uSnXYkzi7DjUdcAplL4jNc929HyMt+ZIAhq3uSvWrjRMaRosgjd7hv/+Nf+PTM85wrEjuuUs0WmdPk9W3TtCFrEZ9DKsZnmwv8LtXkpCj3qeugPVaPqVVEH0M5Y5Zz23s0JJ+D6173Z4Y5oS2GY5Uz+b9Ky8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717405551; c=relaxed/simple; bh=6WLa7LruKri98nPh55YBV/dK/7sYjTWL0W7ZcMRoybo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Eldy8B2QAWC1jUk95LkA6hZbCNrPpfsRwY4v70czowEHX1h58WWAfjDz3+ohm+85t3bwVrRvBXSAAXnV3qKeu9iIefbX5Sz8CkJPP5xGQirDHVlrwrTBZyWVzNvyCC1qVwU6q182b0rKVeEWvgtq3DMZTX1uoyGgfJg6ku1WLnc= 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=kky3hHnt; arc=none smtp.client-ip=209.85.221.50 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 Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-35e4aaa0f33so1560493f8f.0 for ; Mon, 03 Jun 2024 02:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717405548; x=1718010348; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xSQVPnz7myYAOgmYIoz+PW++0ntehkTkLHzuX99TEyc=; b=kky3hHntKi/fstQtWPFhESoFPYn335JCfQXHzFwn/Rm3V1j3plyGhC7NTMWl8btc9n ABFJIc4ygslpMVubhu2DC3JSEKB2v6bqfiFqvdSPk2ZeXArsUduNyTdHPXmB2K6Ig9A1 XiXqM5QpWcBGVNEKPaJrI9OJgg3nVDQRELRRY2NqkOOjECkL8yrtJb7zMB82k3rlEBiL bK6JnmxCQQwW0jDDJewfnygKEYKuoSec53GK1NSjcqiVm08lT7Ed1IvyLX/AzMAC3Ip5 UtOV5z12Noz99wuN9Atu/1aFoVMyrdV/jgLJcEbmaTheWB3CUlisrXwTqnfrRry1DPwJ On1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717405548; x=1718010348; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xSQVPnz7myYAOgmYIoz+PW++0ntehkTkLHzuX99TEyc=; b=BA/1H1wuBMN9kWuU/WCl8yY142/esxL88X16hCGaw45NeLUuwzosKk5Uby8vPP7DHb IXoJCqESfphLM6OyvLLH+0MIaVKmZub2gP8w/92lTLJ4hGBMCUpttC7DyvoBuHXb6sdC O37c1rLQ2wGwle/gdS/GuiErNrdXN2CduDMBMV70duMVcz1+jPQJlaWils2sHcqKZHMu A/IPOKcH1EciK2FZSL+g4cwkjL87mlVeM+hvUHlKsnToflQ1P9ia+EjmWKJYSBGWomVf SUu4M6u8phPlC1HSf1/xG+PMsnsOMJGF7lrHhPs/f0+BlgWcymfuuXzm4n211ZUXeoTP qu/A== X-Forwarded-Encrypted: i=1; AJvYcCUnIvwOIthP858YDeGQjpFqxYA7PPHiWpaALlSGTsuCZERx7ftZexxW7JBeRrMK19fdYfzu7Tu/BC4+UZX+R7Kkx+M2SrkGgKA4A+bJ X-Gm-Message-State: AOJu0YyX9AYhQmTl1oiLn9Jm36fW5i9zcZ419CGaefP7beQVp+6ghXWV jrIm6EfpAhvTdJIqVhC/7xxyDSYbK+wrBhilBi4FF67TJ19kwDVrB8Ejk0/yR/bAjtcDV6SU+qk hDsCN0KE5sQl/e0W1EmcxXmI/ukyAtd5IdQY= X-Received: by 2002:a5d:5350:0:b0:351:b56e:8bc3 with SMTP id ffacd0b85a97d-35e0f325baemr7011366f8f.53.1717405547911; Mon, 03 Jun 2024 02:05:47 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <1716204978-29455-1-git-send-email-zhiguo.niu@unisoc.com> <446c7e4a-2a1e-402d-8238-2eee7cdfd5c2@kernel.org> In-Reply-To: <446c7e4a-2a1e-402d-8238-2eee7cdfd5c2@kernel.org> From: Zhiguo Niu Date: Mon, 3 Jun 2024 17:05:36 +0800 Message-ID: Subject: Re: [PATCH] f2fs: enable atgc if atgc_age_threshold from user is less than elapsed_time To: Chao Yu Cc: Zhiguo Niu , jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, ke.wang@unisoc.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jun 3, 2024 at 3:41=E2=80=AFPM Chao Yu wrote: > > On 2024/5/20 19:36, Zhiguo Niu wrote: > > Now atgc can be enabled based on the following conditions: > > -ATGC mount option is set > > -elapsed_time is more than atgc_age_threshold already > > but these conditions are check when umounted->mounted device again. > > If the device has not be umounted->mounted for a long time, atgc can > > not work even the above conditions met. > > > > It is better to enable atgc dynamiclly when user change atgc_age_thresh= old > > meanwhile this vale is less than elapsed_time and ATGC mount option is = on. > > > > Signed-off-by: Zhiguo Niu > > --- > > fs/f2fs/f2fs.h | 1 + > > fs/f2fs/segment.c | 9 ++++----- > > fs/f2fs/sysfs.c | 16 ++++++++++++++++ > > 3 files changed, 21 insertions(+), 5 deletions(-) > > > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > index 1974b6a..e441d2d 100644 > > --- a/fs/f2fs/f2fs.h > > +++ b/fs/f2fs/f2fs.h > > @@ -3694,6 +3694,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_i= nfo *sbi, > > int f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi); > > void f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi); > > void f2fs_restore_inmem_curseg(struct f2fs_sb_info *sbi); > > +int f2fs_init_atgc_curseg(struct f2fs_sb_info *sbi); > > int f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int ty= pe, > > unsigned int start, unsigned int = end); > > int f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, boo= l force); > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > > index 71dc8042..44923d4 100644 > > --- a/fs/f2fs/segment.c > > +++ b/fs/f2fs/segment.c > > @@ -2931,14 +2931,11 @@ static int get_atssr_segment(struct f2fs_sb_inf= o *sbi, int type, > > return ret; > > } > > > > -static int __f2fs_init_atgc_curseg(struct f2fs_sb_info *sbi) > > +int f2fs_init_atgc_curseg(struct f2fs_sb_info *sbi) > > { > > struct curseg_info *curseg =3D CURSEG_I(sbi, CURSEG_ALL_DATA_ATGC= ); > > int ret =3D 0; > > > > - if (!sbi->am.atgc_enabled) > > - return 0; > > - > > f2fs_down_read(&SM_I(sbi)->curseg_lock); > > > > mutex_lock(&curseg->curseg_mutex); > > @@ -2955,7 +2952,9 @@ static int __f2fs_init_atgc_curseg(struct f2fs_sb= _info *sbi) > > } > > int f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi) > > { > > - return __f2fs_init_atgc_curseg(sbi); > > + if (!sbi->am.atgc_enabled) > > + return 0; > > + return f2fs_init_atgc_curseg(sbi); > > } > > > > static void __f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi, int ty= pe) > > diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c > > index 09d3ecf..72676c5 100644 > > --- a/fs/f2fs/sysfs.c > > +++ b/fs/f2fs/sysfs.c > > @@ -673,6 +673,22 @@ static ssize_t __sbi_store(struct f2fs_attr *a, > > return count; > > } > > > > + if (!strcmp(a->attr.name, "atgc_age_threshold")) { > > + if (t < 0) > > + return -EINVAL; > > + sbi->am.age_threshold =3D t; > > + if (sbi->am.atgc_enabled) > > + return count; > > + > > + if (test_opt(sbi, ATGC) && > > + le64_to_cpu(sbi->ckpt->elapsed_time) >=3D t) { > Hi Chao, > Oh, I guess you want to fix this: Yes, Sorry for not making it clear before. > > static void init_atgc_management(struct f2fs_sb_info *sbi) > { > ... > if (test_opt(sbi, ATGC) && > SIT_I(sbi)->elapsed_time >=3D DEF_GC_THREAD_AGE_THRESHOLD= ) > am->atgc_enabled =3D true; > > What about enabling atgc_enabled during checkpoint once elapsed time is > satisfed w/ the condition? I guess this can give another chance whenever > CP is been triggered, and it can avoid the racing condition as well. 1. I'm not sure if this will increase checkpoint time consumption? 2. dynamically enabling atgc may have other problems. Is this confirmed? thanks=EF=BC=81 > > Thanks, > > > + if (f2fs_init_atgc_curseg(sbi)) > > + return -EINVAL; > > + sbi->am.atgc_enabled =3D true; > > + } > > + return count; > > + } > > + > > if (!strcmp(a->attr.name, "gc_segment_mode")) { > > if (t < MAX_GC_MODE) > > sbi->gc_segment_mode =3D t;