linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
@ 2021-08-13 12:32 Yangtao Li
  2021-08-13 12:32 ` [PATCH v5 2/2] f2fs: convert S_IRUGO to 0444 Yangtao Li
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Yangtao Li @ 2021-08-13 12:32 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, Yangtao Li

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.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
v5:
-fix implicit declaration of function 'stack_trace_save'
 fs/f2fs/f2fs.h  | 34 +++++++++++++++++++++++++++++++++-
 fs/f2fs/sysfs.c | 26 ++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 67faa43cc141..cbd06dea3c6a 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -24,6 +24,8 @@
 #include <linux/quotaops.h>
 #include <linux/part_stat.h>
 #include <crypto/hash.h>
+#include <linux/stackdepot.h>
+#include <linux/stacktrace.h>
 
 #include <linux/fscrypt.h>
 #include <linux/fsverity.h>
@@ -119,6 +121,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 +1790,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 +2003,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)
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 0954761341d7..c134bbb99c7b 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -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);
 	}
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v5 2/2] f2fs: convert S_IRUGO to 0444
  2021-08-13 12:32 [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Yangtao Li
@ 2021-08-13 12:32 ` Yangtao Li
  2021-08-13 14:44 ` [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Chao Yu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Yangtao Li @ 2021-08-13 12:32 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, Yangtao Li

WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.
+               proc_create_single_data("fsck_stack", S_IRUGO, sbi->s_proc,

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/f2fs/debug.c |  2 +-
 fs/f2fs/sysfs.c | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 473ad04d1891..401e5e34edd6 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -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
 }
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index c134bbb99c7b..09bf8c4be2b1 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -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;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
  2021-08-13 12:32 [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Yangtao Li
  2021-08-13 12:32 ` [PATCH v5 2/2] f2fs: convert S_IRUGO to 0444 Yangtao Li
@ 2021-08-13 14:44 ` Chao Yu
  2021-08-13 18:33   ` 李扬韬
  2021-08-13 18:06 ` kernel test robot
  2021-08-14  8:52 ` Christoph Hellwig
  3 siblings, 1 reply; 9+ messages in thread
From: Chao Yu @ 2021-08-13 14:44 UTC (permalink / raw)
  To: Yangtao Li, jaegeuk; +Cc: linux-f2fs-devel, linux-kernel

On 2021/8/13 20:32, Yangtao Li wrote:
> 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.
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> v5:
> -fix implicit declaration of function 'stack_trace_save'
>   fs/f2fs/f2fs.h  | 34 +++++++++++++++++++++++++++++++++-
>   fs/f2fs/sysfs.c | 26 ++++++++++++++++++++++++++
>   2 files changed, 59 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 67faa43cc141..cbd06dea3c6a 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -24,6 +24,8 @@
>   #include <linux/quotaops.h>
>   #include <linux/part_stat.h>
>   #include <crypto/hash.h>
> +#include <linux/stackdepot.h>
> +#include <linux/stacktrace.h>
>   
>   #include <linux/fscrypt.h>
>   #include <linux/fsverity.h>
> @@ -119,6 +121,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 +1790,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 +2003,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)) {

Hmm... I don't know what to say...

> +		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)

stack need to be released here?

> +				return;
> +
> +		new = krealloc(sbi->fsck_stack, (sbi->fsck_count + 1) *
> +			       sizeof(*sbi->fsck_stack), GFP_KERNEL);
> +		if (!new)

Ditto?

> +			return;
> +
> +		sbi->fsck_stack = new;

Need to be released somewhere.

> +		sbi->fsck_stack[sbi->fsck_count++] = stack;

Need to be released somewhere.

