cvs: pecl /apc apc.php apc_cache.c apc_cache.h apc_sma.c apc_sma.h php_apc.c
| From: | Rasmus Lerdorf | Date: | Sat, 25 Feb 2006 19:50:33 +0000 |
| Subject: | cvs: pecl /apc apc.php apc_cache.c apc_cache.h apc_sma.c apc_sma.h php_apc.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-5271@lists.php.net to get a copy of this message | ||
rasmus Sat Feb 25 19:50:33 2006 UTC
Modified files:
/pecl/apc apc.php apc_cache.c apc_cache.h apc_sma.c apc_sma.h
php_apc.c
Log:
Try just clearing the cache on a cache full situation instead of blowing
a million tiny little holes in the cache causing massive fragmentation.
Also added an ALLOC_DISTRIBUTION debug define in apc_sma.h which when
set will maintain an array of allocation size requests so we have an
idea about the distribution. The apc.php script shows this data if
available.
http://cvs.php.net/viewcvs.cgi/pecl/apc/apc.php?r1=3.47&r2=3.48&diff_format=u Index: pecl/apc/apc.php diff -u pecl/apc/apc.php:3.47 pecl/apc/apc.php:3.48 --- pecl/apc/apc.php:3.47 Thu Sep 15 18:26:15 2005 +++ pecl/apc/apc.php Sat Feb 25 19:50:33 2006 @@ -22,7 +22,7 @@ */ -$VERSION='$Id: apc.php,v 3.47 2005/09/15 18:26:15 sniper Exp $'; +$VERSION='$Id: apc.php,v 3.48 2006/02/25 19:50:33 rasmus Exp $'; ////////// READ OPTIONAL CONFIGURATION FILE //////////// if (file_exists("apc.conf.php")) include("apc.conf.php"); @@ -188,7 +188,29 @@ // header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); // HTTP/1.0 +header("Pragma: no-cache"); // HTTP/1.0 + +function duration($ts) { + global $time; + $years = (int)((($time - $ts)/(7*86400))/52.177457); + $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400)); + $weeks = (int)(($rem)/(7*86400)); + $days = (int)(($rem)/86400) - $weeks*7; + $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24; + $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60; + $str = ''; + if($years==1) $str .= "$years year, "; + if($years>1) $str .= "$years years, "; + if($weeks==1) $str .= "$weeks week, "; + if($weeks>1) $str .= "$weeks weeks, "; + if($days==1) $str .= "$days day,"; + if($days>1) $str .= "$days days,"; + if($hours == 1) $str .= " $hours hour and"; + if($hours>1) $str .= " $hours hours and"; + if($mins == 1) $str .= " 1 minute"; + else $str .= " $mins minutes"; + return $str; +} // create graphics // @@ -383,6 +405,13 @@ } } break; + case 4: + $s=$cache['num_hits']+$cache['num_misses']; + $a=$cache['num_hits']; + + fill_box($image, 30,$size,50,-$a*($size-21)/$s,$col_black,$col_green,sprintf("%.1f%%",$cache['num_hits']*100/$s)); + fill_box($image,130,$size,50,-max(4,($s-$a)*($size-21)/$s),$col_black,$col_red,sprintf("%.1f%%",$cache['num_misses']*100/$s)); + break; } header("Content-type: image/png"); @@ -607,7 +636,7 @@ div.graph table td { padding:0.2em 1em 0.4em 1em; } div.div1,div.div2 { margin-bottom:1em; width:35em; } -div.div3 { position:absolute; left:37em; top:1em; width:580px; } +div.div3 { position:absolute; left:40em; top:1em; width:580px; } //div.div3 { position:absolute; left:37em; top:1em; right:1em; } div.sorting { margin:1.5em 0em 1.5em 2em } @@ -732,9 +761,10 @@ <tr class=tr-1><td class=td-0>Request Rate</td><td>$req_rate cache requests/second</td></tr> <tr class=tr-0><td class=td-0>Time To Live</td><td>{$cache['ttl']}</td></tr> <tr class=tr-1><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size</td></tr> + <tr class=tr-0><td class=td-0>Cache full count</td><td>{$cache['expunges']}</td></tr> EOB; - echo - '<tr class=tr-0><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>'; + echo '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>'; + echo '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>'; echo <<<EOB </tbody></table> </div> @@ -821,6 +851,16 @@ </br>Fragmentation: $frag </td> </tr> +EOB; + if(isset($mem['adist'])) { + foreach($mem['adist'] as $i=>$v) { + $cur = pow(2,$i); $nxt = pow(2,$i+1)-1; + if($i==0) $range = "1"; + else $range = "$cur - $nxt"; + echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n"; + } + } + echo <<<EOB </tbody></table> </div> EOB; http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_cache.c?r1=3.104&r2=3.105&diff_format=u Index: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.104 pecl/apc/apc_cache.c:3.105 --- pecl/apc/apc_cache.c:3.104 Sat Feb 25 09:02:56 2006 +++ pecl/apc/apc_cache.c Sat Feb 25 19:50:33 2006 @@ -28,7 +28,7 @@ */ -/* $Id: apc_cache.c,v 3.104 2006/02/25 09:02:56 rasmus Exp $ */ +/* $Id: apc_cache.c,v 3.105 2006/02/25 19:50:33 rasmus Exp $ */ #include "apc_cache.h" #include "apc_lock.h" @@ -70,6 +70,7 @@ int num_misses; /* total unsuccessful hits in cache */ slot_t* deleted_list; /* linked list of to-be-deleted slots */ time_t start_time; /* time the above counters were reset */ + int expunges; /* total number of expunges */ }; /* }}} */ @@ -281,6 +282,7 @@ cache->header->num_misses = 0; cache->header->deleted_list = NULL; cache->header->start_time = time(NULL); + cache->header->expunges = 0; cache->slots = (slot_t**) (((char*) cache->shmaddr) + sizeof(header_t)); cache->num_slots = num_slots; @@ -316,6 +318,7 @@ cache->header->num_hits = 0; cache->header->num_misses = 0; cache->header->start_time = time(NULL); + cache->header->expunges = 0; for (i = 0; i < cache->num_slots; i++) { slot_t* p = cache->slots[i]; @@ -332,6 +335,26 @@ /* {{{ apc_cache_expunge */ void apc_cache_expunge(apc_cache_t* cache, time_t t) { +#if 1 + int i; + if(!cache) return; + /* + Trying to delete only stale entries blows a million tiny little + holes in our cache causing excessive fragmentation. So let's + try just clearing it here instead and bumping the expunges count + to give us a hint that we need to tune the configuration. + */ + LOCK(cache); + cache->header->expunges++; + for (i = 0; i < cache->num_slots; i++) { + slot_t* p = cache->slots[i]; + while (p) { + remove_slot(cache, &p); + } + cache->slots[i] = NULL; + } + UNLOCK(cache); +#else int i; slot_t **p; @@ -373,6 +396,7 @@ } } UNLOCK(cache); +#endif } /* }}} */ @@ -852,6 +876,7 @@ info->list = NULL; info->deleted_list = NULL; info->start_time = cache->header->start_time; + info->expunges = cache->header->expunges; /* For each hashtable slot */ for (i = 0; i < info->num_slots; i++) { http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_cache.h?r1=3.32&r2=3.33&diff_format=u Index: pecl/apc/apc_cache.h diff -u pecl/apc/apc_cache.h:3.32 pecl/apc/apc_cache.h:3.33 --- pecl/apc/apc_cache.h:3.32 Sat Feb 25 09:02:56 2006 +++ pecl/apc/apc_cache.h Sat Feb 25 19:50:33 2006 @@ -26,7 +26,7 @@ */ -/* $Id: apc_cache.h,v 3.32 2006/02/25 09:02:56 rasmus Exp $ */ +/* $Id: apc_cache.h,v 3.33 2006/02/25 19:50:33 rasmus Exp $ */ #ifndef APC_CACHE_H #define APC_CACHE_H @@ -262,6 +262,7 @@ apc_cache_link_t* list; apc_cache_link_t* deleted_list; time_t start_time; + int expunges; }; /* }}} */ http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_sma.c?r1=1.37&r2=1.38&diff_format=u Index: pecl/apc/apc_sma.c diff -u pecl/apc/apc_sma.c:1.37 pecl/apc/apc_sma.c:1.38 --- pecl/apc/apc_sma.c:1.37 Sat Feb 25 15:22:42 2006 +++ pecl/apc/apc_sma.c Sat Feb 25 19:50:33 2006 @@ -26,7 +26,7 @@ */ -/* $Id: apc_sma.c,v 1.37 2006/02/25 15:22:42 rasmus Exp $ */ +/* $Id: apc_sma.c,v 1.38 2006/02/25 19:50:33 rasmus Exp $ */ #include "apc_sma.h" #include "apc.h" @@ -61,6 +61,9 @@ struct header_t { size_t segsize; /* size of entire segment */ size_t avail; /* bytes available (not necessarily contiguous) */ +#if ALLOC_DISTRIBUTION + size_t adist[30]; +#endif }; typedef struct block_t block_t; @@ -99,6 +102,10 @@ size_t realsize; /* actual size of block needed, including header */ size_t minsize; /* for finding best fit */ +#if 1 + if(size < 8) realsize = 8; + else realsize = size; +#else if(size < 0x40) { realsize = 0x40; } else { @@ -126,6 +133,7 @@ realsize = p; } } +#endif realsize = alignword(max(realsize + alignword(sizeof(int)), sizeof(block_t))); /* @@ -167,8 +175,11 @@ /* update the block header */ header->avail -= realsize; +#if ALLOC_DISTRIBUTION + header->adist[(int)(log(size)/log(2))]++; +#endif - if (cur->size == realsize || ((cur->size - realsize) < 0x40)) { + if (cur->size == realsize || ((cur->size - realsize) < 0x20)) { /* cur is a perfect fit for realsize; just unlink it */ prv->next = cur->next; } @@ -289,7 +300,12 @@ header->segsize = sma_segsize; header->avail = sma_segsize - sizeof(header_t) - sizeof(block_t) - alignword(sizeof(int)); - +#if ALLOC_DISTRIBUTION + { + int j; + for(j=0; j<30; j++) header->adist[j] = 0; + } +#endif block = BLOCKAT(sizeof(header_t)); block->size = 0; block->next = sizeof(header_t) + sizeof(block_t); @@ -491,6 +507,12 @@ } /* }}} */ +#if ALLOC_DISTRIBUTION +size_t *apc_sma_get_alloc_distribution(void) { + header_t* header = (header_t*) sma_shmaddrs[0]; + return header->adist; +} + /* {{{ apc_sma_unlock */ void apc_sma_unlock() { http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_sma.h?r1=1.12&r2=1.13&diff_format=u Index: pecl/apc/apc_sma.h diff -u pecl/apc/apc_sma.h:1.12 pecl/apc/apc_sma.h:1.13 --- pecl/apc/apc_sma.h:1.12 Sat Feb 25 17:59:45 2006 +++ pecl/apc/apc_sma.h Sat Feb 25 19:50:33 2006 @@ -25,11 +25,13 @@ */ -/* $Id: apc_sma.h,v 1.12 2006/02/25 17:59:45 rasmus Exp $ */ +/* $Id: apc_sma.h,v 1.13 2006/02/25 19:50:33 rasmus Exp $ */ #ifndef APC_SMA_H #define APC_SMA_H +#define ALLOC_DISTRIBUTION 0 + #include "apc.h" /* Simple shared memory allocator */ @@ -41,6 +43,9 @@ extern char* apc_sma_strdup(const char *s); extern void apc_sma_free(void* p); extern void apc_sma_unlock(); +#if ALLOC_DISTRIBUTION +extern size_t *apc_sma_get_alloc_distribution(); +#endif /* {{{ struct definition: apc_sma_link_t */ typedef struct apc_sma_link_t apc_sma_link_t; http://cvs.php.net/viewcvs.cgi/pecl/apc/php_apc.c?r1=3.79&r2=3.80&diff_format=u Index: pecl/apc/php_apc.c diff -u pecl/apc/php_apc.c:3.79 pecl/apc/php_apc.c:3.80 --- pecl/apc/php_apc.c:3.79 Thu Feb 16 23:31:43 2006 +++ pecl/apc/php_apc.c Sat Feb 25 19:50:33 2006 @@ -26,7 +26,7 @@ */ -/* $Id: php_apc.c,v 3.79 2006/02/16 23:31:43 iliaa Exp $ */ +/* $Id: php_apc.c,v 3.80 2006/02/25 19:50:33 rasmus Exp $ */ #include "php_apc.h" #include "apc_zend.h" @@ -167,7 +167,7 @@ #else php_info_print_table_row(2, "MMAP Support", "Disabled"); #endif - php_info_print_table_row(2, "Revision", "$Revision: 3.79 $"); + php_info_print_table_row(2, "Revision", "$Revision: 3.80 $"); php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); @@ -260,6 +260,7 @@ add_assoc_long(return_value, "num_hits", info->num_hits); add_assoc_long(return_value, "num_misses", info->num_misses); add_assoc_long(return_value, "start_time", info->start_time); + add_assoc_long(return_value, "expunges", info->expunges); ALLOC_INIT_ZVAL(list); array_init(list); @@ -365,7 +366,18 @@ add_assoc_long(return_value, "num_seg", info->num_seg); add_assoc_long(return_value, "seg_size", info->seg_size); add_assoc_long(return_value, "avail_mem", apc_sma_get_avail_mem()); - +#if ALLOC_DISTRIBUTION + { + size_t *adist = apc_sma_get_alloc_distribution(); + zval* list; + ALLOC_INIT_ZVAL(list); + array_init(list); + for(i=0; i<30; i++) { + add_next_index_long(list, adist[i]); + } + add_assoc_zval(return_value, "adist", list); + } +#endif ALLOC_INIT_ZVAL(block_lists); array_init(block_lists);
http://cvs.php.net/viewcvs.cgi/pecl/apc/apc.php?r1=3.47&r2=3.48&diff_format=u Index: pecl/apc/apc.php diff -u pecl/apc/apc.php:3.47 pecl/apc/apc.php:3.48 --- pecl/apc/apc.php:3.47 Thu Sep 15 18:26:15 2005 +++ pecl/apc/apc.php Sat Feb 25 19:50:33 2006 @@ -22,7 +22,7 @@ */ -$VERSION='$Id: apc.php,v 3.47 2005/09/15 18:26:15 sniper Exp $'; +$VERSION='$Id: apc.php,v 3.48 2006/02/25 19:50:33 rasmus Exp $'; ////////// READ OPTIONAL CONFIGURATION FILE //////////// if (file_exists("apc.conf.php")) include("apc.conf.php"); @@ -188,7 +188,29 @@ // header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); // HTTP/1.0 +header("Pragma: no-cache"); // HTTP/1.0 + +function duration($ts) { + global $time; + $years = (int)((($time - $ts)/(7*86400))/52.177457); + $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400)); + $weeks = (int)(($rem)/(7*86400)); + $days = (int)(($rem)/86400) - $weeks*7; + $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24; + $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60; + $str = ''; + if($years==1) $str .= "$years year, "; + if($years>1) $str .= "$years years, "; + if($weeks==1) $str .= "$weeks week, "; + if($weeks>1) $str .= "$weeks weeks, "; + if($days==1) $str .= "$days day,"; + if($days>1) $str .= "$days days,"; + if($hours == 1) $str .= " $hours hour and"; + if($hours>1) $str .= " $hours hours and"; + if($mins == 1) $str .= " 1 minute"; + else $str .= " $mins minutes"; + return $str; +} // create graphics // @@ -383,6 +405,13 @@ } } break; + case 4: + $s=$cache['num_hits']+$cache['num_misses']; + $a=$cache['num_hits']; + + fill_box($image, 30,$size,50,-$a*($size-21)/$s,$col_black,$col_green,sprintf("%.1f%%",$cache['num_hits']*100/$s)); + fill_box($image,130,$size,50,-max(4,($s-$a)*($size-21)/$s),$col_black,$col_red,sprintf("%.1f%%",$cache['num_misses']*100/$s)); + break; } header("Content-type: image/png"); @@ -607,7 +636,7 @@ div.graph table td { padding:0.2em 1em 0.4em 1em; } div.div1,div.div2 { margin-bottom:1em; width:35em; } -div.div3 { position:absolute; left:37em; top:1em; width:580px; } +div.div3 { position:absolute; left:40em; top:1em; width:580px; } //div.div3 { position:absolute; left:37em; top:1em; right:1em; } div.sorting { margin:1.5em 0em 1.5em 2em } @@ -732,9 +761,10 @@ <tr class=tr-1><td class=td-0>Request Rate</td><td>$req_rate cache requests/second</td></tr> <tr class=tr-0><td class=td-0>Time To Live</td><td>{$cache['ttl']}</td></tr> <tr class=tr-1><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size</td></tr> + <tr class=tr-0><td class=td-0>Cache full count</td><td>{$cache['expunges']}</td></tr> EOB; - echo - '<tr class=tr-0><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>'; + echo '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>'; + echo '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>'; echo <<<EOB </tbody></table> </div> @@ -821,6 +851,16 @@ </br>Fragmentation: $frag </td> </tr> +EOB; + if(isset($mem['adist'])) { + foreach($mem['adist'] as $i=>$v) { + $cur = pow(2,$i); $nxt = pow(2,$i+1)-1; + if($i==0) $range = "1"; + else $range = "$cur - $nxt"; + echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n"; + } + } + echo <<<EOB </tbody></table> </div> EOB; http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_cache.c?r1=3.104&r2=3.105&diff_format=u Index: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.104 pecl/apc/apc_cache.c:3.105 --- pecl/apc/apc_cache.c:3.104 Sat Feb 25 09:02:56 2006 +++ pecl/apc/apc_cache.c Sat Feb 25 19:50:33 2006 @@ -28,7 +28,7 @@ */ -/* $Id: apc_cache.c,v 3.104 2006/02/25 09:02:56 rasmus Exp $ */ +/* $Id: apc_cache.c,v 3.105 2006/02/25 19:50:33 rasmus Exp $ */ #include "apc_cache.h" #include "apc_lock.h" @@ -70,6 +70,7 @@ int num_misses; /* total unsuccessful hits in cache */ slot_t* deleted_list; /* linked list of to-be-deleted slots */ time_t start_time; /* time the above counters were reset */ + int expunges; /* total number of expunges */ }; /* }}} */ @@ -281,6 +282,7 @@ cache->header->num_misses = 0; cache->header->deleted_list = NULL; cache->header->start_time = time(NULL); + cache->header->expunges = 0; cache->slots = (slot_t**) (((char*) cache->shmaddr) + sizeof(header_t)); cache->num_slots = num_slots; @@ -316,6 +318,7 @@ cache->header->num_hits = 0; cache->header->num_misses = 0; cache->header->start_time = time(NULL); + cache->header->expunges = 0; for (i = 0; i < cache->num_slots; i++) { slot_t* p = cache->slots[i]; @@ -332,6 +335,26 @@ /* {{{ apc_cache_expunge */ void apc_cache_expunge(apc_cache_t* cache, time_t t) { +#if 1 + int i; + if(!cache) return; + /* + Trying to delete only stale entries blows a million tiny little + holes in our cache causing excessive fragmentation. So let's + try just clearing it here instead and bumping the expunges count + to give us a hint that we need to tune the configuration. + */ + LOCK(cache); + cache->header->expunges++; + for (i = 0; i < cache->num_slots; i++) { + slot_t* p = cache->slots[i]; + while (p) { + remove_slot(cache, &p); + } + cache->slots[i] = NULL; + } + UNLOCK(cache); +#else int i; slot_t **p; @@ -373,6 +396,7 @@ } } UNLOCK(cache); +#endif } /* }}} */ @@ -852,6 +876,7 @@ info->list = NULL; info->deleted_list = NULL; info->start_time = cache->header->start_time; + info->expunges = cache->header->expunges; /* For each hashtable slot */ for (i = 0; i < info->num_slots; i++) { http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_cache.h?r1=3.32&r2=3.33&diff_format=u Index: pecl/apc/apc_cache.h diff -u pecl/apc/apc_cache.h:3.32 pecl/apc/apc_cache.h:3.33 --- pecl/apc/apc_cache.h:3.32 Sat Feb 25 09:02:56 2006 +++ pecl/apc/apc_cache.h Sat Feb 25 19:50:33 2006 @@ -26,7 +26,7 @@ */ -/* $Id: apc_cache.h,v 3.32 2006/02/25 09:02:56 rasmus Exp $ */ +/* $Id: apc_cache.h,v 3.33 2006/02/25 19:50:33 rasmus Exp $ */ #ifndef APC_CACHE_H #define APC_CACHE_H @@ -262,6 +262,7 @@ apc_cache_link_t* list; apc_cache_link_t* deleted_list; time_t start_time; + int expunges; }; /* }}} */ http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_sma.c?r1=1.37&r2=1.38&diff_format=u Index: pecl/apc/apc_sma.c diff -u pecl/apc/apc_sma.c:1.37 pecl/apc/apc_sma.c:1.38 --- pecl/apc/apc_sma.c:1.37 Sat Feb 25 15:22:42 2006 +++ pecl/apc/apc_sma.c Sat Feb 25 19:50:33 2006 @@ -26,7 +26,7 @@ */ -/* $Id: apc_sma.c,v 1.37 2006/02/25 15:22:42 rasmus Exp $ */ +/* $Id: apc_sma.c,v 1.38 2006/02/25 19:50:33 rasmus Exp $ */ #include "apc_sma.h" #include "apc.h" @@ -61,6 +61,9 @@ struct header_t { size_t segsize; /* size of entire segment */ size_t avail; /* bytes available (not necessarily contiguous) */ +#if ALLOC_DISTRIBUTION + size_t adist[30]; +#endif }; typedef struct block_t block_t; @@ -99,6 +102,10 @@ size_t realsize; /* actual size of block needed, including header */ size_t minsize; /* for finding best fit */ +#if 1 + if(size < 8) realsize = 8; + else realsize = size; +#else if(size < 0x40) { realsize = 0x40; } else { @@ -126,6 +133,7 @@ realsize = p; } } +#endif realsize = alignword(max(realsize + alignword(sizeof(int)), sizeof(block_t))); /* @@ -167,8 +175,11 @@ /* update the block header */ header->avail -= realsize; +#if ALLOC_DISTRIBUTION + header->adist[(int)(log(size)/log(2))]++; +#endif - if (cur->size == realsize || ((cur->size - realsize) < 0x40)) { + if (cur->size == realsize || ((cur->size - realsize) < 0x20)) { /* cur is a perfect fit for realsize; just unlink it */ prv->next = cur->next; } @@ -289,7 +300,12 @@ header->segsize = sma_segsize; header->avail = sma_segsize - sizeof(header_t) - sizeof(block_t) - alignword(sizeof(int)); - +#if ALLOC_DISTRIBUTION + { + int j; + for(j=0; j<30; j++) header->adist[j] = 0; + } +#endif block = BLOCKAT(sizeof(header_t)); block->size = 0; block->next = sizeof(header_t) + sizeof(block_t); @@ -491,6 +507,12 @@ } /* }}} */ +#if ALLOC_DISTRIBUTION +size_t *apc_sma_get_alloc_distribution(void) { + header_t* header = (header_t*) sma_shmaddrs[0]; + return header->adist; +} + /* {{{ apc_sma_unlock */ void apc_sma_unlock() { http://cvs.php.net/viewcvs.cgi/pecl/apc/apc_sma.h?r1=1.12&r2=1.13&diff_format=u Index: pecl/apc/apc_sma.h diff -u pecl/apc/apc_sma.h:1.12 pecl/apc/apc_sma.h:1.13 --- pecl/apc/apc_sma.h:1.12 Sat Feb 25 17:59:45 2006 +++ pecl/apc/apc_sma.h Sat Feb 25 19:50:33 2006 @@ -25,11 +25,13 @@ */ -/* $Id: apc_sma.h,v 1.12 2006/02/25 17:59:45 rasmus Exp $ */ +/* $Id: apc_sma.h,v 1.13 2006/02/25 19:50:33 rasmus Exp $ */ #ifndef APC_SMA_H #define APC_SMA_H +#define ALLOC_DISTRIBUTION 0 + #include "apc.h" /* Simple shared memory allocator */ @@ -41,6 +43,9 @@ extern char* apc_sma_strdup(const char *s); extern void apc_sma_free(void* p); extern void apc_sma_unlock(); +#if ALLOC_DISTRIBUTION +extern size_t *apc_sma_get_alloc_distribution(); +#endif /* {{{ struct definition: apc_sma_link_t */ typedef struct apc_sma_link_t apc_sma_link_t; http://cvs.php.net/viewcvs.cgi/pecl/apc/php_apc.c?r1=3.79&r2=3.80&diff_format=u Index: pecl/apc/php_apc.c diff -u pecl/apc/php_apc.c:3.79 pecl/apc/php_apc.c:3.80 --- pecl/apc/php_apc.c:3.79 Thu Feb 16 23:31:43 2006 +++ pecl/apc/php_apc.c Sat Feb 25 19:50:33 2006 @@ -26,7 +26,7 @@ */ -/* $Id: php_apc.c,v 3.79 2006/02/16 23:31:43 iliaa Exp $ */ +/* $Id: php_apc.c,v 3.80 2006/02/25 19:50:33 rasmus Exp $ */ #include "php_apc.h" #include "apc_zend.h" @@ -167,7 +167,7 @@ #else php_info_print_table_row(2, "MMAP Support", "Disabled"); #endif - php_info_print_table_row(2, "Revision", "$Revision: 3.79 $"); + php_info_print_table_row(2, "Revision", "$Revision: 3.80 $"); php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); @@ -260,6 +260,7 @@ add_assoc_long(return_value, "num_hits", info->num_hits); add_assoc_long(return_value, "num_misses", info->num_misses); add_assoc_long(return_value, "start_time", info->start_time); + add_assoc_long(return_value, "expunges", info->expunges); ALLOC_INIT_ZVAL(list); array_init(list); @@ -365,7 +366,18 @@ add_assoc_long(return_value, "num_seg", info->num_seg); add_assoc_long(return_value, "seg_size", info->seg_size); add_assoc_long(return_value, "avail_mem", apc_sma_get_avail_mem()); - +#if ALLOC_DISTRIBUTION + { + size_t *adist = apc_sma_get_alloc_distribution(); + zval* list; + ALLOC_INIT_ZVAL(list); + array_init(list); + for(i=0; i<30; i++) { + add_next_index_long(list, adist[i]); + } + add_assoc_zval(return_value, "adist", list); + } +#endif ALLOC_INIT_ZVAL(block_lists); array_init(block_lists);