Blob Blame History Raw
From 3410745d373acd5b28aeb82ca6770ae012065eb8 Mon Sep 17 00:00:00 2001
From: Poornima G <pgurusid@redhat.com>
Date: Wed, 17 Aug 2016 12:55:37 +0530
Subject: [PATCH 120/141] md-cache: Add cache hit and miss counters

These counters can be accessed either by .meta interface
or statedump.

From meta: cat on the private file in md-cache directory.
Eg: cat /mnt/glusterfs/0/.meta/graphs/active/patchy-md-cache/private
[performance/md-cache.patchy-md-cache]
stat_hit_count = 2
stat_miss_count = 8
xattr_hit_count = 4
xattr_miss_count = 3
nameless_lookup_count = 1
negative_lookup_count = 0
stat_invalidations_recieved = 1
xattr_invalidations_recieved = 1

Conflicts in backport:
        libglusterfs/src/globals.h

Change-Id: Ib62a8822f263a9f75858b15832d0119fbe382629
BUG: 1284873
Signed-off-by: Poornima G <pgurusid@redhat.com>
Reviewed-on: http://review.gluster.org/15185
Smoke: Gluster Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/87033
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
---
 libglusterfs/src/client_t.h                 |   17 ----
 libglusterfs/src/globals.h                  |   17 ++++
 xlators/performance/md-cache/src/md-cache.c |  108 +++++++++++++++++++++++++--
 3 files changed, 118 insertions(+), 24 deletions(-)

diff --git a/libglusterfs/src/client_t.h b/libglusterfs/src/client_t.h
index bfea620..29ea7f2 100644
--- a/libglusterfs/src/client_t.h
+++ b/libglusterfs/src/client_t.h
@@ -73,23 +73,6 @@ typedef struct clienttable clienttable_t;
 
 struct rpcsvc_auth_data;
 
-/*
- * a more comprehensive feature test is shown at
- * http://lists.iptel.org/pipermail/semsdev/2010-October/005075.html
- * this is sufficient for RHEL5 i386 builds
- */
-#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined(__i386__)
-# define INCREMENT_ATOMIC(lk,op) __sync_add_and_fetch(&op, 1)
-# define DECREMENT_ATOMIC(lk,op) __sync_sub_and_fetch(&op, 1)
-#else
-/* These are only here for old gcc, e.g. on RHEL5 i386.
- * We're not ever going to use this in an if stmt,
- * but let's be pedantically correct for style points */
-# define INCREMENT_ATOMIC(lk,op) do { LOCK (&lk); ++op; UNLOCK (&lk); } while (0)
-/* this is a gcc 'statement expression', it works with llvm/clang too */
-# define DECREMENT_ATOMIC(lk,op) ({ LOCK (&lk); --op; UNLOCK (&lk); op; })
-#endif
-
 client_t *
 gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid);
 
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
index f1f8ee1..514109a 100644
--- a/libglusterfs/src/globals.h
+++ b/libglusterfs/src/globals.h
@@ -89,6 +89,23 @@
 #define THIS (*__glusterfs_this_location())
 #define DECLARE_OLD_THIS        xlator_t *old_THIS = THIS
 
+/*
+ * a more comprehensive feature test is shown at
+ * http://lists.iptel.org/pipermail/semsdev/2010-October/005075.html
+ * this is sufficient for RHEL5 i386 builds
+ */
+#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined(__i386__)
+# define INCREMENT_ATOMIC(lk, op) __sync_add_and_fetch(&op, 1)
+# define DECREMENT_ATOMIC(lk, op) __sync_sub_and_fetch(&op, 1)
+#else
+/* These are only here for old gcc, e.g. on RHEL5 i386.
+ * We're not ever going to use this in an if stmt,
+ * but let's be pedantically correct for style points */
+# define INCREMENT_ATOMIC(lk, op) do { LOCK (&lk); ++op; UNLOCK (&lk); } while (0)
+/* this is a gcc 'statement expression', it works with llvm/clang too */
+# define DECREMENT_ATOMIC(lk, op) ({ LOCK (&lk); --op; UNLOCK (&lk); op; })
+#endif
+
 xlator_t **__glusterfs_this_location ();
 xlator_t *glusterfs_this_get ();
 int glusterfs_this_set (xlator_t *);
diff --git a/xlators/performance/md-cache/src/md-cache.c b/xlators/performance/md-cache/src/md-cache.c
index 28e7a57..ab6dcff 100644
--- a/xlators/performance/md-cache/src/md-cache.c
+++ b/xlators/performance/md-cache/src/md-cache.c
@@ -21,13 +21,26 @@
 #include <assert.h>
 #include <sys/time.h>
 #include "md-cache-messages.h"
-
+#include "statedump.h"
 
 /* TODO:
    - cache symlink() link names and nuke symlink-cache
    - send proper postbuf in setattr_cbk even when op_ret = -1
 */
 
