From nobody Wed Dec 17 17:46:17 2025 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 496637344F for ; Tue, 25 Jun 2024 08:09:57 +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=1719303001; cv=none; b=WsXFSyc0iUsRHw+c7iifWf2vfqeNO5WDzpmj6dLy/lVqD6+VslLJougKHZSio7C8XHq7qIE0BQbd127ygwEtyZq8OeJApHc04B1o5wzCZ5h6VBFpVVOIhybnpfqybNoptx+UCDrZUG+9H7HBSqfMpym/HYPoY/CSMSedvXFP7DM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719303001; c=relaxed/simple; bh=TFe37Lm2kh+1TC1JA7q8jV7ydRwDp1EsP+Y+byFXD4U=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=FGuiYxUDWOH5TSWfgqdUleRRiDqI5wNnojAlBXlebahkxUa0KWgGJnlICaYxBBcaIfBig4vrFDSu1tdHLQNr0+v0dLSin5XLY7V2Du4vO3BfxcmjX1/rCawRy6flgP0EbxMInzNZF05iJX466L1TRQY2FUFHcofYKbJjwViDxVw= 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 45P89In1041528; Tue, 25 Jun 2024 16:09:18 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4W7cn20YQWz2RR8CR; Tue, 25 Jun 2024 16:04:38 +0800 (CST) Received: from BJMBX02.spreadtrum.com (10.0.64.8) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 25 Jun 2024 16:09:16 +0800 Received: from BJMBX02.spreadtrum.com ([fe80::c8c3:f3a0:9c9f:b0fb]) by BJMBX02.spreadtrum.com ([fe80::c8c3:f3a0:9c9f:b0fb%19]) with mapi id 15.00.1497.023; Tue, 25 Jun 2024 16:09:16 +0800 From: =?utf-8?B?54mb5b+X5Zu9IChaaGlndW8gTml1KQ==?= To: Chao Yu , "jaegeuk@kernel.org" CC: "linux-f2fs-devel@lists.sourceforge.net" , "linux-kernel@vger.kernel.org" , wangzijie , Yunlei He , =?utf-8?B?546L55qTIChIYW9faGFvIFdhbmcp?= Subject: =?utf-8?B?562U5aSNOiBbUEFUQ0ggdjRdIGYyZnM6IHJlZHVjZSBleHBlbnNpdmUgY2hl?= =?utf-8?Q?ckpoint_trigger_frequency?= Thread-Topic: [PATCH v4] f2fs: reduce expensive checkpoint trigger frequency Thread-Index: AQHaxsyvfbyyiC9cGUGrinilm9Ljg7HYIB4A Date: Tue, 25 Jun 2024 08:09:16 +0000 Message-ID: References: <20240625065459.3665791-1-chao@kernel.org> In-Reply-To: <20240625065459.3665791-1-chao@kernel.org> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MAIL: SHSQR01.spreadtrum.com 45P89In1041528 Reported-by: Yunlei He Reported-by: Zhiguo Niu Reported-by: wangzijie Tested-by: Zhiguo Niu -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6----- =E5=8F=91=E4=BB=B6=E4=BA=BA: Chao Yu =20 =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2024=E5=B9=B46=E6=9C=8825=E6=97=A5 14= :55 =E6=94=B6=E4=BB=B6=E4=BA=BA: jaegeuk@kernel.org =E6=8A=84=E9=80=81: linux-f2fs-devel@lists.sourceforge.net; linux-kernel@vg= er.kernel.org; Chao Yu ; wangzijie ;= =E7=89=9B=E5=BF=97=E5=9B=BD (Zhiguo Niu) ; Yunlei H= e =E4=B8=BB=E9=A2=98: [PATCH v4] f2fs: reduce expensive checkpoint trigger fr= equency =E6=B3=A8=E6=84=8F: =E8=BF=99=E5=B0=81=E9=82=AE=E4=BB=B6=E6=9D=A5=E8=87=AA= =E4=BA=8E=E5=A4=96=E9=83=A8=E3=80=82=E9=99=A4=E9=9D=9E=E4=BD=A0=E7=A1=AE=E5= =AE=9A=E9=82=AE=E4=BB=B6=E5=86=85=E5=AE=B9=E5=AE=89=E5=85=A8=EF=BC=8C=E5=90= =A6=E5=88=99=E4=B8=8D=E8=A6=81=E7=82=B9=E5=87=BB=E4=BB=BB=E4=BD=95=E9=93=BE= =E6=8E=A5=E5=92=8C=E9=99=84=E4=BB=B6=E3=80=82 CAUTION: This email originated from outside of the organization. Do not cli= ck links or open attachments unless you recognize the sender and know the c= ontent is safe. We may trigger high frequent checkpoint for below case: 1. mkdir /mnt/dir1; set dir1 encrypted 2. touch /mnt/file1; fsync /mnt/file1 3. mkdir /mnt/dir2; set dir2 encrypted 4. touch /mnt/file2; fsync /mnt/file2 ... Although, newly created dir and file are not related, due to commit bbf156f= 7afa7 ("f2fs: fix lost xattrs of directories"), we will trigger checkpoint = whenever fsync() comes after a new encrypted dir created. In order to avoid such performance regression issue, let's record an entry = including directory's ino in global cache whenever we update directory's xa= ttr data, and then triggerring checkpoint() only if xattr metadata of targe= t file's parent was updated. This patch updates to cover below no encryption case as well: 1) parent is checkpointed 2) set_xattr(dir) w/ new xnid 3) create(file) 4) fsync(file) Fixes: bbf156f7afa7 ("f2fs: fix lost xattrs of directories") Reported-by: wangzijie Reported-by: Zhiguo Niu Tested-by: Zhiguo Niu Reported-by: Yunlei He Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/file.c | 3 +++ fs/f2fs/xattr.c | 14 ++++++++++++-- include/trace/events/f2fs.h | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f1d65ee3addf..f3c910b898= 3b 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -284,6 +284,7 @@ enum { APPEND_INO, /* for append ino list */ UPDATE_INO, /* for update ino list */ TRANS_DIR_INO, /* for transactions dir ino list */ + ENC_DIR_INO, /* for encrypted dir ino list */ FLUSH_INO, /* for multiple device flushing */ MAX_INO_ENTRY, /* max. list */ }; @@ -1150,6 +1151,7 @@ enum cp_reason_type { CP_FASTBOOT_MODE, CP_SPEC_LOG_NUM, CP_RECOVER_DIR, + CP_ENC_DIR, }; enum iostat_type { diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index a527de1e7a2f..278573974d= b4 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -217,6 +217,9 @@ static inline enum cp_reason_type need_do_checkpoint(st= ruct inode *inode) f2fs_exist_written_data(sbi, F2FS_I(inode)->i_pino, TRANS_DIR_INO)) cp_reason =3D CP_RECOVER_DIR; + else if (f2fs_exist_written_data(sbi, F2FS_I(inode)->i_pino, + ENC_DIR_INO)) + cp_reason =3D CP_ENC_DIR; return cp_reason; } diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index f290fe9327c4..d04c0b47= a4e4 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -629,6 +629,7 @@ static int __f2fs_setxattr(struct inode *inode, int ind= ex, const char *name, const void *value, size_t size, struct page *ipage, int flags) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct f2fs_xattr_entry *here, *last; void *base_addr, *last_base_addr; int found, newsize; @@ -772,9 +773,18 @@ static int __f2fs_setxattr(struct inode *inode, int in= dex, if (index =3D=3D F2FS_XATTR_INDEX_ENCRYPTION && !strcmp(name, F2FS_XATTR_NAME_ENCRYPTION_CONTEXT)) f2fs_set_encrypted_inode(inode); - if (S_ISDIR(inode->i_mode)) - set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_CP); + if (!S_ISDIR(inode->i_mode)) + goto same; + /* + * In restrict mode, fsync() always try to trigger checkpoint for a= ll + * metadata consistency, in other mode, it triggers checkpoint when + * parent's xattr metadata was updated. + */ + if (F2FS_OPTION(sbi).fsync_mode =3D=3D FSYNC_MODE_STRICT) + set_sbi_flag(sbi, SBI_NEED_CP); Hi Chao,=20 For this case, will it also cause the same issue with original issue when f= sync_mode =3D=3D FSYNC_MODE_STRICT ? if ckpt thread is blocked by some reasons and SBI_NEED_CP is not cleared in= time, Subsequent fsync will trigger cp? + else + f2fs_add_ino_entry(sbi, inode->i_ino, ENC_DIR_INO); This patch version regardless of whether dir is encrypted or not, so this n= ame(ENC_DIR_INO) can be rename other for more accurate? Thanks=EF=BC=81 same: if (is_inode_flag_set(inode, FI_ACL_MODE)) { inode->i_mode =3D F2FS_I(inode)->i_acl_mode; diff --git a/i= nclude/trace/events/f2fs.h b/include/trace/events/f2fs.h index ed794b5fefbe= ..e4a94995e9a8 100644 --- a/include/trace/events/f2fs.h +++ b/include/trace/events/f2fs.h @@ -139,7 +139,8 @@ TRACE_DEFINE_ENUM(EX_BLOCK_AGE); { CP_NODE_NEED_CP, "node needs cp" }, \ { CP_FASTBOOT_MODE, "fastboot mode" }, \ { CP_SPEC_LOG_NUM, "log type is 2" }, \ - { CP_RECOVER_DIR, "dir needs recovery" }) + { CP_RECOVER_DIR, "dir needs recovery" }, \ + { CP_ENC_DIR, "persist encryption policy" }) #define show_shutdown_mode(type) \ __print_symbolic(type, \ -- 2.40.1