[DRBD-cvs] r1614 - trunk/drbd

svn at svn.drbd.org svn at svn.drbd.org
Wed Oct 27 16:08:47 CEST 2004


Author: lars
Date: 2004-10-27 16:08:45 +0200 (Wed, 27 Oct 2004)
New Revision: 1614

Modified:
   trunk/drbd/drbd_fs.c
   trunk/drbd/drbd_main.c
   trunk/drbd/drbd_proc.c
   trunk/drbd/lru_cache.c
   trunk/drbd/lru_cache.h
Log:
add hit/miss counts to lru_cache, show them in /proc/drbd

Modified: trunk/drbd/drbd_fs.c
===================================================================
--- trunk/drbd/drbd_fs.c	2004-10-25 21:02:21 UTC (rev 1613)
+++ trunk/drbd/drbd_fs.c	2004-10-27 14:08:45 UTC (rev 1614)
@@ -178,7 +178,7 @@
 
 	in_use = 0;
 	t = mdev->act_log;
-	n = lc_alloc(mdev->sync_conf.al_extents,
+	n = lc_alloc("act_log", mdev->sync_conf.al_extents,
 		     sizeof(struct lc_element), mdev);
 
 	if (n==NULL) {

Modified: trunk/drbd/drbd_main.c
===================================================================
--- trunk/drbd/drbd_main.c	2004-10-25 21:02:21 UTC (rev 1613)
+++ trunk/drbd/drbd_main.c	2004-10-27 14:08:45 UTC (rev 1614)
@@ -1698,9 +1698,9 @@
 
 		if (drbd_bm_init(mdev)) goto Enomem;
 		// no need to lock access, we are still initializing the module.
-		mdev->resync = lc_alloc(17, sizeof(struct bm_extent),mdev);
+		mdev->resync = lc_alloc("resync",17, sizeof(struct bm_extent),mdev);
 		if (!mdev->resync) goto Enomem;
-		mdev->act_log = lc_alloc(mdev->sync_conf.al_extents,
+		mdev->act_log = lc_alloc("act_log",mdev->sync_conf.al_extents,
 					 sizeof(struct lc_element), mdev);
 		if (!mdev->act_log) goto Enomem;
 

Modified: trunk/drbd/drbd_proc.c
===================================================================
--- trunk/drbd/drbd_proc.c	2004-10-25 21:02:21 UTC (rev 1613)
+++ trunk/drbd/drbd_proc.c	2004-10-27 14:08:45 UTC (rev 1614)
@@ -37,6 +37,7 @@
 #include <linux/proc_fs.h>
 #include <linux/drbd.h>
 #include "drbd_int.h"
+#include "lru_cache.h" /* for lc_sprintf_stats */
 
 int drbd_proc_get_info(char *, char **, off_t, int, int *, void *);
 
@@ -215,10 +216,10 @@
 			if(test_bit(PARTNER_DISKLESS,&drbd_conf[i].flags))
 				sn = "ServerForDLess";
 		}
-		if ( drbd_conf[i].cstate == Unconfigured )
+		if ( drbd_conf[i].cstate == Unconfigured ) {
 			rlen += sprintf( buf + rlen,
 			   "%2d: cs:Unconfigured\n", i);
-		else
+		} else {
 			rlen += sprintf( buf + rlen,
 			   "%2d: cs:%s st:%s/%s ld:%s\n"
 			   "    ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
@@ -242,9 +243,14 @@
 			   atomic_read(&drbd_conf[i].ap_bio_cnt)
 			);
 
-		if ( drbd_conf[i].cstate == SyncSource ||
-		     drbd_conf[i].cstate == SyncTarget )
-			rlen += drbd_syncer_progress(drbd_conf+i,buf+rlen);
+			if ( drbd_conf[i].cstate == SyncSource ||
+			     drbd_conf[i].cstate == SyncTarget )
+				rlen += drbd_syncer_progress(drbd_conf+i,buf+rlen);
+
+			rlen += lc_sprintf_stats(buf+rlen,drbd_conf[i].resync);
+			rlen += lc_sprintf_stats(buf+rlen,drbd_conf[i].act_log);
+		}
+
 	}
 
 	/* DEBUG & profile stuff end */

Modified: trunk/drbd/lru_cache.c
===================================================================
--- trunk/drbd/lru_cache.c	2004-10-25 21:02:21 UTC (rev 1613)
+++ trunk/drbd/lru_cache.c	2004-10-27 14:08:45 UTC (rev 1614)
@@ -42,8 +42,8 @@
  * struct lru_cache, and the hash table slots.
  * returns pointer to a newly initialized lru_cache object with said parameters.
  */
-struct lru_cache* lc_alloc(unsigned int e_count, size_t e_size,
-			   void *private_p)
+struct lru_cache* lc_alloc(const char *name, unsigned int e_count,
+			   size_t e_size, void *private_p)
 {
 	unsigned long bytes;
 	struct lru_cache   *lc;
@@ -65,6 +65,7 @@
 		lc->nr_elements      = e_count;
 		lc->new_number	     = -1;
 		lc->lc_private       = private_p;
+		lc->name             = name;
 		for(i=0;i<e_count;i++) {
 			e = lc_entry(lc,i);
 			e->lc_number = LC_FREE;
@@ -84,6 +85,20 @@
 	vfree(lc);
 }
 
+size_t	lc_sprintf_stats(char* buf, struct lru_cache* lc)
+{
+	/* NOTE:
+	 * total calls to lc_get are
+	 * starving + hits + misses
+	 * misses include "dirty" count (update from an other thread in progress)
+	 * and "changed", when this in fact lead to an successful update of the cache.
+	 */
+	return sprintf(buf,"\t%s: elements:%u "
+		"hits:%lu misses:%lu starving:%lu dirty:%lu changed:%lu\n",
+		lc->name, lc->nr_elements,
+		lc->hits, lc->misses, lc->starving, lc->dirty, lc->changed);
+}
+
 static unsigned int lc_hash_fn(struct lru_cache* lc, unsigned int enr)
 {
 	return enr % lc->nr_elements;
@@ -199,15 +214,21 @@
 	BUG_ON(!lc->nr_elements);
 
 	PARANOIA_ENTRY();
-	if ( lc->flags & LC_STARVING ) RETURN(NULL);
+	if ( lc->flags & LC_STARVING ) {
+		++lc->starving;
+		RETURN(NULL);
+	}
 
 	e = lc_find(lc, enr);
 	if (e) {
+		++lc->hits;
 		++e->refcnt;
 		list_move(&e->list,&lc->in_use); // Not evictable...
 		RETURN(e);
 	}
 
+	++lc->misses;
+
 	/* In case there is nothing available and we can not kick out
 	 * the LRU element, we have to wait ...
 	 */
@@ -220,7 +241,10 @@
 	 * which then is replaced.
 	 * we need to update the cache; serialize on lc->flags & LC_DIRTY
 	 */
-	if (test_and_set_bit(__LC_DIRTY,&lc->flags)) RETURN(NULL);
+	if (test_and_set_bit(__LC_DIRTY,&lc->flags)) {
+		++lc->dirty;
+		RETURN(NULL);
+	}
 
 	e = lc_get_unused_element(lc);
 	BUG_ON(!e);
@@ -238,6 +262,7 @@
 {
 	PARANOIA_ENTRY();
 	BUG_ON(e != lc->changing_element);
+	++lc->changed;
 	e->lc_number = lc->new_number;
 	list_add(&e->list,&lc->in_use);
 	hlist_add_head( &e->colision, lc->slot + lc_hash_fn(lc, lc->new_number) );

Modified: trunk/drbd/lru_cache.h
===================================================================
--- trunk/drbd/lru_cache.h	2004-10-25 21:02:21 UTC (rev 1613)
+++ trunk/drbd/lru_cache.h	2004-10-27 14:08:45 UTC (rev 1614)
@@ -53,6 +53,10 @@
 
 #include <linux/version.h>
 
+/* FIXME
+ * I want these structs opaque outside of lru_cache.c
+ */
+
 struct lc_element {
 	struct hlist_node colision;
 	struct list_head list;           // LRU list or free list
@@ -67,10 +71,15 @@
 	size_t element_size;
 	unsigned int  nr_elements;
 	unsigned int  new_number;
+
+	/* here may or may not be a pad... */
+
 	unsigned long flags;
+	unsigned long hits, misses, starving, dirty, changed;
 	struct lc_element *changing_element; // just for paranoia
 
 	void  *lc_private;
+	const char *name;
 
 	struct hlist_head slot[0];
 	// hash colision chains here, then element storage.
@@ -87,8 +96,8 @@
 #define LC_DIRTY    (1<<__LC_DIRTY)
 #define LC_STARVING (1<<__LC_STARVING)
 
-extern struct lru_cache* lc_alloc(unsigned int e_count, size_t e_size,
-				  void *private_p);
+extern struct lru_cache* lc_alloc(const char *name, unsigned int e_count,
+				  size_t e_size, void *private_p);
 extern void lc_free(struct lru_cache* lc);
 extern void lc_set (struct lru_cache* lc, unsigned int enr, int index);
 extern void lc_del (struct lru_cache* lc, struct lc_element *element);
@@ -98,6 +107,7 @@
 extern unsigned int       lc_put (struct lru_cache* lc, struct lc_element* e);
 extern void            lc_changed(struct lru_cache* lc, struct lc_element* e);
 
+extern size_t lc_sprintf_stats(char* buf, struct lru_cache* lc);
 
 /* This can be used to stop lc_get from changing the set of active elements.
  * Note that the reference counts and order on the lru list may still change.



More information about the drbd-cvs mailing list