[Devel] [PATCH RHEL8 COMMIT] fs/fuse kio: share stucked requests count for prometheus stats

Konstantin Khorenko khorenko at virtuozzo.com
Fri Apr 23 11:55:01 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.19
------>
commit ad6ee0c16b41daedea60f539e9e655447098f01c
Author: Ildar Ismagilov <ildar.ismagilov at virtuozzo.com>
Date:   Fri Apr 23 11:55:01 2021 +0300

    fs/fuse kio: share stucked requests count for prometheus stats
    
    Pass the following counters to prometheus through sysfs:
     - stucked_reqs_cnt_8s (total amount of requests that run for longer than 8s)
     - stucked_reqs_cnt_30s (total amount of requests that run for longer than 30s)
     - stucked_reqs_cnt_120s (total amount of requests that run for longer than 120s)
    
    The counters have been added to the end of the kfuse_metrics structure.
    
    https://pmc.acronis.com/browse/VSTOR-41021
    
    Signed-off-by: Ildar Ismagilov <ildar.ismagilov at virtuozzo.com>
    
    Acked-by:  Alexey Kuznetsov <kuznet at acronis.com>
    
    Signed-off-by: Ildar Ismagilov <ildar.ismagilov at virtuozzo.com>
---
 fs/fuse/kio/pcs/fuse_ktrace.h          |  1 +
 fs/fuse/kio/pcs/fuse_prometheus_prot.h |  4 ++++
 fs/fuse/kio/pcs/pcs_fuse_kdirect.c     | 26 ++++++++++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/fs/fuse/kio/pcs/fuse_ktrace.h b/fs/fuse/kio/pcs/fuse_ktrace.h
index 45a4064aa6d0..50861b37c15d 100644
--- a/fs/fuse/kio/pcs/fuse_ktrace.h
+++ b/fs/fuse/kio/pcs/fuse_ktrace.h
@@ -15,6 +15,7 @@
 struct fuse_ktrace
 {
 	atomic_t				refcnt;
+	struct fuse_conn			*fc;
 	struct rchan				*rchan;
 	struct dentry				*dir;
 	unsigned long __percpu			*ovfl;
diff --git a/fs/fuse/kio/pcs/fuse_prometheus_prot.h b/fs/fuse/kio/pcs/fuse_prometheus_prot.h
index 2959b1e7ff14..90aedd6a7ccd 100644
--- a/fs/fuse/kio/pcs/fuse_prometheus_prot.h
+++ b/fs/fuse/kio/pcs/fuse_prometheus_prot.h
@@ -40,6 +40,10 @@ struct kfuse_metrics {
 
 	/* Counters were added in 3.5 release */
 	struct kfuse_counter	cnts[KFUSE_OP_MAX];
+
+	u64 stucked_reqs_cnt_8s;
+	u64 stucked_reqs_cnt_30s;
+	u64 stucked_reqs_cnt_120s;
 };
 
 #endif /* __FUSE_PROMETHEUS_PROT__ */
diff --git a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
index c7b79b90c33e..c44bc287a7c4 100644
--- a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
+++ b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
@@ -1267,6 +1267,8 @@ static void fuse_trace_free(struct fuse_ktrace *tr)
 		free_percpu(tr->prometheus_metrics);
 	free_percpu(tr->buf);
 	debugfs_remove(tr->dir);
+	if (tr->fc)
+		fuse_conn_put(tr->fc);
 	kfree(tr);
 }
 
@@ -1390,6 +1392,24 @@ static int prometheus_file_release(struct inode *inode, struct file *filp)
 	return 0;
 }
 
+static void prometheus_req_iter(struct fuse_file *ff, struct fuse_req *req,
+				void *ctx)
+{
+	struct kfuse_metrics *stats = ctx;
+	struct pcs_fuse_req *r = pcs_req_from_fuse(req);
+	struct pcs_int_request *ireq = &r->exec.ireq;
+	s64 duration;
+
+	duration = ktime_to_ms(ktime_sub(ktime_get(), ireq->ts));
+
+	if (duration >= 8 * MSEC_PER_SEC)
+		stats->stucked_reqs_cnt_8s++;
+	if (duration >= 30 * MSEC_PER_SEC)
+		stats->stucked_reqs_cnt_30s++;
+	if (duration >= 120 * MSEC_PER_SEC)
+		stats->stucked_reqs_cnt_120s++;
+}
+
 /* NOTE: old versions of userspace could read only histograms */
 static ssize_t prometheus_file_read(struct file *filp,
 				    char __user *buffer,
@@ -1435,6 +1455,10 @@ static ssize_t prometheus_file_read(struct file *filp,
 		}
 	}
 
+	spin_lock(&tr->fc->lock);
+	pcs_kio_req_list(tr->fc, prometheus_req_iter, stats);
+	spin_unlock(&tr->fc->lock);
+
 	if (copy_to_user(buffer, (char *)stats + *ppos, count))
 		count = -EFAULT;
 	else
@@ -1467,6 +1491,8 @@ static int fuse_ktrace_setup(struct fuse_conn * fc)
 	if (!tr)
 		return -ENOMEM;
 
+	tr->fc = fuse_conn_get(fc);
+
 	ret = -ENOMEM;
 	tr->ovfl = alloc_percpu(unsigned long);
 	if (!tr->ovfl)


More information about the Devel mailing list