Skip to contentSkip to conversation

ocfs2: add locking filter debugfs file

PATCH Superseded Gang He 2 participants 4 messages Apr 29, 2019 – May 5, 2019 OCFS2

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Gang He

author
#0 lore raw

PATCH v2 2/2 ocfs2: add locking filter debugfs file

Add locking filter debugfs file, which is used to filter lock resources dump from locking_state debugfs file.
We use d_filter_secs field to filter lock resources dump, the default d_filter_secs(0) value filters nothing, otherwise, only dump the last N seconds active lock resources. This enhancement can avoid dumping lots of old records. The d_filter_secs value can be changed via locking_filter file.

Compared with v1, the main change is to add CONFIG_OCFS2_FS_STATS macro definition judgment.

---
 fs/ocfs2/dlmglue.c | 38 ++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/ocfs2.h   |  2 ++
 2 files changed, 40 insertions(+)
fs/ocfs2/dlmglue.c +38 -0
index dccf4136f8c1..554d37d52510 100644
@@ -3006,6 +3006,8 @@ struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
 	kref_init(&dlm_debug->d_refcnt);
 	INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
 	dlm_debug->d_locking_state = NULL;
+	dlm_debug->d_locking_filter = NULL;
+	dlm_debug->d_filter_secs = 0;
 out:
 	return dlm_debug;
 }
@@ -3104,11 +3106,33 @@ static int ocfs2_dlm_seq_show(struct seq_file *m, void *v)
 {
 	int i;
 	char *lvb;
+	u32 now, last = 0;
 	struct ocfs2_lock_res *lockres = v;
+	struct ocfs2_dlm_debug *dlm_debug =
+			((struct ocfs2_dlm_seq_priv *)m->private)->p_dlm_debug;
 
 	if (!lockres)
 		return -EINVAL;
 
+	if (dlm_debug->d_filter_secs) {
+		now = ktime_to_timespec(ktime_get()).tv_sec;
+#ifdef CONFIG_OCFS2_FS_STATS
+		if (lockres->l_lock_prmode.ls_last >
+		    lockres->l_lock_exmode.ls_last)
+			last = lockres->l_lock_prmode.ls_last;
+		else
+			last = lockres->l_lock_exmode.ls_last;
+#endif
+		/*
+		 * Use d_filter_secs field to filter lock resources dump,
+		 * the default d_filter_secs(0) value filters nothing,
+		 * otherwise, only dump the last N seconds active lock
+		 * resources.
+		 */
+		if ((now - last) > dlm_debug->d_filter_secs)
+			return 0;
+	}
+
 	seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
 
 	if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
@@ -3258,6 +3282,19 @@ static int ocfs2_dlm_init_debug(struct ocfs2_super *osb)
 		goto out;
 	}
 
+	dlm_debug->d_locking_filter = debugfs_create_u32("locking_filter",
+						0600,
+						osb->osb_debug_root,
+						&dlm_debug->d_filter_secs);
+	if (!dlm_debug->d_locking_filter) {
+		ret = -EINVAL;
+		mlog(ML_ERROR,
+		     "Unable to create locking filter debugfs file.\n");
+		debugfs_remove(dlm_debug->d_locking_state);
+		dlm_debug->d_locking_state = NULL;
+		goto out;
+	}
+
 	ocfs2_get_dlm_debug(dlm_debug);
 out:
 	return ret;
@@ -3269,6 +3306,7 @@ static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
 
 	if (dlm_debug) {
 		debugfs_remove(dlm_debug->d_locking_state);
+		debugfs_remove(dlm_debug->d_locking_filter);
 		ocfs2_put_dlm_debug(dlm_debug);
 	}
 }
fs/ocfs2/ocfs2.h +2 -0
index 8efa022684f4..f4da51099889 100644
@@ -237,6 +237,8 @@ struct ocfs2_orphan_scan {
 struct ocfs2_dlm_debug {
 	struct kref d_refcnt;
 	struct dentry *d_locking_state;
+	struct dentry *d_locking_filter;
+	u32 d_filter_secs;
 	struct list_head d_lockres_tracking;
 };
 
Signature · 1 line
2.21.0
author
#1 lore raw

Hello Guys,

If you have time, please help to review these two patches.
The patch logic is very simple, but it can help us to control lock resource dump length. In product environment, there are lots of lock resources in memory as time goes by.

Thanks
Gang

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 2019/4/29 at 16:33, in message <[email protected]>, Gang He

Quoted 110 lines · <[email protected]> wrote:

Add locking filter debugfs file, which is used to filter lock resources dump from locking_state debugfs file.
We use d_filter_secs field to filter lock resources dump, the default d_filter_secs(0) value filters nothing, otherwise, only dump the last N seconds active lock resources. This enhancement can avoid dumping lots of old records. The d_filter_secs value can be changed via locking_filter file.

Compared with v1, the main change is to add CONFIG_OCFS2_FS_STATS macro definition judgment.

---
 fs/ocfs2/dlmglue.c | 38 ++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/ocfs2.h   |  2 ++
 2 files changed, 40 insertions(+)
fs/ocfs2/dlmglue.c +24 -0
index dccf4136f8c1..554d37d52510 100644
@@ -3006,6 +3006,8 @@ struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
 	kref_init(&dlm_debug->d_refcnt);
 	INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
 	dlm_debug->d_locking_state = NULL;
+	dlm_debug->d_locking_filter = NULL;
+	dlm_debug->d_filter_secs = 0;
 out:
 	return dlm_debug;
 }
