Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp979651rdb; Sun, 18 Feb 2024 23:19:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWUK9XIjLOxtlkcstLXwQyLqqZ0oltR1j5fazdinAM9CUAMpWyKvLZ5WdlaZNW4cjGCDv5ekJv5bf0InsFBiwqgfAFmAwssdx1YknD0gA== X-Google-Smtp-Source: AGHT+IEZtswMvv6SPCG9K6oXb1qIGegNW/2Uy0zu1LjbqFSQpAi/cz0+ocNOKgbMtbWW0i1Sk44N X-Received: by 2002:a17:90a:8ce:b0:299:35e9:f18 with SMTP id 14-20020a17090a08ce00b0029935e90f18mr5459884pjn.39.1708327151879; Sun, 18 Feb 2024 23:19:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708327151; cv=pass; d=google.com; s=arc-20160816; b=fN234UXyo6R4KMszIveIBMT/9cZaKQwncY3gZwrkfa/M/4pU5Tsvo2pVFRMxaaGGM0 5bkBe5mBwDecH2HTK3iI1Uxj27o6LGmLRm8YkjH/vodg4P25+EQRfMc5/7AGI9iz6nxY haIr35XRwtJx740wUPQEgdAEOzsY6h+U3xJaXykiEbt3doC7kjjJ1WomOajYr2oimLuF li1+0H7kkF7BOaviIksijg6Ez2rtXe5/QmAxtwZmaZYKxLYmPVK4oU4rgYArel24YHHq M8Orgx2Juwk9rW7V3bzlxZEfBEvf6Elyq0cnx7eHHwaQMek10g6FcGiYyJPkBbo02NQH Kzpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=7+8koXOhA1BxfRLWCGX8EcP/4OtI+ZUU6ZrygpC78eI=; fh=/jlYmfOSBew87hQhZ7CSJ4Aj/z9Pn9jdNj9+GyJO/QQ=; b=gqE+KnJ7ZuesLKEcOMhVDsB9cjB2AYMo1ufuSb/0LPlKnGYBfgYHJBa7BJXyx2DdW+ aaXMuhmmag9op5gIVl7sqlHqsaLWD2a4xqd2RsYUPp/tS5bEg9cjs5HpyV/C7iRvRP1O vJ18bzl7j6ZIVafl38+4Ph+JsDsdM1f4VXzsRmgWMg9rWfzMMjX6mnoxtbfQSzxjoLbg WAMWvD83/LNeOq9FbiFxV5kHD/jp5mi+JKroO78lqps9GA8iUQn9FUNrHKgenwFajyOh hQ3mT7+LVlrIkW8C6se1T54OJqYDrCrS1n89F+1uY/3g5a2VIiwWhY9GKy5bhFn3dTT2 Je5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FNpPeAg+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-70814-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k17-20020a17090a591100b0028e63fbc789si4023783pji.107.2024.02.18.23.19.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 23:19:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70814-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=@kernel.org header.s=k20201202 header.b=FNpPeAg+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-70814-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 943D0283FD3 for ; Mon, 19 Feb 2024 07:19:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11EF320B20; Mon, 19 Feb 2024 07:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FNpPeAg+" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F3C6420B09 for ; Mon, 19 Feb 2024 07:19:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708327149; cv=none; b=RjWqEkKWtxef1b2rt86eHNUno+CAFJ3Kh2/hDpoRRkE/lHR14kTmjyI8/R55D1UlI0ghJC/5FZbsx/2/YZmvWHsisxhQvnqssY0FEcgjwmbYRYRA/aiCzkoxFgPXioExtQKMk8V4FXKFr7Y0a6VFC+LqcPbuoMsXN+IrfZ+fL7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708327149; c=relaxed/simple; bh=H/LvVtNLbX7Glwkxq0tYV6X0XZq4RSQbYoC8dTerJNI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Lntu8my4bdUKSM5pm0I3NbVb4O7uQQ5XuTcz/mOVeLaE5y96uXuAtcDGGWRfkFJxZBhY5JPI0pTP4DHBAbQzHDdpdKxjrTJf3g2mfvEQB4gLsmjhFBukpVsbNNfPN/ML9rkNu4ja6W7J2YvSYxbCcES4rsSsO7/0jEDHX3YzI5o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FNpPeAg+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E0FDC433F1; Mon, 19 Feb 2024 07:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708327148; bh=H/LvVtNLbX7Glwkxq0tYV6X0XZq4RSQbYoC8dTerJNI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=FNpPeAg+cF8+1q4yw+Awwp75FsBkjyv8hc8WZmmUBUE8uhVrruY69sGZfcQ2b/6D6 iqu3qP5W5Gg8XNOcqydNIf2cF6VXoD42MKh3e7O5qL/jH+Crkg58Q7VdNIyr9oJWUt N3M/wrMEYcRgaYiAjsjTVdKYYdesqpBLt14Hp2nPCk4cnQcnF0P3fDF694YtiGgTWG L22An/T9kHdOSlziRlnCXzCxm2xJufEhZWn9xg2Q+WYHE+1YFO/HNN9WcT7fv1nUmJ dJomfnTVJOWnAZuRmOg+Vt4g1mGUTJU72UrenbxmGT4qMnsidQU3DtJ9Ui0cSuESdn OqQkutjCYUkmA== Message-ID: Date: Mon, 19 Feb 2024 15:19:04 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] f2fs: reduce expensive checkpoint trigger frequency Content-Language: en-US To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Zhiguo Niu References: <20240111081743.2999210-1-chao@kernel.org> From: Chao Yu In-Reply-To: <20240111081743.2999210-1-chao@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Jaegeuk, Any comments? On 2024/1/11 16:17, Chao Yu wrote: > 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 bbf156f7afa7 ("f2fs: fix lost xattrs of directories"), we will > trigger checkpoint whenever fsync() comes after a new encrypted dir > created. > > In order to avoid such condition, let's record an entry including > directory's ino into global cache when we initialize encryption policy > in a checkpointed directory, and then only trigger checkpoint() when > target file's parent has non-persisted encryption policy, for the case > its parent is not checkpointed, need_do_checkpoint() has cover that > by verifying it with f2fs_is_checkpointed_node(). > > Reported-by: Zhiguo Niu > Tested-by: Zhiguo Niu > Reported-by: Yunlei He > Signed-off-by: Chao Yu > --- > v3: > - Recently, Zhiguo Niu reported the same issue, so I repost this > patch for comments. > fs/f2fs/f2fs.h | 2 ++ > fs/f2fs/file.c | 3 +++ > fs/f2fs/xattr.c | 16 ++++++++++++++-- > include/trace/events/f2fs.h | 3 ++- > 4 files changed, 21 insertions(+), 3 deletions(-) > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index e2e0ca45f881..0094a8c85f4a 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -279,6 +279,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 */ > }; > @@ -1147,6 +1148,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 8198afb5fb9c..18b33b1f0c83 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -218,6 +218,9 @@ static inline enum cp_reason_type need_do_checkpoint(struct inode *inode) > f2fs_exist_written_data(sbi, F2FS_I(inode)->i_pino, > TRANS_DIR_INO)) > cp_reason = CP_RECOVER_DIR; > + else if (f2fs_exist_written_data(sbi, F2FS_I(inode)->i_pino, > + ENC_DIR_INO)) > + cp_reason = CP_ENC_DIR; > > return cp_reason; > } > diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c > index f290fe9327c4..cbd1b88297fe 100644 > --- a/fs/f2fs/xattr.c > +++ b/fs/f2fs/xattr.c > @@ -629,6 +629,7 @@ static int __f2fs_setxattr(struct inode *inode, int index, > const char *name, const void *value, size_t size, > struct page *ipage, int flags) > { > + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > struct f2fs_xattr_entry *here, *last; > void *base_addr, *last_base_addr; > int found, newsize; > @@ -772,8 +773,19 @@ static int __f2fs_setxattr(struct inode *inode, int index, > if (index == 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)) { > + /* > + * In restrict mode, fsync() always tries triggering checkpoint > + * for all metadata consistency, in other mode, it only triggers > + * checkpoint when parent's encryption metadata updates. > + */ > + if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) > + set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_CP); > + else if (IS_ENCRYPTED(inode) && > + f2fs_is_checkpointed_node(sbi, inode->i_ino)) > + f2fs_add_ino_entry(sbi, inode->i_ino, ENC_DIR_INO); > + } > > same: > if (is_inode_flag_set(inode, FI_ACL_MODE)) { > diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h > index 7ed0fc430dc6..48f2e399e184 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, \