Skip to contentSkip to conversation

f2fs: convert S_IRUGO to 0444

PATCH In review Yangtao Li 3 participants 9 messages Aug 14, 2021 – Aug 20, 2021 F2FS file system

lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 f2fs: convert S_IRUGO to 0444

To fix:
WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using octal permissions '0444'.

---
 fs/f2fs/debug.c | 2 +-
 fs/f2fs/sysfs.c | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
fs/f2fs/debug.c +1 -1
index 833325038ef3..542c20e9ea0c 100644
@@ -611,7 +611,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 +4 -4
index 6642246206bd..204de4c2c818 100644
@@ -1213,13 +1213,13 @@ 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);
 	}
 	return 0;
Signature · 1 line
2.32.0
author
#1 lore raw

PATCH v6 1/1 f2fs: introduce /sys/fs/f2fs/<disk>/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 record all fsck stack history, I added F2FS_FSCK_STACK_TRACE configuration options and sysfs nodes. After opening the configuration options and enabling the node, it will start recording. The recorded stack information will not be clear, and we can get information form kernel log.

---
 Documentation/ABI/testing/sysfs-fs-f2fs |  7 ++++
 fs/f2fs/Kconfig                         | 10 ++++++
 fs/f2fs/f2fs.h                          | 45 +++++++++++++++++++++++++
 fs/f2fs/sysfs.c                         | 27 +++++++++++++++
 4 files changed, 89 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +7 -0
index ef4b9218ae1e..047c398093cf 100644
@@ -493,3 +493,10 @@ Contact:	"Chao Yu" <[email protected]>
 Description:	When ATGC is on, it controls age threshold to bypass GCing young
 		candidates whose age is not beyond the threshold, by default it was
 		initialized as 604800 seconds (equals to 7 days).
+
+What:		/sys/fs/f2fs/<disk>/fsck_stack
+Date:		August 2021
+Contact:	"Yangtao Li" <[email protected]>
+Description:	Controls to enable/disable fsck stack trace, you can get stack
+		information from kernel log. Note that the recorded stack information
+		will not be cleared.
fs/f2fs/Kconfig +10 -0
index 7669de7b49ce..f451e567e4a8 100644
@@ -135,3 +135,13 @@ config F2FS_FS_LZORLE
 	default y
 	help
 	  Support LZO-RLE compress algorithm, if unsure, say Y.
+
+config F2FS_FSCK_STACK_TRACE
+	bool "F2FS fsck stack information record"
+	depends on F2FS_FS
+	depends on STACKDEPOT
+	default y
+	help
+	 Support printing out fsck stack history. With this, you have to
+	 turn on "fsck_stack" sysfs node. Then you can get information
+	 from kernel log.
fs/f2fs/f2fs.h +45 -0

75 lines not on this page · raw message

fs/f2fs/sysfs.c +27 -0
index 204de4c2c818..4e786bb797e7 100644
@@ -306,6 +306,26 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
 	if (!strcmp(a->attr.name, "compr_new_inode"))
 		return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
 #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (!strcmp(a->attr.name, "fsck_stack")) {
+		unsigned long *entries;
+		unsigned int nr_entries;
+		unsigned int i;
+		int count;
+
+		count = sysfs_emit(buf, "%u\n", sbi->fsck_stack);
+		if (!sbi->fsck_stack)
+			return count;
+
+		for (i = 0; i < sbi->fsck_count; i++) {
+			nr_entries = stack_depot_fetch(sbi->fsck_stack_history[i], &entries);
+			if (!entries)
+				return count;
+			stack_trace_print(entries, nr_entries, 0);
+		}
+		return count;
+	}
+#endif
 
 	ui = (unsigned int *)(ptr + a->offset);
 
@@ -740,6 +760,10 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou
 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
 F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, fsck_stack, fsck_stack);
+#endif
+
 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
 static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +836,9 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(atgc_candidate_count),
 	ATTR_LIST(atgc_age_weight),
 	ATTR_LIST(atgc_age_threshold),
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	ATTR_LIST(fsck_stack),
+#endif
 	NULL,
 };
 ATTRIBUTE_GROUPS(f2fs);
Signature · 8 lines
2.32.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer
#2 lore raw

Re: [PATCH v6] f2fs: introduce /sys/fs/f2fs/<disk>/fsck_stack node

Quoted 23 lines · 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 record all fsck stack history, I added F2FS_FSCK_STACK_TRACE configuration options and sysfs nodes. After opening the configuration options and enabling the node, it will start recording. The recorded stack information will not be clear, and we can get information form kernel log.

---
  Documentation/ABI/testing/sysfs-fs-f2fs |  7 ++++
  fs/f2fs/Kconfig                         | 10 ++++++
  fs/f2fs/f2fs.h                          | 45 +++++++++++++++++++++++++
  fs/f2fs/sysfs.c                         | 27 +++++++++++++++
  4 files changed, 89 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +0 -0
index ef4b9218ae1e..047c398093cf 100644

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 502

Quoted 10 lines
Documentation/ABI/testing/sysfs-fs-f2fs +7 -0
@@ -493,3 +493,10 @@ Contact:	"Chao Yu" <[email protected]>
  Description:	When ATGC is on, it controls age threshold to bypass GCing young
  		candidates whose age is not beyond the threshold, by default it was
  		initialized as 604800 seconds (equals to 7 days).
+
+What:		/sys/fs/f2fs/<disk>/fsck_stack
+Date:		August 2021
+Contact:	"Yangtao Li" <[email protected]>
+Description:	Controls to enable/disable fsck stack trace, you can get stack
+		information from kernel log. Note that the recorded stack information
+		will not be cleared.

Again, please don't add this into sysfs.

fs/f2fs/Kconfig config F2FS_FS_LZORLE · line 139

Quoted 10 lines
fs/f2fs/Kconfig +2 -0
index 7669de7b49ce..f451e567e4a8 100644
@@ -135,3 +135,13 @@ config F2FS_FS_LZORLE
  	default y
  	help
  	  Support LZO-RLE compress algorithm, if unsure, say Y.
+
+config F2FS_FSCK_STACK_TRACE

I don't think we need another config to wrap this functionality, may be we can use F2FS_CHECK_FS instead.

Quoted 22 lines
fs/f2fs/Kconfig +8 -0
+	bool "F2FS fsck stack information record"
+	depends on F2FS_FS
+	depends on STACKDEPOT
+	default y
+	help
+	 Support printing out fsck stack history. With this, you have to
+	 turn on "fsck_stack" sysfs node. Then you can get information
+	 from kernel log.
fs/f2fs/f2fs.h +2 -0
index ee8eb33e2c25..b2d1d1a5a3fc 100644
@@ -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>