> +	}
>   }
>   
>   static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index 0954761341d7..c134bbb99c7b 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -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);
>   	}
>   
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
  2021-08-13 12:32 [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Yangtao Li
  2021-08-13 12:32 ` [PATCH v5 2/2] f2fs: convert S_IRUGO to 0444 Yangtao Li
  2021-08-13 14:44 ` [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Chao Yu
@ 2021-08-13 18:06 ` kernel test robot
  2021-08-14  8:52 ` Christoph Hellwig
  3 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2021-08-13 18:06 UTC (permalink / raw)
  To: Yangtao Li, jaegeuk, chao
  Cc: kbuild-all, linux-f2fs-devel, linux-kernel, Yangtao Li

[-- Attachment #1: Type: text/plain, Size: 5210 bytes --]

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-203435
base:    36a21d51725af2ce0700c6ebcb6b9594aac658a6
config: openrisc-buildonly-randconfig-r006-20210813 (attached as .config)
compiler: or1k-linux-gcc (GCC) 11.2.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/82cad918b8c0849884a4fa162595110dcb777627
        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-203435
        git checkout 82cad918b8c0849884a4fa162595110dcb777627
        # save the attached .config to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=openrisc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   or1k-linux-ld: fs/f2fs/dir.o: in function `set_sbi_flag.part.0':
>> dir.c:(.text+0x28): undefined reference to `filter_irq_stacks'
   dir.c:(.text+0x28): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `filter_irq_stacks'
>> or1k-linux-ld: dir.c:(.text+0x38): undefined reference to `stack_depot_save'
   dir.c:(.text+0x38): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `stack_depot_save'
   or1k-linux-ld: fs/f2fs/file.o: in function `set_sbi_flag.part.0':
>> file.c:(.text+0xc58): undefined reference to `filter_irq_stacks'
   file.c:(.text+0xc58): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `filter_irq_stacks'
>> or1k-linux-ld: file.c:(.text+0xc68): undefined reference to `stack_depot_save'
   file.c:(.text+0xc68): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `stack_depot_save'
   or1k-linux-ld: fs/f2fs/inode.o: in function `set_sbi_flag.part.0':
>> inode.c:(.text+0x234): undefined reference to `filter_irq_stacks'
   inode.c:(.text+0x234): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `filter_irq_stacks'
>> or1k-linux-ld: inode.c:(.text+0x244): undefined reference to `stack_depot_save'
   inode.c:(.text+0x244): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `stack_depot_save'
   or1k-linux-ld: fs/f2fs/super.o: in function `set_sbi_flag.part.0':
>> super.c:(.text+0x54b8): undefined reference to `filter_irq_stacks'
   super.c:(.text+0x54b8): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `filter_irq_stacks'
>> or1k-linux-ld: super.c:(.text+0x54c8): undefined reference to `stack_depot_save'
   super.c:(.text+0x54c8): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `stack_depot_save'
   or1k-linux-ld: fs/f2fs/inline.o: in function `set_sbi_flag.part.0':
>> inline.c:(.text+0x28): undefined reference to `filter_irq_stacks'
   inline.c:(.text+0x28): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `filter_irq_stacks'
>> or1k-linux-ld: inline.c:(.text+0x38): undefined reference to `stack_depot_save'
   inline.c:(.text+0x38): relocation truncated to fit: R_OR1K_INSN_REL_26 against undefined symbol `stack_depot_save'
   or1k-linux-ld: fs/f2fs/checkpoint.o: in function `set_sbi_flag.part.0':
>> checkpoint.c:(.text+0x134): undefined reference to `filter_irq_stacks'
   checkpoint.c:(.text+0x134): additional relocation overflows omitted from the output
>> or1k-linux-ld: checkpoint.c:(.text+0x144): undefined reference to `stack_depot_save'
   or1k-linux-ld: fs/f2fs/gc.o: in function `set_sbi_flag.part.0':
>> gc.c:(.text+0x178): undefined reference to `filter_irq_stacks'
>> or1k-linux-ld: gc.c:(.text+0x188): undefined reference to `stack_depot_save'
   or1k-linux-ld: fs/f2fs/node.o: in function `set_sbi_flag.part.0':
>> node.c:(.text+0x1cc): undefined reference to `filter_irq_stacks'
>> or1k-linux-ld: node.c:(.text+0x1dc): undefined reference to `stack_depot_save'
   or1k-linux-ld: fs/f2fs/segment.o: in function `set_sbi_flag.part.0':
>> segment.c:(.text+0x674): undefined reference to `filter_irq_stacks'
>> or1k-linux-ld: segment.c:(.text+0x684): undefined reference to `stack_depot_save'
   or1k-linux-ld: fs/f2fs/sysfs.o: in function `fsck_stack_seq_show':
>> sysfs.c:(.text+0x448): undefined reference to `stack_depot_fetch'
   or1k-linux-ld: fs/f2fs/xattr.o: in function `set_sbi_flag.part.0':
>> xattr.c:(.text+0x278): undefined reference to `filter_irq_stacks'
   or1k-linux-ld: xattr.c:(.text+0x288): undefined reference to `stack_depot_save'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33417 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re:Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
  2021-08-13 14:44 ` [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Chao Yu
@ 2021-08-13 18:33   ` 李扬韬
  2021-08-14  1:59     ` Chao Yu
  0 siblings, 1 reply; 9+ messages in thread
From: 李扬韬 @ 2021-08-13 18:33 UTC (permalink / raw)
  To: Chao Yu; +Cc: jaegeuk, linux-f2fs-devel, linux-kernel

From: Chao Yu <chao@kernel.org>
Date: 2021-08-13 22:44:49
To:  Yangtao Li <frank.li@vivo.com>,jaegeuk@kernel.org
Cc:  linux-f2fs-devel@lists.sourceforge.net,linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node>On 2021/8/13 20:32, Yangtao Li wrote:
>> 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.
>> 
>> Signed-off-by: Yangtao Li <frank.li@vivo.com>
>> ---
>> v5:
>> -fix implicit declaration of function 'stack_trace_save'
>>   fs/f2fs/f2fs.h  | 34 +++++++++++++++++++++++++++++++++-
>>   fs/f2fs/sysfs.c | 26 ++++++++++++++++++++++++++
>>   2 files changed, 59 insertions(+), 1 deletion(-)
>> 
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 67faa43cc141..cbd06dea3c6a 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -24,6 +24,8 @@
>>   #include <linux/quotaops.h>
>>   #include <linux/part_stat.h>
>>   #include <crypto/hash.h>
>> +#include <linux/stackdepot.h>
>> +#include <linux/stacktrace.h>
>>   
>>   #include <linux/fscrypt.h>
>>   #include <linux/fsverity.h>
>> @@ -119,6 +121,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 +1790,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 +2003,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)) {
>
>Hmm... I don't know what to say...

Sorry, maybe there is a problem with my vim configuration.
The strange thing is that checkpatch.pl didn't check it out.

>
>> +		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)
>
>stack need to be released here?

We can't remove stack from depot, as we store them contiguously one after
another in a contiguous memory allocation.

Or we can limit the recorded stack number.

$ grep -nr "SBI_NEED_FSCK" fs/f2fs/ --include=*.c --include=*.h | wc -l
53
$ grep -nr "f2fs_bug_on" fs/f2fs/ --include=*.c --include=*.h | wc -l
135

Since we only have two hundred possible settings here, considering that
the same stack will not be recorded, and the probability of occurrence will
not be high, so it is acceptable not to release?

If this is the case, the subsequent allocation does not need to be released.

Thx,
Yangtao


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
  2021-08-13 18:33   ` 李扬韬
@ 2021-08-14  1:59     ` Chao Yu
  2021-08-14  2:08       ` 李扬韬
  0 siblings, 1 reply; 9+ messages in thread
From: Chao Yu @ 2021-08-14  1:59 UTC (permalink / raw)
  To: 李扬韬; +Cc: jaegeuk, linux-f2fs-devel, linux-kernel

On 2021/8/14 2:33, 李扬韬 wrote:
> From: Chao Yu <chao@kernel.org>
> Date: 2021-08-13 22:44:49
> To:  Yangtao Li <frank.li@vivo.com>,jaegeuk@kernel.org
> Cc:  linux-f2fs-devel@lists.sourceforge.net,linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node>On 2021/8/13 20:32, Yangtao Li wrote:
>>> 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.
>>>
>>> Signed-off-by: Yangtao Li <frank.li@vivo.com>
>>> ---
>>> v5:
>>> -fix implicit declaration of function 'stack_trace_save'
>>>    fs/f2fs/f2fs.h  | 34 +++++++++++++++++++++++++++++++++-
>>>    fs/f2fs/sysfs.c | 26 ++++++++++++++++++++++++++
>>>    2 files changed, 59 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>> index 67faa43cc141..cbd06dea3c6a 100644
>>> --- a/fs/f2fs/f2fs.h
>>> +++ b/fs/f2fs/f2fs.h
>>> @@ -24,6 +24,8 @@
>>>    #include <linux/quotaops.h>
>>>    #include <linux/part_stat.h>
>>>    #include <crypto/hash.h>
>>> +#include <linux/stackdepot.h>
>>> +#include <linux/stacktrace.h>
>>>    
>>>    #include <linux/fscrypt.h>
>>>    #include <linux/fsverity.h>
>>> @@ -119,6 +121,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 +1790,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 +2003,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)) {
>>
>> Hmm... I don't know what to say...
> 
> Sorry, maybe there is a problem with my vim configuration.
> The strange thing is that checkpatch.pl didn't check it out.
> 
>>
>>> +		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)
>>
>> stack need to be released here?
> 
> We can't remove stack from depot, as we store them contiguously one after
> another in a contiguous memory allocation.
> 
> Or we can limit the recorded stack number.
> 
> $ grep -nr "SBI_NEED_FSCK" fs/f2fs/ --include=*.c --include=*.h | wc -l
> 53
> $ grep -nr "f2fs_bug_on" fs/f2fs/ --include=*.c --include=*.h | wc -l
> 135

I didn't look into details of stack_depot_save(), two stack handles from below
call paths will be the same?

- move_data_block
  - f2fs_wait_on_page_writeback
   - f2fs_bug_on

- ra_data_block
  - f2fs_wait_on_page_writeback
   - f2fs_bug_on

If they have different stack handles, combination number of
set_sbi_flag(NEED_FSCK)/f2fs_bug_on and their callers will be far more than two
hundred.

Thanks,

> 
> Since we only have two hundred possible settings here, considering that
> the same stack will not be recorded, and the probability of occurrence will
> not be high, so it is acceptable not to release?
> 
> If this is the case, the subsequent allocation does not need to be released.
> 
> Thx,
> Yangtao
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re:Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
  2021-08-14  1:59     ` Chao Yu
@ 2021-08-14  2:08       ` 李扬韬
  2021-08-16  1:54         ` Chao Yu
  0 siblings, 1 reply; 9+ messages in thread
From: 李扬韬 @ 2021-08-14  2:08 UTC (permalink / raw)
  To: Chao Yu; +Cc: jaegeuk, linux-f2fs-devel, linux-kernel

>> We can't remove stack from depot, as we store them contiguously one after
>> another in a contiguous memory allocation.
>> 
>> Or we can limit the recorded stack number.
>> 
>> $ grep -nr "SBI_NEED_FSCK" fs/f2fs/ --include=*.c --include=*.h | wc -l
>> 53
>> $ grep -nr "f2fs_bug_on" fs/f2fs/ --include=*.c --include=*.h | wc -l
>> 135
>
>I didn't look into details of stack_depot_save(), two stack handles from below
>call paths will be the same?
>
>- move_data_block
>  - f2fs_wait_on_page_writeback
>   - f2fs_bug_on
>
>- ra_data_block
>  - f2fs_wait_on_page_writeback
>   - f2fs_bug_on
>
>If they have different stack handles, combination number of
>set_sbi_flag(NEED_FSCK)/f2fs_bug_on and their callers will be far more than two
>hundred.
>

Yes, these will be two different stacks. In the most extreme case, there will be 1000 (I guess) different places to set fsck?
Or we limit the number of recorded stacks to 10?
what do you think. The stack depot design does not consider removing the stack from the depot.

MBR,
Yangtao


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
  2021-08-13 12:32 [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Yangtao Li
                   ` (2 preceding siblings ...)
  2021-08-13 18:06 ` kernel test robot
@ 2021-08-14  8:52 ` Christoph Hellwig
  3 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-08-14  8:52 UTC (permalink / raw)
  To: Yangtao Li; +Cc: jaegeuk, chao, linux-f2fs-devel, linux-kernel

Please don't add new non-process files to procfs.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node
  2021-08-14  2:08       ` 李扬韬
@ 2021-08-16  1:54         ` Chao Yu
  0 siblings, 0 replies; 9+ messages in thread
From: Chao Yu @ 2021-08-16  1:54 UTC (permalink / raw)
  To: 李扬韬; +Cc: jaegeuk, linux-f2fs-devel, linux-kernel

On 2021/8/14 10:08, 李扬韬 wrote:
>>> We can't remove stack from depot, as we store them contiguously one after
>>> another in a contiguous memory allocation.
>>>
>>> Or we can limit the recorded stack number.
>>>
>>> $ grep -nr "SBI_NEED_FSCK" fs/f2fs/ --include=*.c --include=*.h | wc -l
>>> 53
>>> $ grep -nr "f2fs_bug_on" fs/f2fs/ --include=*.c --include=*.h | wc -l
>>> 135
>>
>> I didn't look into details of stack_depot_save(), two stack handles from below
>> call paths will be the same?
>>
>> - move_data_block
>>   - f2fs_wait_on_page_writeback
>>    - f2fs_bug_on
>>
>> - ra_data_block
>>   - f2fs_wait_on_page_writeback
>>    - f2fs_bug_on
>>
>> If they have different stack handles, combination number of
>> set_sbi_flag(NEED_FSCK)/f2fs_bug_on and their callers will be far more than two
>> hundred.
>>
> 
> Yes, these will be two different stacks. In the most extreme case, there will be 1000 (I guess) different places to set fsck?

It may be according to call stack height of each handle record.

> Or we limit the number of recorded stacks to 10?

Yes, please limit the record number, maybe 8? and stack height could be 16 at
maximum?

Thanks,

> what do you think. The stack depot design does not consider removing the stack from the depot.
> 
> MBR,
> Yangtao
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-16  1:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13 12:32 [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Yangtao Li
2021-08-13 12:32 ` [PATCH v5 2/2] f2fs: convert S_IRUGO to 0444 Yangtao Li
2021-08-13 14:44 ` [PATCH v5 1/2] f2fs: introduce proc/fs/f2fs/<dev>/fsck_stack node Chao Yu
2021-08-13 18:33   ` 李扬韬
2021-08-14  1:59     ` Chao Yu
2021-08-14  2:08       ` 李扬韬
2021-08-16  1:54         ` Chao Yu
2021-08-13 18:06 ` kernel test robot
2021-08-14  8:52 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).