@@ -3104,11 +3106,33 @@ static int ocfs2_dlm_seq_show(struct seq_file *m, 
 void *v)
 {
 	int i;
 	char *lvb;
+	u32 now, last = 0;
 	struct ocfs2_lock_res *lockres = v;
+	struct ocfs2_dlm_debug *dlm_debug =
+			((struct ocfs2_dlm_seq_priv *)m->private)->p_dlm_debug;
 
 	if (!lockres)
 		return -EINVAL;
 
+	if (dlm_debug->d_filter_secs) {
+		now = ktime_to_timespec(ktime_get()).tv_sec;
+#ifdef CONFIG_OCFS2_FS_STATS
+		if (lockres->l_lock_prmode.ls_last >
+		    lockres->l_lock_exmode.ls_last)
+			last = lockres->l_lock_prmode.ls_last;
+		else
+			last = lockres->l_lock_exmode.ls_last;
+#endif
+		/*
+		 * Use d_filter_secs field to filter lock resources dump,
+		 * the default d_filter_secs(0) value filters nothing,
+		 * otherwise, only dump the last N seconds active lock
+		 * resources.
+		 */
+		if ((now - last) > dlm_debug->d_filter_secs)
+			return 0;
+	}
+
 	seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
 
fs/ocfs2/dlmglue.c +13 -0
 	if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
@@ -3258,6 +3282,19 @@ static int ocfs2_dlm_init_debug(struct ocfs2_super 
 *osb)
 		goto out;
 	}
 
+	dlm_debug->d_locking_filter = debugfs_create_u32("locking_filter",
+						0600,
+						osb->osb_debug_root,
+						&dlm_debug->d_filter_secs);
+	if (!dlm_debug->d_locking_filter) {
+		ret = -EINVAL;
+		mlog(ML_ERROR,
+		     "Unable to create locking filter debugfs file.\n");
+		debugfs_remove(dlm_debug->d_locking_state);
+		dlm_debug->d_locking_state = NULL;
+		goto out;
+	}
+
 	ocfs2_get_dlm_debug(dlm_debug);
 out:
fs/ocfs2/dlmglue.c +1 -0
 	return ret;
@@ -3269,6 +3306,7 @@ static void ocfs2_dlm_shutdown_debug(struct ocfs2_super 
 *osb)
 
 	if (dlm_debug) {
 		debugfs_remove(dlm_debug->d_locking_state);
+		debugfs_remove(dlm_debug->d_locking_filter);
 		ocfs2_put_dlm_debug(dlm_debug);
 	}

}

fs/ocfs2/ocfs2.h +2 -0
index 8efa022684f4..f4da51099889 100644
@@ -237,6 +237,8 @@ struct ocfs2_orphan_scan {
 struct ocfs2_dlm_debug {
 	struct kref d_refcnt;
 	struct dentry *d_locking_state;
+	struct dentry *d_locking_filter;
+	u32 d_filter_secs;
 	struct list_head d_lockres_tracking;
 };
 
Signature · 1 line
2.21.0
#2 lore raw
In reply to Gang He

Hi Gang,

Quoted 68 lines · Gang He

Add locking filter debugfs file, which is used to filter lock resources dump from locking_state debugfs file.
We use d_filter_secs field to filter lock resources dump, the default d_filter_secs(0) value filters nothing, otherwise, only dump the last N seconds active lock resources. This enhancement can avoid dumping lots of old records. The d_filter_secs value can be changed via locking_filter file.

Compared with v1, the main change is to add CONFIG_OCFS2_FS_STATS macro definition judgment.

---
 fs/ocfs2/dlmglue.c | 38 ++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/ocfs2.h   |  2 ++
 2 files changed, 40 insertions(+)
fs/ocfs2/dlmglue.c +24 -0
index dccf4136f8c1..554d37d52510 100644
@@ -3006,6 +3006,8 @@ struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
 	kref_init(&dlm_debug->d_refcnt);
 	INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
 	dlm_debug->d_locking_state = NULL;
+	dlm_debug->d_locking_filter = NULL;
+	dlm_debug->d_filter_secs = 0;
 out:
 	return dlm_debug;
 }
