Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp901637lqt; Fri, 7 Jun 2024 02:01:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2Q82w1BxI+lCe+hHCJDHE3F4Rx9vqJ31ctNb2UP8RuEJmWlSPATSZBs6xuQfPocDPbgAbqWDEjqsPwL5UIujSUSBI5KEa2pn5pYVpmw== X-Google-Smtp-Source: AGHT+IEhbM3p2kTTH6gAXooj1gCgU2n+8g90SQdyVV096CUByGbPyko03BhInP/NmH7fabfysoI5 X-Received: by 2002:a17:906:3882:b0:a69:2025:1535 with SMTP id a640c23a62f3a-a6cd7a8abdemr128684166b.33.1717750906869; Fri, 07 Jun 2024 02:01:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717750906; cv=pass; d=google.com; s=arc-20160816; b=kGinBIrTcKArlhDBCdKz5E3p8daXmSLAKghGDsseN7w2VoaECurQK0+k0gBbXp/099 HNWqbFBohbUowXo4YMKmBXnRxOWny7SleryaloHObHUk+D/PXCrsssKQj7Fi5BVOfSyx 5e8IubJahVszFmXP0nXhTBVoea51ifp2xp9LPNni806iozMFIpQRyFqSWfd2ACu+1XiS qYS3SQVpBzjgjNhulgP13e3STN0tS3PxHCcXNhJ8eSi1RLGbrUGM54wM+QdCp2VPqj3f 4ONf4yJNxvjFS9x1ct8ngac2zS9Um/KRGwqWk2p9CnLlnTgNX9ZBaitQM/y1xY+qth1j gGxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=E0WoHtq2JtQwc4Qrul4y5A2HcvoTVKuDknap1UB384M=; fh=FjGUeRKuY5Vkps/iCklb/wXg4EmcfkRK+rw0nvXgsb0=; b=al+aj0hpK5G6kll/oGbEx8mIYh/+z1MTgpSBfvQB08JBkQCuqC79a3vjq+vDtmhCGS msKsMQ9oyRI5qGrWP1/89LApfcvxmmZBooAoMb6i7iP9sSLixBBPNxPoEif5uhl5erMe 4LFzbuD2kUz/Ooxc4twpaGhESOT6lAGBZZm9iTpob+MmRoFAMZZD9Z8F9ljEstmxMeo8 yILA1Neu2fIilL0EjSIRdBatGT6bmWdF7rthO0zPJxPSVdem8Vod7FHcKmdkxnMmrOhL qAGfTRjlQE9+g474oiZ7+5z+vRoLUssyVABbL+4YLOQO4FVVARss6E2iM+Uxbnpidk8Z ArMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-205659-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205659-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6eab2f12b5si15768766b.26.2024.06.07.02.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 02:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205659-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-205659-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205659-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8D2201F21B6D for ; Fri, 7 Jun 2024 09:01:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 412BD15B127; Fri, 7 Jun 2024 09:01:39 +0000 (UTC) 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 438E417C6C for ; Fri, 7 Jun 2024 09:01:34 +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=1717750898; cv=none; b=MdkrdSYnF5hN5GtOVyGg9Gykz57QmUpzgKKTXS9+wf0DsLDp+NBby6JyGLHSETB4Vh7VUoY4mGE8hCgMmpVqhjX3VGkFOXvP36CdsPY7o629Y+FFFb/ElA3tbIljhfrr0oalIPCQ/hZ9N7Q0bEwtXQohNQpw8rJtZQIf7RhaFfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717750898; c=relaxed/simple; bh=WKtUVRZ3BEvjG0aZ2Mn4jkpRzDVrYF1ttd++DRwKSJc=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fJE47djvvSGiCdsuF/cWj9zarX8CxYmQryOv5kuzIWn37WSS5clCyVRJMMg69Ks5eXvXPrdDnrzYYnZJUIfB1oBTYbTBFOUt0gCwPbm706eV920drFhinTcOzAt4HL9oeTRyklX7NAocJULLyXEaRtFXX7j/0wAAStD4wHvSsXw= 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 45790osD077378; Fri, 7 Jun 2024 17:00:50 +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 4VwZnV1WLkz2QcKjm; Fri, 7 Jun 2024 16:56:46 +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; Fri, 7 Jun 2024 17:00:48 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH V2] f2fs: enable atgc dynamically if conditions are met Date: Fri, 7 Jun 2024 17:00:30 +0800 Message-ID: <1717750830-15423-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 Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 45790osD077378 Now atgc can only be enabled when umounted->mounted device even related conditions have reached. If the device has not be umounted->mounted for a long time, atgc can not work. So enable atgc dynamically when atgc_age_threshold is less than elapsed_time and ATGC mount option is on. Signed-off-by: Chao Yu Signed-off-by: Zhiguo Niu --- v2: try to enabe atgc in cp to avoid some race cases --- --- fs/f2fs/checkpoint.c | 1 + fs/f2fs/f2fs.h | 1 + fs/f2fs/segment.c | 27 ++++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 55d444be..7cfe4e0 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1718,6 +1718,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) } f2fs_restore_inmem_curseg(sbi); + f2fs_reinit_atgc_curseg(sbi); stat_inc_cp_count(sbi); stop: unblock_operations(sbi); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9688df3..8d385a1 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3693,6 +3693,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno); int f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi); +int f2fs_reinit_atgc_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_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 6e8a4b3..362cfb5 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2931,12 +2931,12 @@ static int get_atssr_segment(struct f2fs_sb_info *sbi, int type, return ret; } -static int __f2fs_init_atgc_curseg(struct f2fs_sb_info *sbi) +static int __f2fs_init_atgc_curseg(struct f2fs_sb_info *sbi, bool force) { struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_ALL_DATA_ATGC); int ret = 0; - if (!sbi->am.atgc_enabled) + if (!sbi->am.atgc_enabled && !force) return 0; f2fs_down_read(&SM_I(sbi)->curseg_lock); @@ -2953,9 +2953,30 @@ static int __f2fs_init_atgc_curseg(struct f2fs_sb_info *sbi) f2fs_up_read(&SM_I(sbi)->curseg_lock); return ret; } + int f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi) { - return __f2fs_init_atgc_curseg(sbi); + return __f2fs_init_atgc_curseg(sbi, false); +} + +int f2fs_reinit_atgc_curseg(struct f2fs_sb_info *sbi) +{ + int ret; + + if (!test_opt(sbi, ATGC)) + return 0; + if (sbi->am.atgc_enabled) + return 0; + if (le64_to_cpu(F2FS_CKPT(sbi)->elapsed_time) < + sbi->am.age_threshold) + return 0; + + ret = __f2fs_init_atgc_curseg(sbi, true); + if (!ret) { + sbi->am.atgc_enabled = true; + f2fs_info(sbi, "reenabled age threshold GC"); + } + return ret; } static void __f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi, int type) -- 1.9.1