Skip to content

Commit 54ca9be

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: introduce FAULT_VMALLOC
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>
1 parent 70dd07c commit 54ca9be

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ Description: Support configuring fault injection type, should be
736736
FAULT_NO_SEGMENT 0x00100000
737737
FAULT_INCONSISTENT_FOOTER 0x00200000
738738
FAULT_TIMEOUT 0x00400000 (1000ms)
739+
FAULT_VMALLOC 0x00800000
739740
=========================== ==========
740741

741742
What: /sys/fs/f2fs/<disk>/discard_io_aware_gran

Documentation/filesystems/f2fs.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ fault_type=%d Support configuring fault injection type, should be
208208
FAULT_NO_SEGMENT 0x00100000
209209
FAULT_INCONSISTENT_FOOTER 0x00200000
210210
FAULT_TIMEOUT 0x00400000 (1000ms)
211+
FAULT_VMALLOC 0x00800000
211212
=========================== ==========
212213
mode=%s Control block allocation mode which supports "adaptive"
213214
and "lfs". In "lfs" mode, there should be no random

fs/f2fs/compress.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct folio *folio)
180180
#ifdef CONFIG_F2FS_FS_LZO
181181
static int lzo_init_compress_ctx(struct compress_ctx *cc)
182182
{
183-
cc->private = f2fs_vmalloc(LZO1X_MEM_COMPRESS);
183+
cc->private = f2fs_vmalloc(F2FS_I_SB(cc->inode),
184+
LZO1X_MEM_COMPRESS);
184185
if (!cc->private)
185186
return -ENOMEM;
186187

@@ -247,7 +248,7 @@ static int lz4_init_compress_ctx(struct compress_ctx *cc)
247248
size = LZ4HC_MEM_COMPRESS;
248249
#endif
249250

250-
cc->private = f2fs_vmalloc(size);
251+
cc->private = f2fs_vmalloc(F2FS_I_SB(cc->inode), size);
251252
if (!cc->private)
252253
return -ENOMEM;
253254

@@ -343,7 +344,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
343344
params = zstd_get_params(level, cc->rlen);
344345
workspace_size = zstd_cstream_workspace_bound(&params.cParams);
345346

346-
workspace = f2fs_vmalloc(workspace_size);
347+
workspace = f2fs_vmalloc(F2FS_I_SB(cc->inode), workspace_size);
347348
if (!workspace)
348349
return -ENOMEM;
349350

@@ -423,7 +424,7 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic)
423424

424425
workspace_size = zstd_dstream_workspace_bound(max_window_size);
425426

426-
workspace = f2fs_vmalloc(workspace_size);
427+
workspace = f2fs_vmalloc(F2FS_I_SB(dic->inode), workspace_size);
427428
if (!workspace)
428429
return -ENOMEM;
429430

fs/f2fs/f2fs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ enum {
6464
FAULT_NO_SEGMENT,
6565
FAULT_INCONSISTENT_FOOTER,
6666
FAULT_TIMEOUT,
67+
FAULT_VMALLOC,
6768
FAULT_MAX,
6869
};
6970

@@ -3532,8 +3533,11 @@ static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi,
35323533
return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
35333534
}
35343535

3535-
static inline void *f2fs_vmalloc(size_t size)
3536+
static inline void *f2fs_vmalloc(struct f2fs_sb_info *sbi, size_t size)
35363537
{
3538+
if (time_to_inject(sbi, FAULT_VMALLOC))
3539+
return NULL;
3540+
35373541
return vmalloc(size);
35383542
}
35393543

fs/f2fs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const char *f2fs_fault_name[FAULT_MAX] = {
6666
[FAULT_NO_SEGMENT] = "no free segment",
6767
[FAULT_INCONSISTENT_FOOTER] = "inconsistent footer",
6868
[FAULT_TIMEOUT] = "timeout",
69+
[FAULT_VMALLOC] = "vmalloc",
6970
};
7071

7172
int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate,

0 commit comments

Comments
 (0)