fs/f2fs/f2fs.h typedef u32 nid_t; · line 122

Quoted 4 lines
fs/f2fs/f2fs.h +1 -0
@@ -117,6 +119,8 @@ typedef u32 nid_t;
 
  #define COMPRESS_EXT_NUM		16
 
+#define FSCK_STACK_DEPTH		64

16?

fs/f2fs/f2fs.h struct f2fs_sb_info { · line 1758

Quoted 12 lines
fs/f2fs/f2fs.h +5 -0
+
  struct f2fs_mount_info {
  	unsigned int opt;
  	int write_io_size_bits;		/* Write IO size bits */
@@ -1748,6 +1752,11 @@ struct f2fs_sb_info {
  	unsigned int compress_watermark;	/* cache page watermark */
  	atomic_t compress_page_hit;		/* cache hit count */
  #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	depot_stack_handle_t *fsck_stack_history;
+	unsigned int fsck_count;
+	bool fsck_stack;

IMO, all bug_on()s are corner cases, and catching those stacks won't cost much, so we can just use CONFIG_XXX to enable/disable this feature.

Quoted 27 lines
fs/f2fs/f2fs.h +20 -0
+#endif
  };
 
  struct f2fs_private_dio {
@@ -1954,6 +1963,38 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
  	return sbi->node_inode->i_mapping;
  }
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+static void fsck_stack_trace(struct f2fs_sb_info *sbi)
+{
+	unsigned long entries[FSCK_STACK_DEPTH];
+	depot_stack_handle_t stack, *new;
+	unsigned int nr_entries;
+	int i;
+
+	if (!sbi->fsck_stack)
+		return;
+
+	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++)

fs/f2fs/f2fs.h static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) · line 1994

Quoted 10 lines
fs/f2fs/f2fs.h +10 -0
+		if (sbi->fsck_stack_history[i] == stack)
+			return;
+
+	new = krealloc(sbi->fsck_stack_history, (sbi->fsck_count + 1) *
+		       sizeof(*sbi->fsck_stack_history), GFP_KERNEL);
+	if (!new)
+		return;
+
+	sbi->fsck_stack_history = new;
+	sbi->fsck_stack_history[sbi->fsck_count++] = stack;

It will case memory leak after f2fs module exits.

Quoted 70 lines
fs/f2fs/f2fs.h +7 -0
+}
+#endif
+
  static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
  {
  	return test_bit(type, &sbi->s_flag);
@@ -1962,6 +2003,10 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
  static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  {
  	set_bit(type, &sbi->s_flag);
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (unlikely(type == SBI_NEED_FSCK))
+		fsck_stack_trace(sbi);
+#endif
  }
 
  static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
fs/f2fs/sysfs.c +27 -0
index 204de4c2c818..4e786bb797e7 100644
@@ -306,6 +306,26 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
  	if (!strcmp(a->attr.name, "compr_new_inode"))
  		return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
  #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (!strcmp(a->attr.name, "fsck_stack")) {
+		unsigned long *entries;
+		unsigned int nr_entries;
+		unsigned int i;
+		int count;
+
+		count = sysfs_emit(buf, "%u\n", sbi->fsck_stack);
+		if (!sbi->fsck_stack)
+			return count;
+
+		for (i = 0; i < sbi->fsck_count; i++) {
+			nr_entries = stack_depot_fetch(sbi->fsck_stack_history[i], &entries);
+			if (!entries)
+				return count;
+			stack_trace_print(entries, nr_entries, 0);
+		}
+		return count;
+	}
+#endif
 
  	ui = (unsigned int *)(ptr + a->offset);
 
@@ -740,6 +760,10 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou
  F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
  F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, fsck_stack, fsck_stack);
