linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sage Weil <sage@newdream.net>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Sage Weil <sage@newdream.net>
Subject: [PATCH 18/20] ceph: debugging
Date: Mon,  9 Mar 2009 15:40:37 -0700	[thread overview]
Message-ID: <1236638439-6753-19-git-send-email-sage@newdream.net> (raw)
In-Reply-To: <1236638439-6753-18-git-send-email-sage@newdream.net>

Some debugging infrastructure, including the ability to adjust the
level of debug output on a per-file basis.  A memory leak detection
tool can also be enabled via .config.

Signed-off-by: Sage Weil <sage@newdream.net>
---
 fs/ceph/bookkeeper.c |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/ceph/bookkeeper.h |   19 ++++++++
 fs/ceph/ceph_debug.h |  103 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 239 insertions(+), 0 deletions(-)
 create mode 100644 fs/ceph/bookkeeper.c
 create mode 100644 fs/ceph/bookkeeper.h
 create mode 100644 fs/ceph/ceph_debug.h

diff --git a/fs/ceph/bookkeeper.c b/fs/ceph/bookkeeper.c
new file mode 100644
index 0000000..5f05509
--- /dev/null
+++ b/fs/ceph/bookkeeper.c
@@ -0,0 +1,117 @@
+#include <linux/spinlock.h>
+#include <linux/slab.h>
+#include <linux/kallsyms.h>
+
+#define CEPH_OVERRIDE_BOOKKEEPER /* avoid kmalloc/kfree recursion */
+
+#define CEPH_BK_MAGIC 0x140985AC
+
+#include "ceph_debug.h"
+
+int ceph_debug_tools __read_mostly = -1;
+#define DOUT_VAR ceph_debug_tools
+#define DOUT_MASK DOUT_MASK_TOOLS
+#include "super.h"
+
+static struct list_head _bk_allocs;
+
+static DEFINE_SPINLOCK(_bk_lock);
+
+static size_t _total_alloc;
+static size_t _total_free;
+
+struct alloc_data {
+	u32 prefix_magic;
+	struct list_head node;
+	size_t size;
+	char *fname;
+	int line;
+	u32 suffix_magic;
+};
+
+void *ceph_kmalloc(char *fname, int line, size_t size, gfp_t flags)
+{
+	struct alloc_data *p = kmalloc(size+sizeof(struct alloc_data), flags);
+
+	if (!p)
+		return NULL;
+
+	p->prefix_magic = CEPH_BK_MAGIC;
+	p->size = size;
+	p->fname = fname;
+	p->line = line;
+	p->suffix_magic = CEPH_BK_MAGIC;
+
+	spin_lock(&_bk_lock);
+	_total_alloc += size;
+
+	list_add_tail(&p->node, &_bk_allocs);
+	spin_unlock(&_bk_lock);
+
+	return ((void *)p)+sizeof(struct alloc_data);
+}
+
+void ceph_kfree(void *ptr)
+{
+	struct alloc_data *p = (struct alloc_data *)(ptr -
+						     sizeof(struct alloc_data));
+	int overrun = 0;
+
+	if (!ptr)
+		return;
+
+	if (p->prefix_magic != CEPH_BK_MAGIC) {
+		derr(0, "ERROR: memory overrun (under)!\n");
+		overrun = 1;
+	}
+
+	if (p->suffix_magic != CEPH_BK_MAGIC) {
+		derr(0, "ERROR: Memory overrun (over)!\n");
+		overrun = 1;
+	}
+
+	if (overrun) {
+		derr(0, "Memory allocated at %s(%d): p=%p (%zu bytes)\n", p->fname,
+			p->line,
+			((void *)p)+sizeof(struct alloc_data),
+			p->size);
+	}
+
+	BUG_ON(overrun);
+
+	spin_lock(&_bk_lock);
+	_total_free += p->size;
+	list_del(&p->node);
+	spin_unlock(&_bk_lock);
+
+	kfree(p);
+
+	return;
+}
+
+void ceph_bookkeeper_init(void)
+{
+	dout(10, "bookkeeper: start\n");
+	INIT_LIST_HEAD(&_bk_allocs);
+}
+
+void ceph_bookkeeper_finalize(void)
+{
+	struct list_head *p;
+	struct alloc_data *entry;
+
+	dout(1, "bookkeeper: total bytes alloc: %zu\n", _total_alloc);
+	dout(1, "bookkeeper: total bytes free: %zu\n", _total_free);
+
+	if (_total_alloc != _total_free) {
+		list_for_each(p, &_bk_allocs) {
+			entry = list_entry(p, struct alloc_data, node);
+			dout(1, "%s(%d): p=%p (%zu bytes)\n", entry->fname,
+			     entry->line,
+			     ((void *)entry)+sizeof(struct alloc_data),
+			     entry->size);
+		}
+	} else {
+		dout(1, "No leaks found! Yay!\n");
+	}
+}
diff --git a/fs/ceph/bookkeeper.h b/fs/ceph/bookkeeper.h
new file mode 100644
index 0000000..e7124f1
--- /dev/null
+++ b/fs/ceph/bookkeeper.h
@@ -0,0 +1,19 @@
+#ifndef _FS_CEPH_BOOKKEEPER_H
+#define _FS_CEPH_BOOKKEEPER_H
+
+#ifdef CONFIG_CEPH_BOOKKEEPER
+extern void ceph_bookkeeper_init(void);
+extern void ceph_bookkeeper_finalize(void);
+extern void *ceph_kmalloc(char *fname, int line, size_t size, gfp_t flags);
+extern void ceph_kfree(void *ptr);
+
+#ifndef CEPH_OVERRIDE_BOOKKEEPER
+#define kmalloc(size, flags)	ceph_kmalloc(__FILE__, __LINE__, size, flags)
+#define kzalloc(size, flags)	ceph_kmalloc(__FILE__, __LINE__, size, \
+					     flags | __GFP_ZERO)
+#define kfree	ceph_kfree
+#endif
+
+#endif
+
+#endif
diff --git a/fs/ceph/ceph_debug.h b/fs/ceph/ceph_debug.h
new file mode 100644
index 0000000..e06ec3d
--- /dev/null
+++ b/fs/ceph/ceph_debug.h
@@ -0,0 +1,103 @@
+#ifndef _FS_CEPH_DEBUG_H
+#define _FS_CEPH_DEBUG_H
+
+#include <linux/string.h>
+
+#include "bookkeeper.h"
+
+extern int ceph_debug __read_mostly;         /* debug level. */
+extern int ceph_debug_console __read_mostly; /* send debug output to console? */
+extern int ceph_debug_mask __read_mostly;
+
+/*
+ * different debug levels for different modules.  These default to -1.
+ * If they are >= 0, then they override the global ceph_debug value.
+ */
+extern int ceph_debug_addr __read_mostly;
+extern int ceph_debug_caps __read_mostly;
+extern int ceph_debug_dir __read_mostly;
+extern int ceph_debug_export __read_mostly;
+extern int ceph_debug_file __read_mostly;
+extern int ceph_debug_inode __read_mostly;
+extern int ceph_debug_ioctl __read_mostly;
+extern int ceph_debug_mdsc __read_mostly;
+extern int ceph_debug_mdsmap __read_mostly;
+extern int ceph_debug_msgr __read_mostly;
+extern int ceph_debug_mon __read_mostly;
+extern int ceph_debug_osdc __read_mostly;
+extern int ceph_debug_osdmap __read_mostly;
+extern int ceph_debug_snap __read_mostly;
+extern int ceph_debug_super __read_mostly;
+extern int ceph_debug_protocol __read_mostly;
+extern int ceph_debug_proc __read_mostly;
+extern int ceph_debug_tools __read_mostly;
+
+#define DOUT_MASK_ADDR		0x00000001
+#define DOUT_MASK_CAPS		0x00000002
+#define DOUT_MASK_DIR		0x00000004
+#define DOUT_MASK_EXPORT	0x00000008
+#define DOUT_MASK_FILE		0x00000010
+#define DOUT_MASK_INODE		0x00000020
+#define DOUT_MASK_IOCTL		0x00000040
+#define DOUT_MASK_MDSC		0x00000080
+#define DOUT_MASK_MDSMAP	0x00000100
+#define DOUT_MASK_MSGR		0x00000200
+#define DOUT_MASK_MON		0x00000400
+#define DOUT_MASK_OSDC		0x00000800
+#define DOUT_MASK_OSDMAP	0x00001000
+#define DOUT_MASK_SNAP		0x00002000
+#define DOUT_MASK_SUPER		0x00004000
+#define DOUT_MASK_PROTOCOL	0x00008000
+#define DOUT_MASK_PROC		0x00010000
+#define DOUT_MASK_TOOLS		0x00020000
+
+#define DOUT_UNMASKABLE	0x80000000
+
+#define _STRINGIFY(x) #x
+#define STRINGIFY(x) _STRINGIFY(x)
+
+#define FMT_PREFIX "%-30.30s: "
+#define FMT_SUFFIX "%s"
+#define LOG_ARGS __FILE__ ":" STRINGIFY(__LINE__)
+#define TRAIL_PARAM ""
+
+#define LOG_LINE FMT_PREFIX fmt, LOG_ARGS, args
+
+#define dout_flag(x, mask, fmt, args...) do {				\
+		if (((ceph_debug_mask | DOUT_UNMASKABLE) & mask) &&	\
+		    ((DOUT_VAR >= 0 && x <= DOUT_VAR) ||		\
+		     (DOUT_VAR < 0 && x <= ceph_debug))) {		\
+			if (ceph_debug_console)				\
+				printk(KERN_ERR FMT_PREFIX fmt, LOG_ARGS, args);	\
+			else						\
+				printk(KERN_DEBUG FMT_PREFIX fmt, LOG_ARGS, args);	\
+		}							\
+	} while (0)
+
+#define _dout(x, fmt, args...) dout_flag(x, DOUT_MASK, fmt FMT_SUFFIX, args)
+
+#define _derr(x, fmt, args...) do {					\
+		printk(KERN_ERR FMT_PREFIX fmt FMT_SUFFIX, LOG_ARGS, args);	\
+	} while (0)
+
+#define dout(x, args...) _dout(x, args, TRAIL_PARAM)
+#define derr(x, args...) _derr(x, args, TRAIL_PARAM)
+
+/* dcache d_count debugging */
+#if 0
+# define dput(dentry)				       \
+	do {					       \
+		dout(20, "dput %p %d -> %d\n", dentry, \
+		     atomic_read(&dentry->d_count),    \
+		     atomic_read(&dentry->d_count)-1); \
+		dput(dentry);			       \
+	} while (0)
+# define d_drop(dentry)				       \
+	do {					       \
+		dout(20, "d_drop %p\n", dentry);       \
+		d_drop(dentry);			       \
+	} while (0)
+#endif
+
+
+#endif
-- 
1.5.6.5


  reply	other threads:[~2009-03-09 22:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-09 22:40 [PATCH 00/20] ceph: Ceph distributed file system client Sage Weil
2009-03-09 22:40 ` [PATCH 01/20] ceph: documentation Sage Weil
2009-03-09 22:40   ` [PATCH 02/20] ceph: on-wire types Sage Weil
2009-03-09 22:40     ` [PATCH 03/20] ceph: client types Sage Weil
2009-03-09 22:40       ` [PATCH 04/20] ceph: super.c Sage Weil
2009-03-09 22:40         ` [PATCH 05/20] ceph: inode operations Sage Weil
2009-03-09 22:40           ` [PATCH 06/20] ceph: directory operations Sage Weil
2009-03-09 22:40             ` [PATCH 07/20] ceph: file operations Sage Weil
2009-03-09 22:40               ` [PATCH 08/20] ceph: address space operations Sage Weil
2009-03-09 22:40                 ` [PATCH 09/20] ceph: MDS client Sage Weil
2009-03-09 22:40                   ` [PATCH 10/20] ceph: OSD client Sage Weil
2009-03-09 22:40                     ` [PATCH 11/20] ceph: CRUSH mapping algorithm Sage Weil
2009-03-09 22:40                       ` [PATCH 12/20] ceph: monitor client Sage Weil
2009-03-09 22:40                         ` [PATCH 13/20] ceph: capability management Sage Weil
2009-03-09 22:40                           ` [PATCH 14/20] ceph: snapshot management Sage Weil
2009-03-09 22:40                             ` [PATCH 15/20] ceph: messenger library Sage Weil
2009-03-09 22:40                               ` [PATCH 16/20] ceph: nfs re-export support Sage Weil
2009-03-09 22:40                                 ` [PATCH 17/20] ceph: ioctls Sage Weil
2009-03-09 22:40                                   ` Sage Weil [this message]
2009-03-09 22:40                                     ` [PATCH 19/20] ceph: sysfs Sage Weil
2009-03-09 22:40                                       ` [PATCH 20/20] ceph: Kconfig, Makefile Sage Weil
2009-03-10 18:27 ` [PATCH 00/20] ceph: Ceph distributed file system client Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2009-07-15 21:24 [PATCH 00/20] ceph: Ceph distributed file system client v0.10 Sage Weil
2009-07-15 21:24 ` [PATCH 01/20] ceph: documentation Sage Weil
2009-07-15 21:24   ` [PATCH 02/20] ceph: on-wire types Sage Weil
2009-07-15 21:24     ` [PATCH 03/20] ceph: client types Sage Weil
2009-07-15 21:24       ` [PATCH 04/20] ceph: super.c Sage Weil
2009-07-15 21:24         ` [PATCH 05/20] ceph: inode operations Sage Weil
2009-07-15 21:24           ` [PATCH 06/20] ceph: directory operations Sage Weil
2009-07-15 21:24             ` [PATCH 07/20] ceph: file operations Sage Weil
2009-07-15 21:24               ` [PATCH 08/20] ceph: address space operations Sage Weil
2009-07-15 21:24                 ` [PATCH 09/20] ceph: MDS client Sage Weil
2009-07-15 21:24                   ` [PATCH 10/20] ceph: OSD client Sage Weil
2009-07-15 21:24                     ` [PATCH 11/20] ceph: CRUSH mapping algorithm Sage Weil
2009-07-15 21:24                       ` [PATCH 12/20] ceph: monitor client Sage Weil
2009-07-15 21:24                         ` [PATCH 13/20] ceph: capability management Sage Weil
2009-07-15 21:24                           ` [PATCH 14/20] ceph: snapshot management Sage Weil
2009-07-15 21:24                             ` [PATCH 15/20] ceph: messenger library Sage Weil
2009-07-15 21:24                               ` [PATCH 16/20] ceph: nfs re-export support Sage Weil
2009-07-15 21:24                                 ` [PATCH 17/20] ceph: ioctls Sage Weil
2009-07-15 21:24                                   ` [PATCH 18/20] ceph: debugging Sage Weil
2009-07-16 12:27                                     ` Andi Kleen
2009-07-16 17:17                                       ` Sage Weil
2009-07-17 18:07                                         ` Sage Weil
2009-07-17 18:56                                           ` Andi Kleen
2009-07-17 19:52                                             ` Sage Weil
2009-07-17 20:01                                               ` Andi Kleen
2009-07-17 21:35                                                 ` Sage Weil
2009-07-17 21:51                                                   ` Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1236638439-6753-19-git-send-email-sage@newdream.net \
    --to=sage@newdream.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).