From 3a1ee29cd6df3069bce8321784d065fa01d219ff Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Tue, 1 Apr 2025 11:58:00 +0800 Subject: [PATCH] BACKPORT: f2fs: support to disable linear lookup fallback After commit 91b587ba79e1 ("f2fs: Introduce linear search for dentries"), f2fs forced to use linear lookup whenever a hash-based lookup fails on casefolded directory, it may affect performance for scenarios: a) create a new file w/ filename it doesn't exist in directory, b) lookup a file which may be removed. This patch supports to disable linear lookup fallback, so, once there is a solution for commit 5c26d2f1d3f5 ("unicode: Don't special case ignorable code points") to fix red heart unicode issue, then we can set an encodeing flag to disable the fallback for performance recovery. The way is kept in line w/ ext4, refer to commit 9e28059d5664 ("ext4: introduce linear search for dentries"). Cc: Daniel Lee Cc: Gabriel Krisman Bertazi Change-Id: I8f93a8432a16cb9f25309e3afc021f50edc95c2d Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim (cherry picked from commit aa00c6d5d05a80ef5946984025c25ab231b722f9) --- fs/f2fs/dir.c | 3 ++- include/linux/fs.h | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 5a63ff0df03b..a9f21bc1915d 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -366,7 +366,8 @@ start_find_entry: out: #if IS_ENABLED(CONFIG_UNICODE) - if (IS_CASEFOLDED(dir) && !de && use_hash) { + if (!sb_no_casefold_compat_fallback(dir->i_sb) && + IS_CASEFOLDED(dir) && !de && use_hash) { use_hash = false; goto start_find_entry; } diff --git a/include/linux/fs.h b/include/linux/fs.h index 231e77900001..fb45ebb17c07 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1200,11 +1200,19 @@ extern int send_sigurg(struct file *file); #define SB_NOUSER BIT(31) /* These flags relate to encoding and casefolding */ -#define SB_ENC_STRICT_MODE_FL (1 << 0) +#define SB_ENC_STRICT_MODE_FL (1 << 0) +#define SB_ENC_NO_COMPAT_FALLBACK_FL (1 << 1) #define sb_has_strict_encoding(sb) \ (sb->s_encoding_flags & SB_ENC_STRICT_MODE_FL) +#if IS_ENABLED(CONFIG_UNICODE) +#define sb_no_casefold_compat_fallback(sb) \ + (sb->s_encoding_flags & SB_ENC_NO_COMPAT_FALLBACK_FL) +#else +#define sb_no_casefold_compat_fallback(sb) (1) +#endif + /* * Umount options */