f2fs: introduce FAULT_VMALLOC
authorChao Yu <chao@kernel.org>
Tue, 13 May 2025 05:57:21 +0000 (13:57 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 27 May 2025 23:52:36 +0000 (23:52 +0000)
Introduce a new fault type FAULT_VMALLOC to simulate no memory error in
f2fs_vmalloc().

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

index e060798f9fc1410095121b6bef541b723c7089e3..bf03263b9f468a972334861b34733ac14e5e1676 100644 (file)
@@ -736,6 +736,7 @@ Description:        Support configuring fault injection type, should be
                FAULT_NO_SEGMENT                 0x00100000
                FAULT_INCONSISTENT_FOOTER        0x00200000
                FAULT_TIMEOUT                    0x00400000 (1000ms)
+               FAULT_VMALLOC                    0x00800000
                ===========================      ==========
 
 What:          /sys/fs/f2fs/<disk>/discard_io_aware_gran
index 724fc5e2889a66c0946acbaff2d848eb305d0acf..440e4ae74e443216defc1c968c52b8b35fd9545d 100644 (file)
@@ -208,6 +208,7 @@ fault_type=%d                Support configuring fault injection type, should be
                         FAULT_NO_SEGMENT                 0x00100000
                         FAULT_INCONSISTENT_FOOTER        0x00200000
                         FAULT_TIMEOUT                    0x00400000 (1000ms)
+                        FAULT_VMALLOC                    0x00800000
                         ===========================      ==========
 mode=%s                         Control block allocation mode which supports "adaptive"
                         and "lfs". In "lfs" mode, there should be no random
index b2ec943a4c730f46e1d0bc5cd7d88723bfcccda4..0dc65634cc6123efea1a1b031ec4bcd97059c240 100644 (file)
@@ -180,7 +180,8 @@ void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct folio *folio)
 #ifdef CONFIG_F2FS_FS_LZO
 static int lzo_init_compress_ctx(struct compress_ctx *cc)
 {
-       cc->private = f2fs_vmalloc(LZO1X_MEM_COMPRESS);
+       cc->private = f2fs_vmalloc(F2FS_I_SB(cc->inode),
+                                       LZO1X_MEM_COMPRESS);
        if (!cc->private)
                return -ENOMEM;
 
@@ -247,7 +248,7 @@ static int lz4_init_compress_ctx(struct compress_ctx *cc)
                size = LZ4HC_MEM_COMPRESS;
 #endif
 
-       cc->private = f2fs_vmalloc(size);
+       cc->private = f2fs_vmalloc(F2FS_I_SB(cc->inode), size);
        if (!cc->private)
                return -ENOMEM;
 
@@ -343,7 +344,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
        params = zstd_get_params(level, cc->rlen);
        workspace_size = zstd_cstream_workspace_bound(&params.cParams);
 
-       workspace = f2fs_vmalloc(workspace_size);
+       workspace = f2fs_vmalloc(F2FS_I_SB(cc->inode), workspace_size);
        if (!workspace)
                return -ENOMEM;
 
@@ -423,7 +424,7 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic)
 
        workspace_size = zstd_dstream_workspace_bound(max_window_size);
 
-       workspace = f2fs_vmalloc(workspace_size);
+       workspace = f2fs_vmalloc(F2FS_I_SB(dic->inode), workspace_size);
        if (!workspace)
                return -ENOMEM;
 
index 9f6a02955f973fb7ae0378137145478b52b22dc0..e0196c285ad168a140a013562cabeeb3556386d3 100644 (file)
@@ -64,6 +64,7 @@ enum {
        FAULT_NO_SEGMENT,
        FAULT_INCONSISTENT_FOOTER,
        FAULT_TIMEOUT,
+       FAULT_VMALLOC,
        FAULT_MAX,
 };
 
@@ -3532,8 +3533,11 @@ static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi,
        return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
 }
 
-static inline void *f2fs_vmalloc(size_t size)
+static inline void *f2fs_vmalloc(struct f2fs_sb_info *sbi, size_t size)
 {
+       if (time_to_inject(sbi, FAULT_VMALLOC))
+               return NULL;
+
        return vmalloc(size);
 }
 
index 7654f2beabdde865ccd3ef15b2b406f2c9084abe..b7115690089219e8cab956a9472cc69ea3f1ece7 100644 (file)
@@ -66,6 +66,7 @@ const char *f2fs_fault_name[FAULT_MAX] = {
        [FAULT_NO_SEGMENT]              = "no free segment",
        [FAULT_INCONSISTENT_FOOTER]     = "inconsistent footer",
        [FAULT_TIMEOUT]                 = "timeout",
+       [FAULT_VMALLOC]                 = "vmalloc",
 };
 
 int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate,