f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
PATCH v4 1/2 f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
SBI_NEED_FSCK is an indicator that fsck.f2fs needs to be triggered, this flag is set in too many places. For some scenes that are not very reproducible, adding stack information will help locate the problem.
Let's expose all fsck stack history in procfs.
--- fs/f2fs/f2fs.h | 33 ++++++++++++++++++++++++++++++++- fs/f2fs/sysfs.c | 26 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +32 -1
@@ -24,6 +24,7 @@#include <linux/quotaops.h> #include <linux/part_stat.h> #include <crypto/hash.h> +#include <linux/stackdepot.h> #include <linux/fscrypt.h> #include <linux/fsverity.h>
@@ -119,6 +120,8 @@ typedef u32 nid_t;#define COMPRESS_EXT_NUM 16 +#define FSCK_STACK_DEPTH 64 +struct f2fs_mount_info {unsigned int opt;int write_io_size_bits;/* Write IO size bits */
@@ -1786,6 +1789,8 @@ struct f2fs_sb_info {unsigned int compress_watermark;/* cache page watermark */ atomic_t compress_page_hit;/* cache hit count */ #endif +depot_stack_handle_t *fsck_stack; +unsigned int fsck_count; };struct f2fs_private_dio {
@@ -1997,9 +2002,35 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)return test_bit (type, &sbi->s_flag); } -static inline void set_sbi_flag (struct f2fs_sb_info *sbi,unsigned int type) +static void set_sbi_flag (struct f2fs_sb_info *sbi,unsigned int type) {set_bit (type, &sbi->s_flag); + +if (unlikely (type ==SBI_NEED_FSCK )) { +unsigned long entries[FSCK_STACK_DEPTH ]; +depot_stack_handle_t stack, *new; +unsigned int nr_entries; +int i; + + nr_entries =stack_trace_save (entries,ARRAY_SIZE (entries),0 ); + nr_entries =filter_irq_stacks (entries, nr_entries); + stack =stack_depot_save (entries, nr_entries,GFP_KERNEL ); +if (!stack) +return ; + +/* Try to find an existing entry for this backtrace */ +for (i =0 ; i < sbi->fsck_count; i++) +if (sbi->fsck_stack[i] == stack) +return ; + + new =krealloc (sbi->fsck_stack, (sbi->fsck_count +1 ) * +sizeof (*sbi->fsck_stack),GFP_KERNEL ); +if (!new) +return ; + + sbi->fsck_stack = new; + sbi->fsck_stack[sbi->fsck_count++] = stack; + } }static inline void clear_sbi_flag (struct f2fs_sb_info *sbi,unsigned int type)
fs/f2fs/sysfs.c +26 -0
@@ -1171,6 +1171,29 @@ static int __maybe_unused iostat_info_seq_show(struct seq_file *seq,return 0 ; } +static int __maybe_unused fsck_stack_seq_show (struct seq_file *seq, +void *offset) +{ +struct super_block *sb = seq->private; +struct f2fs_sb_info *sbi =F2FS_SB (sb); +unsigned long *entries; +unsigned int nr_entries; +unsigned int i, j; + +for (i =0 ; i < sbi->fsck_count; i++) { + nr_entries =stack_depot_fetch (sbi->fsck_stack[i], &entries); +if (!entries) +return 0 ; + +for (j =0 ; j < nr_entries; j++) +seq_printf (seq,"%pS\n" , (void *)entries[j]); + +seq_putc (seq,'\n' ); + } + +return 0 ; +} +static int __maybe_unused victim_bits_seq_show (struct seq_file *seq,void *offset) {
@@ -1261,6 +1284,8 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) iostat_info_seq_show, sb);proc_create_single_data ("victim_bits" ,S_IRUGO , sbi->s_proc, victim_bits_seq_show, sb); +proc_create_single_data ("fsck_stack" ,S_IRUGO , sbi->s_proc, + fsck_stack_seq_show, sb); }return 0 ; put_feature_list_kobj:
@@ -1282,6 +1307,7 @@ void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)remove_proc_entry ("segment_info" , sbi->s_proc);remove_proc_entry ("segment_bits" , sbi->s_proc);remove_proc_entry ("victim_bits" , sbi->s_proc); +remove_proc_entry ("fsck_stack" , sbi->s_proc);remove_proc_entry (sbi->sb->s_id, f2fs_proc_root); }
Signature · 1 line
2.32.0
PATCH v4 2/2 f2fs: convert S_IRUGO to 0444
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.
+ proc_create_single_data("fsck_stack", S_IRUGO, sbi->s_proc,
--- fs/f2fs/debug.c | 2 +- fs/f2fs/sysfs.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
fs/f2fs/debug.c +1 -1
@@ -621,7 +621,7 @@ void __init f2fs_create_root_stats(void)#ifdef CONFIG_DEBUG_FS f2fs_debugfs_root =debugfs_create_dir ("f2fs" ,NULL ); -debugfs_create_file ("status" ,S_IRUGO , f2fs_debugfs_root,NULL , +debugfs_create_file ("status" ,0444 , f2fs_debugfs_root,NULL , &stat_fops);#endif }
fs/f2fs/sysfs.c +5 -5
@@ -1276,15 +1276,15 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) sbi->s_proc =proc_mkdir (sb->s_id, f2fs_proc_root);if (sbi->s_proc) { -proc_create_single_data ("segment_info" ,S_IRUGO , sbi->s_proc, +proc_create_single_data ("segment_info" ,0444 , sbi->s_proc, segment_info_seq_show, sb); -proc_create_single_data ("segment_bits" ,S_IRUGO , sbi->s_proc, +proc_create_single_data ("segment_bits" ,0444 , sbi->s_proc, segment_bits_seq_show, sb); -proc_create_single_data ("iostat_info" ,S_IRUGO , sbi->s_proc, +proc_create_single_data ("iostat_info" ,0444 , sbi->s_proc, iostat_info_seq_show, sb); -proc_create_single_data ("victim_bits" ,S_IRUGO , sbi->s_proc, +proc_create_single_data ("victim_bits" ,0444 , sbi->s_proc, victim_bits_seq_show, sb); -proc_create_single_data ("fsck_stack" ,S_IRUGO , sbi->s_proc, +proc_create_single_data ("fsck_stack" ,0444 , sbi->s_proc, fsck_stack_seq_show, sb); }return 0 ;
Signature · 1 line
2.32.0
kernel test robot
build botI love your patch! Yet something to improve:
Hi Yangtao,
I love your patch! Yet something to improve:
[auto build test ERROR on v5.14-rc5]
[cannot apply to f2fs/dev-test next-20210813]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Yangtao-Li/f2fs-introduce-proc-fs-f2fs-dev-fsck_stack-node/20210813-181512 base: 36a21d51725af2ce0700c6ebcb6b9594aac658a6 config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 10.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/9170231cb55b00262ee1f9240b22b6f1b15bb1e1
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Yangtao-Li/f2fs-introduce-proc-fs-f2fs-dev-fsck_stack-node/20210813-181512 git checkout 9170231cb55b00262ee1f9240b22b6f1b15bb1e1
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from fs/f2fs/dir.c:13:
fs/f2fs/f2fs.h: In function 'set_sbi_flag':
>> fs/f2fs/f2fs.h:1977:16: error: implicit declaration of function 'stack_trace_save'; did you mean 'stack_depot_save'? [-Werror=implicit-function-declaration]
1977 | nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
| ^~~~~~~~~~~~~~~~
| stack_depot_savecc1: some warnings being treated as errors
vim +1977 fs/f2fs/f2fs.h
1966
1967 static void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
1968 {
1969 set_bit(type, &sbi->s_flag);
1970
1971 if (unlikely(type == SBI_NEED_FSCK)) {
1972 unsigned long entries[FSCK_STACK_DEPTH];
1973 depot_stack_handle_t stack, *new;
1974 unsigned int nr_entries;
1975 int i;
1976
> 1977 nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
1978 nr_entries = filter_irq_stacks(entries, nr_entries);
1979 stack = stack_depot_save(entries, nr_entries, GFP_KERNEL);
1980 if (!stack)
1981 return;
1982
1983 /* Try to find an existing entry for this backtrace */
1984 for (i = 0; i < sbi->fsck_count; i++)
1985 if (sbi->fsck_stack[i] == stack)
1986 return;
1987
1988 new = krealloc(sbi->fsck_stack, (sbi->fsck_count + 1) *
1989 sizeof(*sbi->fsck_stack), GFP_KERNEL);
1990 if (!new)
1991 return;
1992
1993 sbi->fsck_stack = new;
1994 sbi->fsck_stack[sbi->fsck_count++] = stack;
1995 }
1996 }
1997
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org