From nobody Wed Feb 11 05:41:45 2026 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 DD55453E1B for ; Mon, 20 May 2024 11:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716205045; cv=none; b=f9lN8OcbIbXlJRXLuzPfRvYpAUj9V9M7OK1n7Y9CYYFB/Y8+SRVHsd0P/87cARWhm+lGcAFe5nlFCV5u3gFgYGftZtLhphAuc2sq4MFi5Ach/bgcy2PMngXQ0UhB8pousNfcJJ03m8RhBmInDf9VghCt2rehODSaBeVkC6fERSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716205045; c=relaxed/simple; bh=cj9mL1bGgD8z39mvLMM7/PQdXOTIZAKRgKgyy7lcLMQ=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=oyKXJAdo1mbIzLWh1hSvIK341rofGMuFBeqFo5O4oxIZOz2IDkpooQc0OS3h2N+KCtC+9vcd/K+m+eETVQTEZdiZSjgE1znpDAj60cJ3fTJjOquBD9W2BKb1n0U/aNpKntrd1dD7hEoHlmKYg99mxQlBHEuds2UUfx5sSBnBWOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 44KBaWh8040804; Mon, 20 May 2024 19:36:32 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Vjb672thwz2Q7LW0; Mon, 20 May 2024 19:33:03 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 20 May 2024 19:36:29 +0800 From: Zhiguo Niu To: , CC: , , , , Subject: [PATCH] f2fs: enable atgc if atgc_age_threshold from user is less than elapsed_time Date: Mon, 20 May 2024 19:36:18 +0800 Message-ID: <1716204978-29455-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 44KBaWh8040804 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_threshold 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_info = *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 type, unsigned int start, unsigned int end); int f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool for= ce); 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_info *s= bi, int type, return ret; } =20 -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; =20 - if (!sbi->am.atgc_enabled) - return 0; - f2fs_down_read(&SM_I(sbi)->curseg_lock); =20 mutex_lock(&curseg->curseg_mutex); @@ -2955,7 +2952,9 @@ static int __f2fs_init_atgc_curseg(struct f2fs_sb_inf= o *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); } =20 static void __f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi, int type) 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; } =20 + 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) { + 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; --=20 1.9.1