+#endif
+
  #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
  static struct attribute *f2fs_attrs[] = {
  	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +836,9 @@ static struct attribute *f2fs_attrs[] = {
  	ATTR_LIST(atgc_candidate_count),
  	ATTR_LIST(atgc_age_weight),
  	ATTR_LIST(atgc_age_threshold),
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	ATTR_LIST(fsck_stack),
+#endif
  	NULL,
  };
  ATTRIBUTE_GROUPS(f2fs);
author
#3 lore raw

Re:Re: [PATCH v6] f2fs: introduce /sys/fs/f2fs/<disk>/fsck_stack node

HI Chao,

Quoted 27 lines
Quoted 27 lines

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 record all fsck stack history, I added F2FS_FSCK_STACK_TRACE configuration options and sysfs nodes. After opening the configuration options and enabling the node, it will start recording. The recorded stack information will not be clear, and we can get information form kernel log.

---
  Documentation/ABI/testing/sysfs-fs-f2fs |  7 ++++
  fs/f2fs/Kconfig                         | 10 ++++++
  fs/f2fs/f2fs.h                          | 45 +++++++++++++++++++++++++
  fs/f2fs/sysfs.c                         | 27 +++++++++++++++
  4 files changed, 89 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +1 -0
index ef4b9218ae1e..047c398093cf 100644
@@ -493,3 +493,10 @@ Contact:	"Chao Yu" <[email protected]>
  Description:	When ATGC is on, it controls age threshold to bypass GCing young
  		candidates whose age is not beyond the threshold, by default it was
  		initialized as 604800 seconds (equals to 7 days).
+
Quoted 8 lines

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 502

Quoted 6 lines
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
+What:		/sys/fs/f2fs/<disk>/fsck_stack
+Date:		August 2021
+Contact:	"Yangtao Li" <[email protected]>
+Description:	Controls to enable/disable fsck stack trace, you can get stack
+		information from kernel log. Note that the recorded stack information
+		will not be cleared.

Again, please don't add this into sysfs.

I added this node, part of the idea is to trigger the export of stack information.
There is no information transmitted through sysfs here, but the record of the stack is switched on and off. If don't export this information through procfs and sysfs, is there a more appropriate way?

Quoted 14 lines

fs/f2fs/Kconfig config F2FS_FS_LZORLE · line 139

Quoted 11 lines
fs/f2fs/Kconfig +2 -0
index 7669de7b49ce..f451e567e4a8 100644
@@ -135,3 +135,13 @@ config F2FS_FS_LZORLE
  	default y
  	help
  	  Support LZO-RLE compress algorithm, if unsure, say Y.
+
+config F2FS_FSCK_STACK_TRACE

I don't think we need another config to wrap this functionality, may be we can use F2FS_CHECK_FS instead.

OK.

Quoted 24 lines
Quoted 24 lines
fs/f2fs/Kconfig +8 -0
+	bool "F2FS fsck stack information record"
+	depends on F2FS_FS
+	depends on STACKDEPOT
+	default y
+	help
+	 Support printing out fsck stack history. With this, you have to
+	 turn on "fsck_stack" sysfs node. Then you can get information
+	 from kernel log.
fs/f2fs/f2fs.h +2 -0
index ee8eb33e2c25..b2d1d1a5a3fc 100644
@@ -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>
@@ -117,6 +119,8 @@ typedef u32 nid_t;
 
Quoted 5 lines

fs/f2fs/f2fs.h typedef u32 nid_t; · line 122

Quoted 3 lines
fs/f2fs/f2fs.h +1 -0
  #define COMPRESS_EXT_NUM		16
 
+#define FSCK_STACK_DEPTH		64

16?

OK.

Quoted 16 lines

fs/f2fs/f2fs.h struct f2fs_sb_info { · line 1758

Quoted 13 lines
fs/f2fs/f2fs.h +5 -0
+
  struct f2fs_mount_info {
  	unsigned int opt;
  	int write_io_size_bits;		/* Write IO size bits */
@@ -1748,6 +1752,11 @@ struct f2fs_sb_info {
  	unsigned int compress_watermark;	/* cache page watermark */
  	atomic_t compress_page_hit;		/* cache hit count */
  #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	depot_stack_handle_t *fsck_stack_history;
+	unsigned int fsck_count;
+	bool fsck_stack;

IMO, all bug_on()s are corner cases, and catching those stacks won't cost much, so we can just use CONFIG_XXX to enable/disable this feature.

F2FS_CHECK_FS ?

Quoted 32 lines
Quoted 32 lines
fs/f2fs/f2fs.h +24 -0
+#endif
  };
 
  struct f2fs_private_dio {
@@ -1954,6 +1963,38 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
  	return sbi->node_inode->i_mapping;
  }
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+static void fsck_stack_trace(struct f2fs_sb_info *sbi)
+{
+	unsigned long entries[FSCK_STACK_DEPTH];
+	depot_stack_handle_t stack, *new;
+	unsigned int nr_entries;
+	int i;
+
+	if (!sbi->fsck_stack)
+		return;
+
+	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_history[i] == stack)
+			return;
+
+	new = krealloc(sbi->fsck_stack_history, (sbi->fsck_count + 1) *
Quoted 8 lines

fs/f2fs/f2fs.h static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) · line 1994

Quoted 6 lines
fs/f2fs/f2fs.h +6 -0
+		       sizeof(*sbi->fsck_stack_history), GFP_KERNEL);
+	if (!new)
+		return;
+
+	sbi->fsck_stack_history = new;
+	sbi->fsck_stack_history[sbi->fsck_count++] = stack;

It will case memory leak after f2fs module exits.

So let's enable this feature when f2fs is not a module and enable F2FS_CHECK_FS.

Quoted 63 lines
Quoted 63 lines
fs/f2fs/f2fs.h +7 -0
+}
+#endif
+
  static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
  {
  	return test_bit(type, &sbi->s_flag);
@@ -1962,6 +2003,10 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
  static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
  {
  	set_bit(type, &sbi->s_flag);
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (unlikely(type == SBI_NEED_FSCK))
+		fsck_stack_trace(sbi);
+#endif
  }
 
  static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
fs/f2fs/sysfs.c +24 -0
index 204de4c2c818..4e786bb797e7 100644
@@ -306,6 +306,26 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
  	if (!strcmp(a->attr.name, "compr_new_inode"))
  		return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
  #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (!strcmp(a->attr.name, "fsck_stack")) {
+		unsigned long *entries;
+		unsigned int nr_entries;
+		unsigned int i;
+		int count;
+
+		count = sysfs_emit(buf, "%u\n", sbi->fsck_stack);
+		if (!sbi->fsck_stack)
+			return count;
+
+		for (i = 0; i < sbi->fsck_count; i++) {
+			nr_entries = stack_depot_fetch(sbi->fsck_stack_history[i], &entries);
+			if (!entries)
+				return count;
+			stack_trace_print(entries, nr_entries, 0);
+		}
+		return count;
+	}
+#endif
 
  	ui = (unsigned int *)(ptr + a->offset);
 
@@ -740,6 +760,10 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou
  F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
  F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, fsck_stack, fsck_stack);
