Changeset 1135 for trunk/mod_cacher/xc_cacher.c
- Timestamp:
- 2012-08-09T11:04:02+02:00 (10 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
mod_cacher/xc_cacher.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
trunk/mod_cacher/xc_cacher.c
r1132 r1135 100 100 struct _xc_lock_t *lck; 101 101 struct _xc_shm_t *shm; /* which shm contains us */ 102 struct _xc_mem_t *mem; /* which mem contains us */102 xc_allocator_t *allocator; 103 103 104 104 xc_hash_t *hentry; /* hash settings to entry */ … … 125 125 static zend_ulong xc_var_gc_interval = 0; 126 126 127 static char *xc_php_allocator = NULL; 128 static char *xc_var_allocator = NULL; 129 127 130 /* total size */ 128 131 static zend_ulong xc_php_size = 0; … … 163 166 php->hits = 0; 164 167 php->refcount = 0; 165 stored_php = xc_processor_store_xc_entry_data_php_t(cache->shm, cache-> mem, php TSRMLS_CC);168 stored_php = xc_processor_store_xc_entry_data_php_t(cache->shm, cache->allocator, php TSRMLS_CC); 166 169 if (stored_php) { 167 170 xc_php_add_unlocked(cache->cached, stored_php); … … 188 191 static void xc_php_free_unlocked(xc_cache_t *cache, xc_entry_data_php_t *php) /* {{{ */ 189 192 { 190 cache-> mem->handlers->free(cache->mem, (xc_entry_data_php_t *)php);193 cache->allocator->vtable->free(cache->allocator, (xc_entry_data_php_t *)php); 191 194 } 192 195 /* }}} */ … … 310 313 entry->atime = XG(request_time); 311 314 stored_entry = type == XC_TYPE_PHP 312 ? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache->shm, cache-> mem, (xc_entry_php_t *) entry TSRMLS_CC)313 : (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache->shm, cache-> mem, (xc_entry_var_t *) entry TSRMLS_CC);315 ? (xc_entry_t *) xc_processor_store_xc_entry_php_t(cache->shm, cache->allocator, (xc_entry_php_t *) entry TSRMLS_CC) 316 : (xc_entry_t *) xc_processor_store_xc_entry_var_t(cache->shm, cache->allocator, (xc_entry_var_t *) entry TSRMLS_CC); 314 317 if (stored_entry) { 315 318 xc_entry_add_unlocked(cache->cached, entryslotid, stored_entry); … … 338 341 xc_php_release_unlocked(cache, ((xc_entry_php_t *) entry)->php); 339 342 } 340 cache-> mem->handlers->free(cache->mem, (xc_entry_t *)entry);343 cache->allocator->vtable->free(cache->allocator, (xc_entry_t *)entry); 341 344 } 342 345 /* }}} */ … … 604 607 zval *blocks, *hits; 605 608 size_t i; 606 const xc_ block_t *b;609 const xc_allocator_block_t *b; 607 610 #ifndef NDEBUG 608 611 xc_memsize_t avail = 0; 609 612 #endif 610 const xc_ mem_t *mem = cache->mem;611 const xc_ mem_handlers_t *handlers = mem->handlers;613 const xc_allocator_t *allocator = cache->allocator; 614 const xc_allocator_vtable_t *vtable = allocator->vtable; 612 615 zend_ulong interval; 613 616 const xc_cached_t *cached = cache->cached; … … 657 660 array_init(blocks); 658 661 659 add_assoc_long_ex(return_value, ZEND_STRS("size"), handlers->size(mem));660 add_assoc_long_ex(return_value, ZEND_STRS("avail"), handlers->avail(mem));662 add_assoc_long_ex(return_value, ZEND_STRS("size"), vtable->size(allocator)); 663 add_assoc_long_ex(return_value, ZEND_STRS("avail"), vtable->avail(allocator)); 661 664 add_assoc_bool_ex(return_value, ZEND_STRS("can_readonly"), xc_readonly_protection); 662 665 663 for (b = handlers->freeblock_first(mem); b; b = handlers->freeblock_next(b)) {666 for (b = vtable->freeblock_first(allocator); b; b = vtable->freeblock_next(b)) { 664 667 zval *bi; 665 668 … … 667 670 array_init(bi); 668 671 669 add_assoc_long_ex(bi, ZEND_STRS("size"), handlers->block_size(b));670 add_assoc_long_ex(bi, ZEND_STRS("offset"), handlers->block_offset(mem, b));672 add_assoc_long_ex(bi, ZEND_STRS("size"), vtable->block_size(b)); 673 add_assoc_long_ex(bi, ZEND_STRS("offset"), vtable->block_offset(allocator, b)); 671 674 add_next_index_zval(blocks, bi); 672 675 #ifndef NDEBUG 673 avail += handlers->block_size(b);676 avail += vtable->block_size(b); 674 677 #endif 675 678 } 676 679 add_assoc_zval_ex(return_value, ZEND_STRS("free_blocks"), blocks); 677 680 #ifndef NDEBUG 678 assert(avail == handlers->avail(mem));681 assert(avail == vtable->avail(allocator)); 679 682 #endif 680 683 } … … 2311 2314 /* do NOT touch cached data */ 2312 2315 shm = cache->shm; 2313 cache->shm->handlers->memdestroy(cache-> mem);2316 cache->shm->handlers->memdestroy(cache->allocator); 2314 2317 } 2315 2318 } … … 2318 2321 } 2319 2322 /* }}} */ 2320 static xc_cache_t *xc_cache_init(xc_shm_t *shm, xc_hash_t *hcache, xc_hash_t *hentry, xc_hash_t *hphp, xc_shmsize_t shmsize) /* {{{ */2323 static xc_cache_t *xc_cache_init(xc_shm_t *shm, const char *allocator_name, xc_hash_t *hcache, xc_hash_t *hentry, xc_hash_t *hphp, xc_shmsize_t shmsize) /* {{{ */ 2321 2324 { 2322 2325 xc_cache_t *caches = NULL; 2323 xc_ mem_t *mem;2326 xc_allocator_t *allocator; 2324 2327 time_t now = time(NULL); 2325 2328 size_t i; … … 2343 2346 for (i = 0; i < hcache->size; i ++) { 2344 2347 xc_cache_t *cache = &caches[i]; 2345 CHECK(mem = shm->handlers->meminit(shm, memsize), "Failed init memory allocator"); 2346 CHECK(cache->cached = mem->handlers->calloc(mem, 1, sizeof(xc_cached_t)), "cache OOM"); 2347 CHECK(cache->cached->entries = mem->handlers->calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 2348 CHECK(allocator = shm->handlers->meminit(shm, memsize), "Failed init shm"); 2349 if (!(allocator->vtable = xc_allocator_find(allocator_name))) { 2350 zend_error(E_ERROR, "Allocator %s not found", allocator_name); 2351 goto err; 2352 } 2353 CHECK(allocator->vtable->init(shm, allocator, memsize), "Failed init allocator"); 2354 CHECK(cache->cached = allocator->vtable->calloc(allocator, 1, sizeof(xc_cached_t)), "cache OOM"); 2355 CHECK(cache->cached->entries = allocator->vtable->calloc(allocator, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); 2348 2356 if (hphp) { 2349 CHECK(cache->cached->phps = mem->handlers->calloc(mem, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM");2357 CHECK(cache->cached->phps = allocator->vtable->calloc(allocator, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM"); 2350 2358 } 2351 2359 CHECK(cache->lck = xc_lock_init(NULL), "can't create lock"); … … 2355 2363 cache->hphp = hphp; 2356 2364 cache->shm = shm; 2357 cache-> mem = mem;2365 cache->allocator = allocator; 2358 2366 cache->cacheid = i; 2359 2367 cache->cached->last_gc_deletes = now; … … 2413 2421 2414 2422 if (xc_php_size) { 2415 CHECK(xc_php_caches = xc_cache_init(shm, &xc_php_hcache, &xc_php_hentry, &xc_php_hentry, xc_php_size), "failed init opcode cache");2423 CHECK(xc_php_caches = xc_cache_init(shm, xc_php_allocator, &xc_php_hcache, &xc_php_hentry, &xc_php_hentry, xc_php_size), "failed init opcode cache"); 2416 2424 } 2417 2425 2418 2426 if (xc_var_size) { 2419 CHECK(xc_var_caches = xc_cache_init(shm, &xc_var_hcache, &xc_var_hentry, NULL, xc_var_size), "failed init variable cache");2427 CHECK(xc_var_caches = xc_cache_init(shm, xc_var_allocator, &xc_var_hcache, &xc_var_hentry, NULL, xc_var_size), "failed init variable cache"); 2420 2428 } 2421 2429 } … … 3184 3192 PHP_INI_ENTRY1 ("xcache.count", "1", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL) 3185 3193 PHP_INI_ENTRY1 ("xcache.slots", "8K", PHP_INI_SYSTEM, xcache_OnUpdateDummy, NULL) 3194 PHP_INI_ENTRY1 ("xcache.allocator", "bestfit", PHP_INI_SYSTEM, xcache_OnUpdateString, &xc_php_allocator) 3186 3195 PHP_INI_ENTRY1 ("xcache.ttl", "0", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_php_ttl) 3187 3196 PHP_INI_ENTRY1 ("xcache.gc_interval", "0", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_php_gc_interval) … … 3194 3203 PHP_INI_ENTRY1 ("xcache.var_maxttl", "0", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_var_maxttl) 3195 3204 PHP_INI_ENTRY1 ("xcache.var_gc_interval", "120", PHP_INI_SYSTEM, xcache_OnUpdateULong, &xc_var_gc_interval) 3205 PHP_INI_ENTRY1 ("xcache.var_allocator", "bestfit", PHP_INI_SYSTEM, xcache_OnUpdateString, &xc_var_allocator) 3196 3206 STD_PHP_INI_ENTRY ("xcache.var_ttl", "0", PHP_INI_ALL, OnUpdateLong, var_ttl, zend_xcache_globals, xcache_globals) 3197 3207 PHP_INI_END() … … 3360 3370 pefree(xc_shm_scheme, 1); 3361 3371 xc_shm_scheme = NULL; 3372 } 3373 if (xc_php_allocator) { 3374 pefree(xc_php_allocator, 1); 3375 xc_php_allocator = NULL; 3376 } 3377 if (xc_var_allocator) { 3378 pefree(xc_var_allocator, 1); 3379 xc_var_allocator = NULL; 3362 3380 } 3363 3381
Note: See TracChangeset
for help on using the changeset viewer.