+struct mdc_statistics {
+        uint64_t stat_hit; /* No. of times lookup/stat was served from mdc */
+        uint64_t stat_miss; /* No. of times valid stat wasn't present in mdc */
+        uint64_t xattr_hit; /* No. of times getxattr was served from mdc, Note:
+                             this doesn't count the xattr served from lookup */
+        uint64_t xattr_miss; /* No. of times xattr req was WIND from mdc */
+        uint64_t negative_lookup; /* No. of negative lookups */
+        uint64_t nameless_lookup; /* No. of negative lookups that were sent
+                                     sent to bricks */
+        uint64_t stat_invals; /* No. of invalidates recieved from upcall*/
+        uint64_t xattr_invals; /* No. of invalidates recieved from upcall*/
+        gf_lock_t lock;
+};
 
 struct mdc_conf {
 	int  timeout;
@@ -39,6 +52,7 @@ struct mdc_conf {
         gf_boolean_t mdc_invalidation;
         time_t last_child_down;
         gf_lock_t lock;
+        struct mdc_statistics mdc_counter;
 };
 
 
@@ -956,11 +970,16 @@ mdc_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
                 struct iatt *stbuf, dict_t *dict, struct iatt *postparent)
 {
         mdc_local_t *local = NULL;
+        struct mdc_conf *conf = this->private;
 
         local = frame->local;
 
-        if (op_ret != 0)
+        if (op_ret != 0) {
+                if (op_errno == ENOENT)
+                        INCREMENT_ATOMIC (conf->mdc_counter.lock,
+                                          conf->mdc_counter.negative_lookup);
                 goto out;
+        }
 
         if (!local)
                 goto out;
@@ -990,15 +1009,20 @@ mdc_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc,
         dict_t      *xattr_rsp = NULL;
         dict_t      *xattr_alloc = NULL;
         mdc_local_t *local = NULL;
-
+        struct mdc_conf *conf = this->private;
 
         local = mdc_local_get (frame);
-        if (!local)
+        if (!local) {
+                INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.stat_miss);
                 goto uncached;
+        }
 
         loc_copy (&local->loc, loc);
 
 	if (!loc->name) {
+                INCREMENT_ATOMIC (conf->mdc_counter.lock,
+                                  conf->mdc_counter.nameless_lookup);
+
                 gf_msg_trace ("md-cache", 0, "Nameless lookup(%s) sent to the "
                               "brick", uuid_utoa (loc->inode->gfid));
 		/* A nameless discovery is dangerous to serve from cache. We
@@ -1009,18 +1033,28 @@ mdc_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc,
         }
 
         ret = mdc_inode_iatt_get (this, loc->inode, &stbuf);
-        if (ret != 0)
+        if (ret != 0) {
+                INCREMENT_ATOMIC (conf->mdc_counter.lock,
+                                  conf->mdc_counter.stat_miss);
                 goto uncached;
+        }
 
         if (xdata) {
                 ret = mdc_inode_xatt_get (this, loc->inode, &xattr_rsp);
-                if (ret != 0)
+                if (ret != 0) {
+                        INCREMENT_ATOMIC (conf->mdc_counter.lock,
+                                          conf->mdc_counter.xattr_miss);
                         goto uncached;
+                }
 
-                if (!mdc_xattr_satisfied (this, xdata, xattr_rsp))
+                if (!mdc_xattr_satisfied (this, xdata, xattr_rsp)) {
+                        INCREMENT_ATOMIC (conf->mdc_counter.lock,
+                                          conf->mdc_counter.xattr_miss);
                         goto uncached;
+                }
         }
 
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.stat_hit);
         MDC_STACK_UNWIND (lookup, frame, 0, 0, loc->inode, &stbuf,
                           xattr_rsp, &postparent);
 
@@ -1074,6 +1108,7 @@ mdc_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
         int           ret;
         struct iatt   stbuf;
         mdc_local_t  *local = NULL;
+        struct mdc_conf *conf = this->private;
 
         local = mdc_local_get (frame);
         if (!local)
@@ -1085,11 +1120,13 @@ mdc_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
         if (ret != 0)
                 goto uncached;
 
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.stat_hit);
         MDC_STACK_UNWIND (stat, frame, 0, 0, &stbuf, xdata);
 
         return 0;
 
 uncached:
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.stat_miss);
         STACK_WIND (frame, mdc_stat_cbk,
                     FIRST_CHILD(this), FIRST_CHILD(this)->fops->stat,
                     loc, xdata);
@@ -1126,6 +1163,7 @@ mdc_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
         int           ret;
         struct iatt   stbuf;
         mdc_local_t  *local = NULL;
+        struct mdc_conf *conf = this->private;
 
         local = mdc_local_get (frame);
         if (!local)
@@ -1137,11 +1175,13 @@ mdc_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
         if (ret != 0)
                 goto uncached;
 
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.stat_hit);
         MDC_STACK_UNWIND (fstat, frame, 0, 0, &stbuf, xdata);
 
         return 0;
 
 uncached:
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.stat_miss);
         STACK_WIND (frame, mdc_fstat_cbk,
                     FIRST_CHILD(this), FIRST_CHILD(this)->fops->fstat,
                     fd, xdata);
@@ -1953,6 +1993,7 @@ mdc_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, const char *key,
 	int           op_errno = ENODATA;
         mdc_local_t  *local = NULL;
 	dict_t       *xattr = NULL;
+        struct mdc_conf *conf = this->private;
 
         local = mdc_local_get (frame);
         if (!local)
@@ -1972,11 +2013,13 @@ mdc_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, const char *key,
 		op_errno = ENODATA;
 	}
 
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.xattr_hit);
         MDC_STACK_UNWIND (getxattr, frame, ret, op_errno, xattr, xdata);
 
         return 0;
 
 uncached:
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.xattr_miss);
         STACK_WIND (frame, mdc_getxattr_cbk,
                     FIRST_CHILD(this), FIRST_CHILD(this)->fops->getxattr,
                     loc, key, xdata);
@@ -2015,6 +2058,7 @@ mdc_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, const char *key,
         mdc_local_t  *local = NULL;
 	dict_t       *xattr = NULL;
 	int           op_errno = ENODATA;
+        struct mdc_conf *conf = this->private;
 
         local = mdc_local_get (frame);
         if (!local)
@@ -2034,11 +2078,13 @@ mdc_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, const char *key,
 		op_errno = ENODATA;
 	}
 
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.xattr_hit);
         MDC_STACK_UNWIND (fgetxattr, frame, ret, op_errno, xattr, xdata);
 
         return 0;
 
 uncached:
+        INCREMENT_ATOMIC (conf->mdc_counter.lock, conf->mdc_counter.xattr_miss);
         STACK_WIND (frame, mdc_fgetxattr_cbk,
                     FIRST_CHILD(this), FIRST_CHILD(this)->fops->fgetxattr,
                     fd, key, xdata);
@@ -2371,6 +2417,39 @@ int mdc_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
 
 
 int
+mdc_priv_dump (xlator_t *this)
+{
+        struct mdc_conf *conf = NULL;
+        char  key_prefix[GF_DUMP_MAX_BUF_LEN];
+        char  key[GF_DUMP_MAX_BUF_LEN];
+
+        conf = this->private;
+
+        snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.%s", this->type, this->name);
+        gf_proc_dump_add_section(key_prefix);
+
+        gf_proc_dump_write("stat_hit_count", "%"PRId64,
+                           conf->mdc_counter.stat_hit);
+        gf_proc_dump_write("stat_miss_count", "%"PRId64,
+                           conf->mdc_counter.stat_miss);
+        gf_proc_dump_write("xattr_hit_count", "%"PRId64,
+                           conf->mdc_counter.xattr_hit);
+        gf_proc_dump_write("xattr_miss_count", "%"PRId64,
+                           conf->mdc_counter.xattr_miss);
+        gf_proc_dump_write("nameless_lookup_count", "%"PRId64,
+                           conf->mdc_counter.nameless_lookup);
+        gf_proc_dump_write("negative_lookup_count", "%"PRId64,
+                           conf->mdc_counter.negative_lookup);
+        gf_proc_dump_write("stat_invalidations_recieved", "%"PRId64,
+                           conf->mdc_counter.stat_invals);
+        gf_proc_dump_write("xattr_invalidations_recieved", "%"PRId64,
+                           conf->mdc_counter.xattr_invals);
+
+        return 0;
+}
+
+
+int
 mdc_forget (xlator_t *this, inode_t *inode)
 {
         mdc_inode_wipe (this, inode);
@@ -2432,6 +2511,7 @@ mdc_invalidate (xlator_t *this, void *data)
         int                                  ret        = 0;
         struct set                           tmp        = {0, };
         inode_table_t                       *itable     = NULL;
+        struct mdc_conf                     *conf       = this->private;
 
         up_data = (struct gf_upcall *)data;
 
@@ -2456,16 +2536,24 @@ mdc_invalidate (xlator_t *this, void *data)
                  */
                 if (ret < 0)
                         goto out;
+                INCREMENT_ATOMIC (conf->mdc_counter.lock,
+                                  conf->mdc_counter.stat_invals);
         }
         if (up_ci->flags & UP_XATTR) {
                 if (up_ci->dict)
                         ret = mdc_inode_xatt_update (this, inode, up_ci->dict);
                 else
                         ret = mdc_inode_xatt_invalidate (this, inode);
+
+                INCREMENT_ATOMIC (conf->mdc_counter.lock,
+                                  conf->mdc_counter.xattr_invals);
         } else if (up_ci->flags & UP_XATTR_RM) {
                 tmp.inode = inode;
                 tmp.this = this;
                 ret = dict_foreach (up_ci->dict, mdc_inval_xatt, &tmp);
+
+                INCREMENT_ATOMIC (conf->mdc_counter.lock,
+                                  conf->mdc_counter.xattr_invals);
         }
 
 out:
@@ -2681,6 +2769,12 @@ struct xlator_cbks cbks = {
         .forget      = mdc_forget,
 };
 
+
+struct xlator_dumpops dumpops = {
+        .priv       = mdc_priv_dump,
+};
+
+
 struct volume_options options[] = {
 	{ .key = {"cache-selinux"},
 	  .type = GF_OPTION_TYPE_BOOL,
-- 
1.7.1