From 6df60fffb6ed630b9fb15c8b439335be9726e249 Mon Sep 17 00:00:00 2001 From: Xuefer Date: Sat, 27 May 2006 03:05:10 +0000 Subject: [PATCH] optimized xcache_info() to not wake up swapped memory. git-svn-id: svn://svn.lighttpd.net/xcache/trunk@32 c26eb9a1-5813-0410-bd6c-c2e55f420ca7 --- xcache.c | 21 ++++++--------------- xcache.h | 2 ++ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/xcache.c b/xcache.c index 0710eaa..3deac6e 100644 --- a/xcache.c +++ b/xcache.c @@ -139,6 +139,7 @@ static void xc_entry_add_dmz(xc_entry_t *xce) /* {{{ */ xc_entry_t **head = &(xce->cache->entries[xce->hvalue]); xce->next = *head; *head = xce; + xce->cache->entries_count ++; } /* }}} */ static xc_entry_t *xc_entry_store_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ @@ -166,6 +167,7 @@ static void xc_entry_remove_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ for (p = *last; p; last = &(p->next), p = p->next) { if (xc_entry_equal_dmz(xce, p)) { *last = p->next; + xce->cache->entries_count ++; if (p->refcount == 0) { xc_entry_free_dmz(p); } @@ -173,6 +175,7 @@ static void xc_entry_remove_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ p->next = p->cache->deletes; p->cache->deletes = p; p->dtime = XG(request_time); + xce->cache->deletes_count ++; } return; } @@ -223,8 +226,6 @@ static void xc_fillinfo_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /* xc_memsize_t avail = 0; #endif xc_mem_t *mem = cache->mem; - int i, c, count; - xc_entry_t *e; add_assoc_long_ex(return_value, ZEND_STRS("slots"), cache->hentry->size); add_assoc_long_ex(return_value, ZEND_STRS("compiling"), cache->compiling); @@ -233,19 +234,8 @@ static void xc_fillinfo_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /* add_assoc_long_ex(return_value, ZEND_STRS("clogs"), cache->clogs); add_assoc_long_ex(return_value, ZEND_STRS("ooms"), cache->ooms); - count = 0; - for (i = 0, c = cache->hentry->size; i < c; i ++) { - for (e = cache->entries[i]; e; e = e->next) { - count ++; - } - } - add_assoc_long_ex(return_value, ZEND_STRS("cached"), count); - - count = 0; - for (e = cache->deletes; e; e = e->next) { - count ++; - } - add_assoc_long_ex(return_value, ZEND_STRS("deleted"), count); + add_assoc_long_ex(return_value, ZEND_STRS("cached"), cache->entries_count); + add_assoc_long_ex(return_value, ZEND_STRS("deleted"), cache->deletes_count); MAKE_STD_ZVAL(blocks); array_init(blocks); @@ -418,6 +408,7 @@ static void xc_entry_gc_real(xc_cache_t **caches, int size TSRMLS_DC) /* {{{ */ } if (p->refcount == 0) { *last = p->next; + cache->deletes_count --; xc_entry_free_dmz(p); } else { diff --git a/xcache.h b/xcache.h index 607d567..8028430 100644 --- a/xcache.h +++ b/xcache.h @@ -131,7 +131,9 @@ typedef struct { xc_mem_t *mem; /* to which mem contains us */ xc_entry_t **entries; + int entries_count; xc_entry_t *deletes; + int deletes_count; xc_hash_t *hentry; /* hash to entry */ } xc_cache_t; /* }}} */