@@ -3104,11 +3106,33 @@ static int ocfs2_dlm_seq_show(struct seq_file *m, void *v)
 {
 	int i;
 	char *lvb;
+	u32 now, last = 0;
 	struct ocfs2_lock_res *lockres = v;
+	struct ocfs2_dlm_debug *dlm_debug =
+			((struct ocfs2_dlm_seq_priv *)m->private)->p_dlm_debug;
 
 	if (!lockres)
 		return -EINVAL;
 
+	if (dlm_debug->d_filter_secs) {
+		now = ktime_to_timespec(ktime_get()).tv_sec;
+#ifdef CONFIG_OCFS2_FS_STATS
+		if (lockres->l_lock_prmode.ls_last >
+		    lockres->l_lock_exmode.ls_last)
+			last = lockres->l_lock_prmode.ls_last;
+		else
+			last = lockres->l_lock_exmode.ls_last;
+#endif
+		/*
+		 * Use d_filter_secs field to filter lock resources dump,
+		 * the default d_filter_secs(0) value filters nothing,
+		 * otherwise, only dump the last N seconds active lock
+		 * resources.
+		 */
+		if ((now - last) > dlm_debug->d_filter_secs)
+			return 0;
+	}
+
 	seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
 
 	if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
@@ -3258,6 +3282,19 @@ static int ocfs2_dlm_init_debug(struct ocfs2_super *osb)
 		goto out;
 	}
 

fs/ocfs2/dlmglue.c static int ocfs2_dlm_init_debug(struct ocfs2_super *osb) · line 3294

Quoted 10 lines
fs/ocfs2/dlmglue.c +10 -0
+	dlm_debug->d_locking_filter = debugfs_create_u32("locking_filter",
+						0600,
+						osb->osb_debug_root,
+						&dlm_debug->d_filter_secs);
+	if (!dlm_debug->d_locking_filter) {
+		ret = -EINVAL;
+		mlog(ML_ERROR,
+		     "Unable to create locking filter debugfs file.\n");
+		debugfs_remove(dlm_debug->d_locking_state);
+		dlm_debug->d_locking_state = NULL;

Or we can just leave this cleanup for ocfs2_dlm_shutdown_debug()?

Thanks,
Joseph

Quoted 28 lines
fs/ocfs2/dlmglue.c +4 -0
+		goto out;
+	}
+
 	ocfs2_get_dlm_debug(dlm_debug);
 out:
 	return ret;
@@ -3269,6 +3306,7 @@ static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
 
 	if (dlm_debug) {
 		debugfs_remove(dlm_debug->d_locking_state);
+		debugfs_remove(dlm_debug->d_locking_filter);
 		ocfs2_put_dlm_debug(dlm_debug);
 	}
 }