+#endif
+
  #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
  static struct attribute *f2fs_attrs[] = {
  	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +836,9 @@ static struct attribute *f2fs_attrs[] = {
  	ATTR_LIST(atgc_candidate_count),
  	ATTR_LIST(atgc_age_weight),
Quoted 8 lines

fs/f2fs/sysfs.c static struct attribute *f2fs_attrs[] = { · line 844

Quoted 8 lines
fs/f2fs/sysfs.c +3 -0
  	ATTR_LIST(atgc_age_threshold),
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	ATTR_LIST(fsck_stack),
+#endif
  	NULL,
  };
  ATTRIBUTE_GROUPS(f2fs);

Thx,
Yangtao

maintainer
#4 lore raw

Re: [PATCH v6] f2fs: introduce /sys/fs/f2fs/<disk>/fsck_stack node

Quoted 36 lines · 李扬韬

HI Chao,

Quoted 35 lines
Quoted 23 lines

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 record all fsck stack history, I added F2FS_FSCK_STACK_TRACE configuration options and sysfs nodes. After opening the configuration options and enabling the node, it will start recording. The recorded stack information will not be clear, and we can get information form kernel log.

---
   Documentation/ABI/testing/sysfs-fs-f2fs |  7 ++++
   fs/f2fs/Kconfig                         | 10 ++++++
   fs/f2fs/f2fs.h                          | 45 +++++++++++++++++++++++++
   fs/f2fs/sysfs.c                         | 27 +++++++++++++++
   4 files changed, 89 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +0 -0
index ef4b9218ae1e..047c398093cf 100644

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 502

Quoted 10 lines
Documentation/ABI/testing/sysfs-fs-f2fs +7 -0
@@ -493,3 +493,10 @@ Contact:	"Chao Yu" <[email protected]>
   Description:	When ATGC is on, it controls age threshold to bypass GCing young
   		candidates whose age is not beyond the threshold, by default it was
   		initialized as 604800 seconds (equals to 7 days).
+
+What:		/sys/fs/f2fs/<disk>/fsck_stack
+Date:		August 2021
+Contact:	"Yangtao Li" <[email protected]>
+Description:	Controls to enable/disable fsck stack trace, you can get stack
+		information from kernel log. Note that the recorded stack information
+		will not be cleared.

Again, please don't add this into sysfs.

Oh, I missed to check the details...

Quoted 4 lines

I added this node, part of the idea is to trigger the export of stack information.
There is no information transmitted through sysfs here, but the record of the stack is switched on and off. If don't export this information through procfs and sysfs, is there a more appropriate way?

Well, I doubt why we should export stack info via proc/sysfs node or sysfs switch.

Those info will always be needed to troubleshoot issues no matter in user or eng version of Android, can we just print them directly into kernel message... what I concern is we may lost the bug scene due to no one can help to trigger dmesg printing via sysfs.

Jaegeuk, thoughts?

Quoted 110 lines
Quoted 15 lines

fs/f2fs/Kconfig config F2FS_FS_LZORLE · line 139

Quoted 12 lines
fs/f2fs/Kconfig +2 -0
index 7669de7b49ce..f451e567e4a8 100644
@@ -135,3 +135,13 @@ config F2FS_FS_LZORLE
   	default y
   	help
   	  Support LZO-RLE compress algorithm, if unsure, say Y.
+
+config F2FS_FSCK_STACK_TRACE

I don't think we need another config to wrap this functionality, may be we can use F2FS_CHECK_FS instead.

OK.

Quoted 24 lines
Quoted 24 lines
fs/f2fs/Kconfig +8 -0
+	bool "F2FS fsck stack information record"
+	depends on F2FS_FS
+	depends on STACKDEPOT
+	default y
+	help
+	 Support printing out fsck stack history. With this, you have to
+	 turn on "fsck_stack" sysfs node. Then you can get information
+	 from kernel log.
fs/f2fs/f2fs.h +2 -0
index ee8eb33e2c25..b2d1d1a5a3fc 100644
@@ -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>
@@ -117,6 +119,8 @@ typedef u32 nid_t;
 
Quoted 5 lines

fs/f2fs/f2fs.h typedef u32 nid_t; · line 122

Quoted 3 lines
fs/f2fs/f2fs.h +1 -0
   #define COMPRESS_EXT_NUM		16
 
+#define FSCK_STACK_DEPTH		64

16?

OK.

Quoted 16 lines

fs/f2fs/f2fs.h struct f2fs_sb_info { · line 1758

Quoted 13 lines
fs/f2fs/f2fs.h +5 -0
+
   struct f2fs_mount_info {
   	unsigned int opt;
   	int write_io_size_bits;		/* Write IO size bits */
@@ -1748,6 +1752,11 @@ struct f2fs_sb_info {
   	unsigned int compress_watermark;	/* cache page watermark */
   	atomic_t compress_page_hit;		/* cache hit count */
   #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	depot_stack_handle_t *fsck_stack_history;
+	unsigned int fsck_count;
+	bool fsck_stack;

IMO, all bug_on()s are corner cases, and catching those stacks won't cost much, so we can just use CONFIG_XXX to enable/disable this feature.

F2FS_CHECK_FS ?

Quoted 32 lines
Quoted 32 lines
fs/f2fs/f2fs.h +24 -0
+#endif
   };
 
   struct f2fs_private_dio {
@@ -1954,6 +1963,38 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
   	return sbi->node_inode->i_mapping;
   }
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+static void fsck_stack_trace(struct f2fs_sb_info *sbi)
+{
+	unsigned long entries[FSCK_STACK_DEPTH];
+	depot_stack_handle_t stack, *new;
+	unsigned int nr_entries;
+	int i;
+
+	if (!sbi->fsck_stack)
+		return;
+
+	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_history[i] == stack)
+			return;
+
+	new = krealloc(sbi->fsck_stack_history, (sbi->fsck_count + 1) *
Quoted 8 lines

fs/f2fs/f2fs.h static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) · line 1994

Quoted 6 lines
fs/f2fs/f2fs.h +6 -0
+		       sizeof(*sbi->fsck_stack_history), GFP_KERNEL);
+	if (!new)
+		return;
+
+	sbi->fsck_stack_history = new;
+	sbi->fsck_stack_history[sbi->fsck_count++] = stack;

It will case memory leak after f2fs module exits.

Quoted 1 line

So let's enable this feature when f2fs is not a module and enable F2FS_CHECK_FS.

I mean it needs to free .fsck_stack_history during umount().

Thanks,

Quoted 76 lines
Quoted 64 lines
Quoted 64 lines
fs/f2fs/f2fs.h +7 -0
+}
+#endif
+
   static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
   {
   	return test_bit(type, &sbi->s_flag);
@@ -1962,6 +2003,10 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
   static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
   {
   	set_bit(type, &sbi->s_flag);
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (unlikely(type == SBI_NEED_FSCK))
+		fsck_stack_trace(sbi);
+#endif
   }
 
   static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
fs/f2fs/sysfs.c +24 -0
index 204de4c2c818..4e786bb797e7 100644
@@ -306,6 +306,26 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
   	if (!strcmp(a->attr.name, "compr_new_inode"))
   		return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
   #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (!strcmp(a->attr.name, "fsck_stack")) {
+		unsigned long *entries;
+		unsigned int nr_entries;
+		unsigned int i;
+		int count;
+
+		count = sysfs_emit(buf, "%u\n", sbi->fsck_stack);
+		if (!sbi->fsck_stack)
+			return count;
+
+		for (i = 0; i < sbi->fsck_count; i++) {
+			nr_entries = stack_depot_fetch(sbi->fsck_stack_history[i], &entries);
+			if (!entries)
+				return count;
+			stack_trace_print(entries, nr_entries, 0);
+		}
+		return count;
+	}
+#endif
 
   	ui = (unsigned int *)(ptr + a->offset);
 
@@ -740,6 +760,10 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou
   F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
   F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, fsck_stack, fsck_stack);
+#endif
+
   #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
   static struct attribute *f2fs_attrs[] = {
   	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +836,9 @@ static struct attribute *f2fs_attrs[] = {
   	ATTR_LIST(atgc_candidate_count),
   	ATTR_LIST(atgc_age_weight),
Quoted 8 lines

fs/f2fs/sysfs.c static struct attribute *f2fs_attrs[] = { · line 844

Quoted 8 lines
fs/f2fs/sysfs.c +3 -0
   	ATTR_LIST(atgc_age_threshold),
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	ATTR_LIST(fsck_stack),
+#endif
   	NULL,
   };
   ATTRIBUTE_GROUPS(f2fs);

Thx,
Yangtao

author
#5 lore raw

Re:Re: [PATCH v6] f2fs: introduce /sys/fs/f2fs/<disk>/fsck_stack node

Quoted 45 lines
Quoted 37 lines

HI Chao,

Quoted 35 lines
Quoted 23 lines

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 record all fsck stack history, I added F2FS_FSCK_STACK_TRACE configuration options and sysfs nodes. After opening the configuration options and enabling the node, it will start recording. The recorded stack information will not be clear, and we can get information form kernel log.

---
   Documentation/ABI/testing/sysfs-fs-f2fs |  7 ++++
   fs/f2fs/Kconfig                         | 10 ++++++
   fs/f2fs/f2fs.h                          | 45 +++++++++++++++++++++++++
   fs/f2fs/sysfs.c                         | 27 +++++++++++++++
   4 files changed, 89 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +0 -0
index ef4b9218ae1e..047c398093cf 100644

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 502

Quoted 10 lines
Documentation/ABI/testing/sysfs-fs-f2fs +7 -0
@@ -493,3 +493,10 @@ Contact:	"Chao Yu" <[email protected]>
   Description:	When ATGC is on, it controls age threshold to bypass GCing young
   		candidates whose age is not beyond the threshold, by default it was
   		initialized as 604800 seconds (equals to 7 days).
+
+What:		/sys/fs/f2fs/<disk>/fsck_stack
+Date:		August 2021
+Contact:	"Yangtao Li" <[email protected]>
+Description:	Controls to enable/disable fsck stack trace, you can get stack
+		information from kernel log. Note that the recorded stack information
+		will not be cleared.

Again, please don't add this into sysfs.

Oh, I missed to check the details...

Quoted 4 lines

I added this node, part of the idea is to trigger the export of stack information.
There is no information transmitted through sysfs here, but the record of the stack is switched on and off. If don't export this information through procfs and sysfs, is there a more appropriate way?

Quoted 8 lines

Well, I doubt why we should export stack info via proc/sysfs node or

sysfs switch.>
Those info will always be needed to troubleshoot issues no matter in user or eng version of Android, can we just print them directly into kernel message... what I concern is we may lost the bug scene due to

no one can help to trigger dmesg printing via sysfs.

We can collect these stacks in user space by monitoring whether the sbi status contains fsck.

In addition, I noticed that there are some places, f2fs_bug_on is set in some places, and set_sbi_flag(sbi, SBI_NEED_FSCK) is used in a small part. Why not change everything to f2fs_bug_on? In this way, when CONFIG_F2FS_CHECK_FS is turned on, it will actively panic, allowing us to discover problems in time. If follow the above approach, it is better to have a separate F2FS_FSCK_STACK_TRACE configuration?

Thx,>

Quoted 194 lines

Jaegeuk, thoughts?

Quoted 110 lines
Quoted 15 lines

fs/f2fs/Kconfig config F2FS_FS_LZORLE · line 139

Quoted 12 lines
fs/f2fs/Kconfig +2 -0
index 7669de7b49ce..f451e567e4a8 100644
@@ -135,3 +135,13 @@ config F2FS_FS_LZORLE
   	default y
   	help
   	  Support LZO-RLE compress algorithm, if unsure, say Y.
+
+config F2FS_FSCK_STACK_TRACE

I don't think we need another config to wrap this functionality, may be we can use F2FS_CHECK_FS instead.

OK.

Quoted 24 lines
Quoted 24 lines
fs/f2fs/Kconfig +8 -0
+	bool "F2FS fsck stack information record"
+	depends on F2FS_FS
+	depends on STACKDEPOT
+	default y
+	help
+	 Support printing out fsck stack history. With this, you have to
+	 turn on "fsck_stack" sysfs node. Then you can get information
+	 from kernel log.
fs/f2fs/f2fs.h +2 -0
index ee8eb33e2c25..b2d1d1a5a3fc 100644
@@ -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>
@@ -117,6 +119,8 @@ typedef u32 nid_t;
 
Quoted 5 lines

fs/f2fs/f2fs.h typedef u32 nid_t; · line 122

Quoted 3 lines
fs/f2fs/f2fs.h +1 -0
   #define COMPRESS_EXT_NUM		16
 
+#define FSCK_STACK_DEPTH		64

16?

OK.

Quoted 16 lines

fs/f2fs/f2fs.h struct f2fs_sb_info { · line 1758

Quoted 13 lines
fs/f2fs/f2fs.h +5 -0
+
   struct f2fs_mount_info {
   	unsigned int opt;
   	int write_io_size_bits;		/* Write IO size bits */
@@ -1748,6 +1752,11 @@ struct f2fs_sb_info {
   	unsigned int compress_watermark;	/* cache page watermark */
   	atomic_t compress_page_hit;		/* cache hit count */
   #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	depot_stack_handle_t *fsck_stack_history;
+	unsigned int fsck_count;
+	bool fsck_stack;

IMO, all bug_on()s are corner cases, and catching those stacks won't cost much, so we can just use CONFIG_XXX to enable/disable this feature.

F2FS_CHECK_FS ?

Quoted 32 lines
Quoted 32 lines
fs/f2fs/f2fs.h +24 -0
+#endif
   };
 
   struct f2fs_private_dio {
@@ -1954,6 +1963,38 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
   	return sbi->node_inode->i_mapping;
   }
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+static void fsck_stack_trace(struct f2fs_sb_info *sbi)
+{
+	unsigned long entries[FSCK_STACK_DEPTH];
+	depot_stack_handle_t stack, *new;
+	unsigned int nr_entries;
+	int i;
+
+	if (!sbi->fsck_stack)
+		return;
+
+	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_history[i] == stack)
+			return;
+
+	new = krealloc(sbi->fsck_stack_history, (sbi->fsck_count + 1) *
Quoted 8 lines

fs/f2fs/f2fs.h static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) · line 1994

Quoted 6 lines
fs/f2fs/f2fs.h +6 -0
+		       sizeof(*sbi->fsck_stack_history), GFP_KERNEL);
+	if (!new)
+		return;
+
+	sbi->fsck_stack_history = new;
+	sbi->fsck_stack_history[sbi->fsck_count++] = stack;

It will case memory leak after f2fs module exits.

Quoted 1 line

So let's enable this feature when f2fs is not a module and enable F2FS_CHECK_FS.

I mean it needs to free .fsck_stack_history during umount().

Thanks,

Quoted 76 lines
Quoted 64 lines
Quoted 64 lines
fs/f2fs/f2fs.h +7 -0
+}
+#endif
+
   static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
   {
   	return test_bit(type, &sbi->s_flag);
@@ -1962,6 +2003,10 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
   static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
   {
   	set_bit(type, &sbi->s_flag);
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (unlikely(type == SBI_NEED_FSCK))
+		fsck_stack_trace(sbi);
+#endif
   }
 
   static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
fs/f2fs/sysfs.c +24 -0
index 204de4c2c818..4e786bb797e7 100644
@@ -306,6 +306,26 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
   	if (!strcmp(a->attr.name, "compr_new_inode"))
   		return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
   #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (!strcmp(a->attr.name, "fsck_stack")) {
+		unsigned long *entries;
+		unsigned int nr_entries;
+		unsigned int i;
+		int count;
+
+		count = sysfs_emit(buf, "%u\n", sbi->fsck_stack);
+		if (!sbi->fsck_stack)
+			return count;
+
+		for (i = 0; i < sbi->fsck_count; i++) {
+			nr_entries = stack_depot_fetch(sbi->fsck_stack_history[i], &entries);
+			if (!entries)
+				return count;
+			stack_trace_print(entries, nr_entries, 0);
+		}
+		return count;
+	}
+#endif
 
   	ui = (unsigned int *)(ptr + a->offset);
 
@@ -740,6 +760,10 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou
   F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
   F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
 
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, fsck_stack, fsck_stack);
+#endif
+
   #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
   static struct attribute *f2fs_attrs[] = {
   	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +836,9 @@ static struct attribute *f2fs_attrs[] = {
   	ATTR_LIST(atgc_candidate_count),
   	ATTR_LIST(atgc_age_weight),
Quoted 8 lines

fs/f2fs/sysfs.c static struct attribute *f2fs_attrs[] = { · line 844

Quoted 8 lines
fs/f2fs/sysfs.c +3 -0
   	ATTR_LIST(atgc_age_threshold),
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	ATTR_LIST(fsck_stack),
+#endif
   	NULL,
   };
   ATTRIBUTE_GROUPS(f2fs);

Thx,
Yangtao

maintainer
#6 lore raw

Re: [PATCH v6] f2fs: introduce /sys/fs/f2fs/<disk>/fsck_stack node

In reply to Chao Yu
Quoted 48 lines · Chao Yu
Quoted 36 lines · 李扬韬

HI Chao,

Quoted 35 lines
Quoted 23 lines

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 record all fsck stack history, I added F2FS_FSCK_STACK_TRACE configuration options and sysfs nodes. After opening the configuration options and enabling the node, it will start recording. The recorded stack information will not be clear, and we can get information form kernel log.

---
   Documentation/ABI/testing/sysfs-fs-f2fs |  7 ++++
   fs/f2fs/Kconfig                         | 10 ++++++
   fs/f2fs/f2fs.h                          | 45 +++++++++++++++++++++++++
   fs/f2fs/sysfs.c                         | 27 +++++++++++++++
   4 files changed, 89 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +0 -0
index ef4b9218ae1e..047c398093cf 100644

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 502

Quoted 10 lines
Documentation/ABI/testing/sysfs-fs-f2fs +7 -0
@@ -493,3 +493,10 @@ Contact:	"Chao Yu" <[email protected]>
   Description:	When ATGC is on, it controls age threshold to bypass GCing young
   		candidates whose age is not beyond the threshold, by default it was
   		initialized as 604800 seconds (equals to 7 days).
+
+What:		/sys/fs/f2fs/<disk>/fsck_stack
+Date:		August 2021
+Contact:	"Yangtao Li" <[email protected]>
+Description:	Controls to enable/disable fsck stack trace, you can get stack
+		information from kernel log. Note that the recorded stack information
+		will not be cleared.

Again, please don't add this into sysfs.

Oh, I missed to check the details...

Quoted 4 lines

I added this node, part of the idea is to trigger the export of stack information.
There is no information transmitted through sysfs here, but the record of the stack is switched on and off. If don't export this information through procfs and sysfs, is there a more appropriate way?

Well, I doubt why we should export stack info via proc/sysfs node or sysfs switch.

Quoted 6 lines

Those info will always be needed to troubleshoot issues no matter in user or eng version of Android, can we just print them directly into kernel message... what I concern is we may lost the bug scene due to no one can help to trigger dmesg printing via sysfs.

Jaegeuk, thoughts?

I thought that it'd be good to have an error history in debufs. For example, we can have a set of reasons defined as enum and put the error counts per SBI_NEED_FSCK along with error number like ENOMEM, EIO, and so on. The goal would be to understand whether we're getting SBI_NEED_FSCK which triggers fsck in practical.

Quoted 106 lines
Quoted 106 lines
Quoted 16 lines

fs/f2fs/Kconfig config F2FS_FS_LZORLE · line 139

Quoted 13 lines
fs/f2fs/Kconfig +2 -0
index 7669de7b49ce..f451e567e4a8 100644
@@ -135,3 +135,13 @@ config F2FS_FS_LZORLE
   	default y
   	help
   	  Support LZO-RLE compress algorithm, if unsure, say Y.
+
+config F2FS_FSCK_STACK_TRACE

I don't think we need another config to wrap this functionality, may be we can use F2FS_CHECK_FS instead.

OK.

Quoted 18 lines
Quoted 18 lines
fs/f2fs/Kconfig +8 -0
+	bool "F2FS fsck stack information record"
+	depends on F2FS_FS
+	depends on STACKDEPOT
+	default y
+	help
+	 Support printing out fsck stack history. With this, you have to
+	 turn on "fsck_stack" sysfs node. Then you can get information
+	 from kernel log.
fs/f2fs/f2fs.h +1 -0
index ee8eb33e2c25..b2d1d1a5a3fc 100644
@@ -24,6 +24,8 @@
   #include <linux/quotaops.h>
   #include <linux/part_stat.h>
   #include <crypto/hash.h>
+#include <linux/stackdepot.h>
Quoted 8 lines

fs/f2fs/f2fs.h typedef u32 nid_t; · line 120

Quoted 6 lines
fs/f2fs/f2fs.h +2 -0
+#include <linux/stacktrace.h>
   #include <linux/fscrypt.h>
   #include <linux/fsverity.h>
@@ -117,6 +119,8 @@ typedef u32 nid_t;
   #define COMPRESS_EXT_NUM		16
+#define FSCK_STACK_DEPTH		64

16?

OK.

Quoted 16 lines

fs/f2fs/f2fs.h struct f2fs_sb_info { · line 1758

Quoted 13 lines
fs/f2fs/f2fs.h +5 -0
+
   struct f2fs_mount_info {
   	unsigned int opt;
   	int write_io_size_bits;		/* Write IO size bits */
@@ -1748,6 +1752,11 @@ struct f2fs_sb_info {
   	unsigned int compress_watermark;	/* cache page watermark */
   	atomic_t compress_page_hit;		/* cache hit count */
   #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	depot_stack_handle_t *fsck_stack_history;
+	unsigned int fsck_count;
+	bool fsck_stack;

IMO, all bug_on()s are corner cases, and catching those stacks won't cost much, so we can just use CONFIG_XXX to enable/disable this feature.

F2FS_CHECK_FS ?

Quoted 38 lines
Quoted 26 lines
fs/f2fs/f2fs.h +20 -0
+#endif
   };
   struct f2fs_private_dio {
@@ -1954,6 +1963,38 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
   	return sbi->node_inode->i_mapping;
   }
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+static void fsck_stack_trace(struct f2fs_sb_info *sbi)
+{
+	unsigned long entries[FSCK_STACK_DEPTH];
+	depot_stack_handle_t stack, *new;
+	unsigned int nr_entries;
+	int i;
+
+	if (!sbi->fsck_stack)
+		return;
+
+	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++)

fs/f2fs/f2fs.h static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) · line 1993

Quoted 10 lines
fs/f2fs/f2fs.h +10 -0
+		if (sbi->fsck_stack_history[i] == stack)
+			return;
+
+	new = krealloc(sbi->fsck_stack_history, (sbi->fsck_count + 1) *
+		       sizeof(*sbi->fsck_stack_history), GFP_KERNEL);
+	if (!new)
+		return;
+
+	sbi->fsck_stack_history = new;
+	sbi->fsck_stack_history[sbi->fsck_count++] = stack;

It will case memory leak after f2fs module exits.

Quoted 78 lines
Quoted 1 line

So let's enable this feature when f2fs is not a module and enable F2FS_CHECK_FS.

I mean it needs to free .fsck_stack_history during umount().

Thanks,

Quoted 72 lines
Quoted 60 lines
Quoted 60 lines
fs/f2fs/f2fs.h +7 -0
+}
+#endif
+
   static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
   {
   	return test_bit(type, &sbi->s_flag);
@@ -1962,6 +2003,10 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
   static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
   {
   	set_bit(type, &sbi->s_flag);
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (unlikely(type == SBI_NEED_FSCK))
+		fsck_stack_trace(sbi);
+#endif
   }
   static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
fs/f2fs/sysfs.c +24 -0
index 204de4c2c818..4e786bb797e7 100644
@@ -306,6 +306,26 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
   	if (!strcmp(a->attr.name, "compr_new_inode"))
   		return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
   #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (!strcmp(a->attr.name, "fsck_stack")) {
+		unsigned long *entries;
+		unsigned int nr_entries;
+		unsigned int i;
+		int count;
+
+		count = sysfs_emit(buf, "%u\n", sbi->fsck_stack);
+		if (!sbi->fsck_stack)
+			return count;
+
+		for (i = 0; i < sbi->fsck_count; i++) {
+			nr_entries = stack_depot_fetch(sbi->fsck_stack_history[i], &entries);
+			if (!entries)
+				return count;
+			stack_trace_print(entries, nr_entries, 0);
+		}
+		return count;
+	}
+#endif
   	ui = (unsigned int *)(ptr + a->offset);
@@ -740,6 +760,10 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou
   F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
   F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, fsck_stack, fsck_stack);
+#endif
+
   #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
   static struct attribute *f2fs_attrs[] = {
   	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +836,9 @@ static struct attribute *f2fs_attrs[] = {
   	ATTR_LIST(atgc_candidate_count),
   	ATTR_LIST(atgc_age_weight),
Quoted 8 lines

fs/f2fs/sysfs.c static struct attribute *f2fs_attrs[] = { · line 844

Quoted 8 lines
fs/f2fs/sysfs.c +3 -0
   	ATTR_LIST(atgc_age_threshold),
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	ATTR_LIST(fsck_stack),
+#endif
   	NULL,
   };
   ATTRIBUTE_GROUPS(f2fs);

Thx,
Yangtao

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#7 lore raw

Re: [PATCH v6] f2fs: introduce /sys/fs/f2fs/<disk>/fsck_stack node

Quoted 54 lines · Jaegeuk Kim
Quoted 53 lines · Chao Yu
Quoted 36 lines · 李扬韬

HI Chao,

Quoted 35 lines
Quoted 23 lines

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 record all fsck stack history, I added F2FS_FSCK_STACK_TRACE configuration options and sysfs nodes. After opening the configuration options and enabling the node, it will start recording. The recorded stack information will not be clear, and we can get information form kernel log.

---
    Documentation/ABI/testing/sysfs-fs-f2fs |  7 ++++
    fs/f2fs/Kconfig                         | 10 ++++++
    fs/f2fs/f2fs.h                          | 45 +++++++++++++++++++++++++
    fs/f2fs/sysfs.c                         | 27 +++++++++++++++
    4 files changed, 89 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +0 -0
index ef4b9218ae1e..047c398093cf 100644

Documentation/ABI/testing/sysfs-fs-f2fs Contact: "Chao Yu" <[email protected]> · line 502

Quoted 10 lines
Documentation/ABI/testing/sysfs-fs-f2fs +7 -0
@@ -493,3 +493,10 @@ Contact:	"Chao Yu" <[email protected]>
    Description:	When ATGC is on, it controls age threshold to bypass GCing young
    		candidates whose age is not beyond the threshold, by default it was
    		initialized as 604800 seconds (equals to 7 days).
+
+What:		/sys/fs/f2fs/<disk>/fsck_stack
+Date:		August 2021
+Contact:	"Yangtao Li" <[email protected]>
+Description:	Controls to enable/disable fsck stack trace, you can get stack
+		information from kernel log. Note that the recorded stack information
+		will not be cleared.

Again, please don't add this into sysfs.

Oh, I missed to check the details...

Quoted 4 lines

I added this node, part of the idea is to trigger the export of stack information.
There is no information transmitted through sysfs here, but the record of the stack is switched on and off. If don't export this information through procfs and sysfs, is there a more appropriate way?

Well, I doubt why we should export stack info via proc/sysfs node or sysfs switch.

Those info will always be needed to troubleshoot issues no matter in user or eng version of Android, can we just print them directly into kernel message... what I concern is we may lost the bug scene due to no one can help to trigger dmesg printing via sysfs.

Quoted 7 lines
Quoted 1 line

Jaegeuk, thoughts?

I thought that it'd be good to have an error history in debufs. For example, we can have a set of reasons defined as enum and put the error counts per SBI_NEED_FSCK along with error number like ENOMEM, EIO, and so on. The goal would be to understand whether we're getting SBI_NEED_FSCK which triggers fsck in practical.

In most of the cases we set SBI_NEED_FSCK, the reason is in-mem or on-disk data becomes inconsistent, so it looks it's not easy to distinguish the reason based on error number like ENOMEM, EIO... if I get your point correctly here.

Thanks,

Quoted 185 lines
Quoted 185 lines
Quoted 107 lines
Quoted 4 lines
Quoted 13 lines

fs/f2fs/Kconfig config F2FS_FS_LZORLE · line 139

Quoted 10 lines
fs/f2fs/Kconfig +2 -0
index 7669de7b49ce..f451e567e4a8 100644
@@ -135,3 +135,13 @@ config F2FS_FS_LZORLE
    	default y
    	help
    	  Support LZO-RLE compress algorithm, if unsure, say Y.
+
+config F2FS_FSCK_STACK_TRACE

I don't think we need another config to wrap this functionality, may be we can use F2FS_CHECK_FS instead.

OK.

Quoted 18 lines
Quoted 18 lines
fs/f2fs/Kconfig +8 -0
+	bool "F2FS fsck stack information record"
+	depends on F2FS_FS
+	depends on STACKDEPOT
+	default y
+	help
+	 Support printing out fsck stack history. With this, you have to
+	 turn on "fsck_stack" sysfs node. Then you can get information
+	 from kernel log.
fs/f2fs/f2fs.h +1 -0
index ee8eb33e2c25..b2d1d1a5a3fc 100644
@@ -24,6 +24,8 @@
    #include <linux/quotaops.h>
    #include <linux/part_stat.h>
    #include <crypto/hash.h>
+#include <linux/stackdepot.h>
Quoted 8 lines

fs/f2fs/f2fs.h typedef u32 nid_t; · line 120

Quoted 6 lines
fs/f2fs/f2fs.h +2 -0
+#include <linux/stacktrace.h>
    #include <linux/fscrypt.h>
    #include <linux/fsverity.h>
@@ -117,6 +119,8 @@ typedef u32 nid_t;
    #define COMPRESS_EXT_NUM		16
+#define FSCK_STACK_DEPTH		64

16?

OK.

Quoted 16 lines

fs/f2fs/f2fs.h struct f2fs_sb_info { · line 1758

Quoted 13 lines
fs/f2fs/f2fs.h +5 -0
+
    struct f2fs_mount_info {
    	unsigned int opt;
    	int write_io_size_bits;		/* Write IO size bits */
@@ -1748,6 +1752,11 @@ struct f2fs_sb_info {
    	unsigned int compress_watermark;	/* cache page watermark */
    	atomic_t compress_page_hit;		/* cache hit count */
    #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	depot_stack_handle_t *fsck_stack_history;
+	unsigned int fsck_count;
+	bool fsck_stack;

IMO, all bug_on()s are corner cases, and catching those stacks won't cost much, so we can just use CONFIG_XXX to enable/disable this feature.

F2FS_CHECK_FS ?

Quoted 30 lines
Quoted 30 lines
fs/f2fs/f2fs.h +24 -0
+#endif
    };
    struct f2fs_private_dio {
@@ -1954,6 +1963,38 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
    	return sbi->node_inode->i_mapping;
    }
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+static void fsck_stack_trace(struct f2fs_sb_info *sbi)
+{
+	unsigned long entries[FSCK_STACK_DEPTH];
+	depot_stack_handle_t stack, *new;
+	unsigned int nr_entries;
+	int i;
+
+	if (!sbi->fsck_stack)
+		return;
+
+	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_history[i] == stack)
+			return;
+
+	new = krealloc(sbi->fsck_stack_history, (sbi->fsck_count + 1) *
Quoted 8 lines

fs/f2fs/f2fs.h static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) · line 1994

Quoted 6 lines
fs/f2fs/f2fs.h +6 -0
+		       sizeof(*sbi->fsck_stack_history), GFP_KERNEL);
+	if (!new)
+		return;
+
+	sbi->fsck_stack_history = new;
+	sbi->fsck_stack_history[sbi->fsck_count++] = stack;

It will case memory leak after f2fs module exits.

Quoted 1 line

So let's enable this feature when f2fs is not a module and enable F2FS_CHECK_FS.

I mean it needs to free .fsck_stack_history during umount().

Thanks,

Quoted 72 lines
Quoted 60 lines
Quoted 60 lines
fs/f2fs/f2fs.h +7 -0
+}
+#endif
+
    static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
    {
    	return test_bit(type, &sbi->s_flag);
@@ -1962,6 +2003,10 @@ static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
    static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
    {
    	set_bit(type, &sbi->s_flag);
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (unlikely(type == SBI_NEED_FSCK))
+		fsck_stack_trace(sbi);
+#endif
    }
    static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
fs/f2fs/sysfs.c +24 -0
index 204de4c2c818..4e786bb797e7 100644
@@ -306,6 +306,26 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
    	if (!strcmp(a->attr.name, "compr_new_inode"))
    		return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
    #endif
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	if (!strcmp(a->attr.name, "fsck_stack")) {
+		unsigned long *entries;
+		unsigned int nr_entries;
+		unsigned int i;
+		int count;
+
+		count = sysfs_emit(buf, "%u\n", sbi->fsck_stack);
+		if (!sbi->fsck_stack)
+			return count;
+
+		for (i = 0; i < sbi->fsck_count; i++) {
+			nr_entries = stack_depot_fetch(sbi->fsck_stack_history[i], &entries);
+			if (!entries)
+				return count;
+			stack_trace_print(entries, nr_entries, 0);
+		}
+		return count;
+	}
+#endif
    	ui = (unsigned int *)(ptr + a->offset);
@@ -740,6 +760,10 @@ F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_candidate_count, max_candidate_cou
    F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_weight, age_weight);
    F2FS_RW_ATTR(ATGC_INFO, atgc_management, atgc_age_threshold, age_threshold);
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, fsck_stack, fsck_stack);
+#endif
+
    #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
    static struct attribute *f2fs_attrs[] = {
    	ATTR_LIST(gc_urgent_sleep_time),
@@ -812,6 +836,9 @@ static struct attribute *f2fs_attrs[] = {
    	ATTR_LIST(atgc_candidate_count),
    	ATTR_LIST(atgc_age_weight),
Quoted 8 lines

fs/f2fs/sysfs.c static struct attribute *f2fs_attrs[] = { · line 844

Quoted 8 lines
fs/f2fs/sysfs.c +3 -0
    	ATTR_LIST(atgc_age_threshold),
+#ifdef CONFIG_F2FS_FSCK_STACK_TRACE
+	ATTR_LIST(fsck_stack),
+#endif
    	NULL,
    };
    ATTRIBUTE_GROUPS(f2fs);

Thx,
Yangtao