]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: control nat_bits feature via mount option
authorChao Yu <chao@kernel.org>
Sat, 8 Mar 2025 05:18:46 +0000 (13:18 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 8 Mar 2025 16:04:10 +0000 (16:04 +0000)
Introduce a new mount option "nat_bits" to control nat_bits feature,
by default nat_bits feature is disabled.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Documentation/filesystems/f2fs.rst
fs/f2fs/f2fs.h
fs/f2fs/node.c
fs/f2fs/super.c

index fb7d2ee022bc06f5dfb3e45e339e353bc5d3b5cd..aad08eff05029bfa12ab23747f367e335825539c 100644 (file)
@@ -365,6 +365,8 @@ errors=%s            Specify f2fs behavior on critical errors. This supports modes:
                         pending node write     drop            keep            N/A
                         pending meta write     keep            keep            N/A
                         ====================== =============== =============== ========
+nat_bits                Enable nat_bits feature to enhance full/empty nat blocks access,
+                        by default it's disabled.
 ======================== ============================================================
 
 Debugfs Entries
index c6cc2694f9ac9f76eccbae8aafcf4ccec7d836d8..20be0ff17dea08e82b5e8787e2164f65b502a869 100644 (file)
@@ -114,6 +114,7 @@ extern const char *f2fs_fault_name[FAULT_MAX];
 #define        F2FS_MOUNT_GC_MERGE             0x02000000
 #define F2FS_MOUNT_COMPRESS_CACHE      0x04000000
 #define F2FS_MOUNT_AGE_EXTENT_CACHE    0x08000000
+#define F2FS_MOUNT_NAT_BITS            0x10000000
 
 #define F2FS_OPTION(sbi)       ((sbi)->mount_opt)
 #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
index 36614a1c25907a518859137b92be6a7d144e57da..af9900bc3714d559112817c502c57ebc4ce2c63a 100644 (file)
@@ -3306,6 +3306,9 @@ static int init_node_manager(struct f2fs_sb_info *sbi)
        if (!nm_i->nat_bitmap)
                return -ENOMEM;
 
+       if (!test_opt(sbi, NAT_BITS))
+               disable_nat_bits(sbi, true);
+
        err = __get_nat_bitmaps(sbi);
        if (err)
                return err;
index 3c875dc072663a8de6554bb600eeb9a1de4722a7..a2808f5fd705627bd1d7f9dad60bd80d3f6c2b56 100644 (file)
@@ -190,6 +190,7 @@ enum {
        Opt_memory_mode,
        Opt_age_extent_cache,
        Opt_errors,
+       Opt_nat_bits,
        Opt_err,
 };
 
@@ -269,6 +270,7 @@ static match_table_t f2fs_tokens = {
        {Opt_memory_mode, "memory=%s"},
        {Opt_age_extent_cache, "age_extent_cache"},
        {Opt_errors, "errors=%s"},
+       {Opt_nat_bits, "nat_bits"},
        {Opt_err, NULL},
 };
 
@@ -1322,6 +1324,9 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
                        }
                        kfree(name);
                        break;
+               case Opt_nat_bits:
+                       set_opt(sbi, NAT_BITS);
+                       break;
                default:
                        f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
                                 p);
@@ -2135,6 +2140,9 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
        else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC)
                seq_printf(seq, ",errors=%s", "panic");
 
+       if (test_opt(sbi, NAT_BITS))
+               seq_puts(seq, ",nat_bits");
+
        return 0;
 }
 
@@ -2325,6 +2333,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        bool no_discard = !test_opt(sbi, DISCARD);
        bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE);
        bool block_unit_discard = f2fs_block_unit_discard(sbi);
+       bool no_nat_bits = !test_opt(sbi, NAT_BITS);
 #ifdef CONFIG_QUOTA
        int i, j;
 #endif
@@ -2453,6 +2462,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
                goto restore_opts;
        }
 
+       if (no_nat_bits == !!test_opt(sbi, NAT_BITS)) {
+               err = -EINVAL;
+               f2fs_warn(sbi, "switch nat_bits option is not allowed");
+               goto restore_opts;
+       }
+
        if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
                err = -EINVAL;
                f2fs_warn(sbi, "disabling checkpoint not compatible with read-only");