fs/ocfs2/ocfs2.h +2 -0
index 8efa022684f4..f4da51099889 100644
@@ -237,6 +237,8 @@ struct ocfs2_orphan_scan {
 struct ocfs2_dlm_debug {
 	struct kref d_refcnt;
 	struct dentry *d_locking_state;
+	struct dentry *d_locking_filter;
+	u32 d_filter_secs;
 	struct list_head d_lockres_tracking;
 };
 
author
#3 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 2019/5/5 at 14:54, in message

<[email protected]>, Joseph Qi

Quoted 73 lines · <[email protected]> wrote:

Hi Gang,

fs/ocfs2/dlmglue.c static int ocfs2_dlm_seq_show(struct seq_file *m,

Quoted 31 lines · Gang He

Add locking filter debugfs file, which is used to filter lock resources dump from locking_state debugfs file.
We use d_filter_secs field to filter lock resources dump, the default d_filter_secs(0) value filters nothing, otherwise, only dump the last N seconds active lock resources. This enhancement can avoid dumping lots of old records. The d_filter_secs value can be changed via locking_filter file.

Compared with v1, the main change is to add CONFIG_OCFS2_FS_STATS macro definition judgment.

---
 fs/ocfs2/dlmglue.c | 38 ++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/ocfs2.h   |  2 ++
 2 files changed, 40 insertions(+)
fs/ocfs2/dlmglue.c +2 -0
index dccf4136f8c1..554d37d52510 100644
@@ -3006,6 +3006,8 @@ struct ocfs2_dlm_debug *ocfs2_new_dlm_debug(void)
 	kref_init(&dlm_debug->d_refcnt);
 	INIT_LIST_HEAD(&dlm_debug->d_lockres_tracking);
 	dlm_debug->d_locking_state = NULL;
+	dlm_debug->d_locking_filter = NULL;
+	dlm_debug->d_filter_secs = 0;
 out:
 	return dlm_debug;
 }
@@ -3104,11 +3106,33 @@ static int ocfs2_dlm_seq_show(struct seq_file *m, 

void *v)

fs/ocfs2/dlmglue.c static int ocfs2_dlm_init_debug(struct ocfs2_super

Quoted 34 lines
fs/ocfs2/dlmglue.c +22 -0
 {
 	int i;
 	char *lvb;
+	u32 now, last = 0;
 	struct ocfs2_lock_res *lockres = v;
+	struct ocfs2_dlm_debug *dlm_debug =
+			((struct ocfs2_dlm_seq_priv *)m->private)->p_dlm_debug;
 
 	if (!lockres)
 		return -EINVAL;
 
+	if (dlm_debug->d_filter_secs) {
+		now = ktime_to_timespec(ktime_get()).tv_sec;
+#ifdef CONFIG_OCFS2_FS_STATS
+		if (lockres->l_lock_prmode.ls_last >
+		    lockres->l_lock_exmode.ls_last)
+			last = lockres->l_lock_prmode.ls_last;
+		else
+			last = lockres->l_lock_exmode.ls_last;
+#endif
+		/*
+		 * Use d_filter_secs field to filter lock resources dump,
+		 * the default d_filter_secs(0) value filters nothing,
+		 * otherwise, only dump the last N seconds active lock
+		 * resources.
+		 */
+		if ((now - last) > dlm_debug->d_filter_secs)
+			return 0;
+	}
+
 	seq_printf(m, "0x%x\t", OCFS2_DLM_DEBUG_STR_VERSION);
 
 	if (lockres->l_type == OCFS2_LOCK_TYPE_DENTRY)
@@ -3258,6 +3282,19 @@ static int ocfs2_dlm_init_debug(struct ocfs2_super 

*osb)

Quoted 3 lines
fs/ocfs2/dlmglue.c +0 -0
 		goto out;
 	}
 
Quoted 12 lines

fs/ocfs2/dlmglue.c static int ocfs2_dlm_init_debug(struct ocfs2_super *osb) · line 3294

Quoted 10 lines
fs/ocfs2/dlmglue.c +10 -0
+	dlm_debug->d_locking_filter = debugfs_create_u32("locking_filter",
+						0600,
+						osb->osb_debug_root,
+						&dlm_debug->d_filter_secs);
+	if (!dlm_debug->d_locking_filter) {
+		ret = -EINVAL;
+		mlog(ML_ERROR,
+		     "Unable to create locking filter debugfs file.\n");
+		debugfs_remove(dlm_debug->d_locking_state);
+		dlm_debug->d_locking_state = NULL;

Or we can just leave this cleanup for ocfs2_dlm_shutdown_debug()?

Yes, it looks more concise to delete these two lines code, then let ocfs2_dlm_shutdown_debug() function to handle the cleanup in case failure.

Thanks
Gang

Quoted 33 lines

Thanks,
Joseph

fs/ocfs2/dlmglue.c static void ocfs2_dlm_shutdown_debug(struct

Quoted 7 lines
fs/ocfs2/dlmglue.c +3 -0
+		goto out;
+	}
+
 	ocfs2_get_dlm_debug(dlm_debug);
 out:
 	return ret;
@@ -3269,6 +3306,7 @@ static void ocfs2_dlm_shutdown_debug(struct 

ocfs2_super *osb)

Quoted 21 lines
fs/ocfs2/dlmglue.c +1 -0
 	if (dlm_debug) {
 		debugfs_remove(dlm_debug->d_locking_state);
+		debugfs_remove(dlm_debug->d_locking_filter);
 		ocfs2_put_dlm_debug(dlm_debug);
 	}
 }
fs/ocfs2/ocfs2.h +2 -0
index 8efa022684f4..f4da51099889 100644
@@ -237,6 +237,8 @@ struct ocfs2_orphan_scan {
 struct ocfs2_dlm_debug {
 	struct kref d_refcnt;
 	struct dentry *d_locking_state;
+	struct dentry *d_locking_filter;
+	u32 d_filter_secs;
 	struct list_head d_lockres_tracking;
 };