Changeset 1135
- Timestamp:
- 08/09/2012 11:04:02 AM (9 months ago)
- Location:
- trunk
- Files:
-
- 11 modified
- 2 moved
-
. (modified) (1 prop)
-
Makefile.frag.deps (modified) (1 diff)
-
config.m4 (modified) (2 diffs)
-
config.w32 (modified) (2 diffs)
-
devel/test.mak (modified) (1 diff)
-
mod_cacher/xc_cacher.c (modified) (17 diffs)
-
processor/head.m4 (modified) (5 diffs)
-
xcache/xc_allocator.c (moved) (moved from trunk/xcache/xc_mem.c) (5 diffs)
-
xcache/xc_allocator.h (moved) (moved from trunk/xcache/xc_mem.h) (2 diffs)
-
xcache/xc_malloc.c (modified) (9 diffs)
-
xcache/xc_shm.c (modified) (2 diffs)
-
xcache/xc_shm.h (modified) (4 diffs)
-
xcache/xc_shm_mmap.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
trunk/Makefile.frag.deps
r1114 r1135 1 $(XCACHE_INCLUDES_I) $(builddir)/includes.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_ mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h1 $(XCACHE_INCLUDES_I) $(builddir)/includes.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h 2 2 $(builddir)/mod_assembler/xc_assembler.lo: 3 $(builddir)/mod_cacher/xc_cacher.lo: $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_ mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/util/xc_align.h4 $(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_ mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h3 $(builddir)/mod_cacher/xc_cacher.lo: $(srcdir)/mod_cacher/xc_cacher.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_vector.h $(srcdir)/util/xc_align.h 4 $(builddir)/mod_coverager/xc_coverager.lo: $(srcdir)/mod_coverager/xc_coverager.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h 5 5 $(builddir)/mod_decoder/xc_decoder.lo: 6 $(builddir)/mod_disassembler/xc_disassembler.lo: $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_ mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache.h $(srcdir)/mod_cacher/xc_cache.h6 $(builddir)/mod_disassembler/xc_disassembler.lo: $(srcdir)/mod_disassembler/xc_disassembler.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h 7 7 $(builddir)/mod_encoder/xc_encoder.lo: 8 $(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_ mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h8 $(builddir)/mod_optimizer/xc_optimizer.lo: $(srcdir)/mod_optimizer/xc_optimizer.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h 9 9 $(builddir)/util/xc_stack.lo: $(srcdir)/util/xc_trace.h $(srcdir)/util/xc_stack.h 10 10 $(builddir)/util/xc_trace.lo: $(srcdir)/util/xc_trace.h 11 $(builddir)/xcache.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_foreachcoresig.h 11 $(builddir)/xcache.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_ini.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_foreachcoresig.h 12 $(builddir)/xcache/xc_allocator_bestfit.lo: $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h 13 $(builddir)/xcache/xc_allocator.lo: $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h 12 14 $(builddir)/xcache/xc_compatibility.lo: $(srcdir)/xcache/xc_compatibility.h 13 $(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_ mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h14 $(builddir)/xcache/xc_extension.lo: $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_ mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h15 $(builddir)/xcache/xc_const_string.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_const_string_opcodes_php5.4.h 16 $(builddir)/xcache/xc_extension.lo: $(srcdir)/xcache/xc_extension.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_trace.h 15 17 $(builddir)/xcache/xc_ini.lo: $(srcdir)/xcache/xc_ini.h 16 $(builddir)/xcache/xc_lock.lo: $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h 17 $(builddir)/xcache/xc_malloc.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h 18 $(builddir)/xcache/xc_mem.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/util/xc_align.h $(srcdir)/util/xc_trace.h 19 $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec_def.h 20 $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C) $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(XCACHE_PROC_H) $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h 21 $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h 22 $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h 23 $(builddir)/xcache/xc_shm_mmap.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h 24 $(builddir)/xcache/xc_utils.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_mem.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/util/xc_trace.h 18 $(builddir)/xcache/xc_lock.lo: $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h 19 $(builddir)/xcache/xc_malloc.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h 20 $(builddir)/xcache/xc_opcode_spec.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_opcode_spec_def.h 21 $(builddir)/xcache/xc_processor.lo: $(XCACHE_PROC_C) $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/mod_cacher/xc_cache.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_allocator.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_const_string.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/util/xc_align.h $(XCACHE_PROC_H) $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h 22 $(builddir)/xcache/xc_sandbox.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_sandbox.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h 23 $(builddir)/xcache/xc_shm.lo: $(srcdir)/xcache/xc_shm.h 24 $(builddir)/xcache/xc_shm_mmap.lo: $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_compatibility.h 25 $(builddir)/xcache/xc_utils.lo: $(srcdir)/xcache.h $(srcdir)/xcache/xc_shm.h $(srcdir)/xcache/xc_lock.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache_globals.h $(srcdir)/util/xc_stack.h $(srcdir)/xcache/xc_utils.h $(srcdir)/xcache/xc_compatibility.h $(srcdir)/xcache/xc_opcode_spec.h $(srcdir)/util/xc_trace.h -
trunk/config.m4
r1040 r1135 32 32 done 33 33 for i in \ 34 xc_allocator.c \ 35 xc_allocator_bestfit.c \ 34 36 xc_compatibility.c \ 35 37 xc_const_string.c \ … … 37 39 xc_ini.c \ 38 40 xc_lock.c \ 39 xc_mem.c \40 41 xc_opcode_spec.c \ 41 42 xc_processor.c \ -
trunk/config.w32
r1108 r1135 19 19 20 20 ADD_SOURCES(configure_module_dirname + "/xcache", " \ 21 xc_allocator.c \ 22 xc_allocator_bestfit.c \ 21 23 xc_compatibility.c \ 22 24 xc_const_string.c \ … … 24 26 xc_ini.c \ 25 27 xc_lock.c \ 26 xc_mem.c \27 28 xc_opcode_spec.c \ 28 29 xc_processor.c \ -
trunk/devel/test.mak
r998 r1135 1 1 #! /usr/bin/make -f 2 2 3 EXES= mem_test4 OBJS= mem.o3 EXES=allocator_test 4 OBJS=allocator.o 5 5 CC=gcc 6 CFLAGS=-g -O0 -I. -D TEST - Wall6 CFLAGS=-g -O0 -I. -D TEST -D HAVE_XCACHE_TEST -Wall 7 7 TEST=valgrind 8 8 9 all: mem9 all: allocator 10 10 11 mem_test: xcache/xc_mem.c xcache/xc_mem.hutil/xc_trace.c util/xc_trace.h12 $(CC) $(CFLAGS) -o mem_test xcache/xc_mem.c util/xc_trace.c11 allocator_test: xcache/xc_allocator.h xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c util/xc_trace.h 12 $(CC) $(CFLAGS) -o allocator_test xcache/xc_allocator.c xcache/xc_malloc.c xcache/xc_allocator_bestfit.c util/xc_trace.c 13 13 14 mem: mem_test15 $(TEST) ./ mem_test14 allocator: allocator_test 15 $(TEST) ./allocator_test 16 16 17 17 clean: -
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 -
trunk/processor/head.m4
r1132 r1135 14 14 /* export: #include "mod_cacher/xc_cache.h" :export */ 15 15 #include "mod_cacher/xc_cache.h" 16 #include "util/xc_align.h" 16 /* export: #include "xcache/xc_shm.h" :export */ 17 #include "xcache/xc_shm.h" 18 /* export: #include "xcache/xc_allocator.h" :export */ 19 #include "xcache/xc_allocator.h" 17 20 #include "xcache/xc_const_string.h" 18 21 #include "xcache/xc_utils.h" 22 #include "util/xc_align.h" 19 23 #include "xc_processor.h" 20 24 #include "xcache_globals.h" … … 95 99 const xc_entry_data_php_t *php_dst; 96 100 xc_shm_t *shm; 97 xc_ mem_t *mem;101 xc_allocator_t *allocator; 98 102 const zend_class_entry *cache_ce; 99 103 zend_uint cache_class_index; … … 395 399 dnl ================ export API 396 400 define(`DEFINE_STORE_API', ` 397 /* export: $1 *xc_processor_store_$1(xc_shm_t *shm, xc_ mem_t *mem, $1 *src TSRMLS_DC); :export {{{ */398 $1 *xc_processor_store_$1(xc_shm_t *shm, xc_ mem_t *mem, $1 *src TSRMLS_DC) {401 /* export: $1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC); :export {{{ */ 402 $1 *xc_processor_store_$1(xc_shm_t *shm, xc_allocator_t *allocator, $1 *src TSRMLS_DC) { 399 403 $1 *dst; 400 404 xc_processor_t processor; … … 403 407 processor.reference = 1; 404 408 processor.shm = shm; 405 processor. mem = mem;409 processor.allocator = allocator; 406 410 407 411 IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);') … … 440 444 } 441 445 442 /* mem:) */443 processor.p = (char *) processor. mem->handlers->malloc(processor.mem, processor.size);446 /* allocator :) */ 447 processor.p = (char *) processor.allocator->vtable->malloc(processor.allocator, processor.size); 444 448 if (processor.p == NULL) { 445 449 dst = NULL; -
trunk/xcache/xc_allocator.c
r1044 r1135 1 #ifdef TEST 2 # include <limits.h> 3 # include <stdio.h> 4 # define XCACHE_DEBUG 5 typedef int zend_bool; 6 # define ZEND_ATTRIBUTE_PTR_FORMAT(a, b, c) 7 # define zend_error(type, error) fprintf(stderr, "%s", error) 8 #else 9 # include <php.h> 1 #include "xc_allocator.h" 2 #include <string.h> 3 #include <stdio.h> 4 5 typedef struct { 6 const char *name; 7 const xc_allocator_vtable_t *allocator_vtable; 8 } xc_allocator_info_t; 9 static xc_allocator_info_t xc_allocator_infos[10]; 10 11 int xc_allocator_register(const char *name, const xc_allocator_vtable_t *allocator_vtable) /* {{{ */ 12 { 13 size_t i; 14 for (i = 0; i < sizeof(xc_allocator_infos) / sizeof(xc_allocator_infos[0]); i ++) { 15 if (!xc_allocator_infos[i].name) { 16 xc_allocator_infos[i].name = name; 17 xc_allocator_infos[i].allocator_vtable = allocator_vtable; 18 return 1; 19 } 20 } 21 return 0; 22 } 23 /* }}} */ 24 const xc_allocator_vtable_t *xc_allocator_find(const char *name) /* {{{ */ 25 { 26 size_t i; 27 for (i = 0; i < sizeof(xc_allocator_infos) / sizeof(xc_allocator_infos[0]) && xc_allocator_infos[i].name; i ++) { 28 if (strcmp(xc_allocator_infos[i].name, name) == 0) { 29 return xc_allocator_infos[i].allocator_vtable; 30 } 31 } 32 return NULL; 33 } 34 /* }}} */ 35 void xc_allocator_init() /* {{{ */ 36 { 37 extern void xc_allocator_bestfit_register(); 38 #ifdef HAVE_XCACHE_TEST 39 extern void xc_allocator_malloc_register(); 10 40 #endif 11 41 12 #ifdef XCACHE_DEBUG 13 # define ALLOC_DEBUG_BLOCK_CHECK 42 memset(xc_allocator_infos, 0, sizeof(xc_allocator_infos)); 43 xc_allocator_bestfit_register(); 44 #ifdef HAVE_XCACHE_TEST 45 xc_allocator_malloc_register(); 14 46 #endif 15 16 17 #include <assert.h>18 #include <stdlib.h>19 #include <string.h>20 #define XC_MEMBLOCK_IMPL _xc_mem_block_t21 #define XC_MEM_IMPL _xc_mem_mem_t22 #include "xc_shm.h"23 #include "util/xc_align.h"24 #include "util/xc_trace.h"25 26 #if 027 #undef ALLOC_DEBUG_BLOCK_CHECK28 #endif29 30 #define CHAR_PTR(p) ((char *) (p))31 #define PADD(p, a) (CHAR_PTR(p) + a)32 #define PSUB(p1, p2) (CHAR_PTR(p1) - CHAR_PTR(p2))33 34 /* {{{ mem */35 struct _xc_mem_block_t {36 #ifdef ALLOC_DEBUG_BLOCK_CHECK37 unsigned int magic;38 #endif39 xc_memsize_t size; /* reserved even after alloc */40 xc_block_t *next; /* not used after alloc */41 };42 43 struct _xc_mem_mem_t {44 const xc_mem_handlers_t *handlers;45 xc_shm_t *shm;46 xc_memsize_t size;47 xc_memsize_t avail; /* total free */48 xc_block_t headblock[1]; /* just as a pointer to first block*/49 };50 51 #ifndef XtOffsetOf52 # include <linux/stddef.h>53 # define XtOffsetOf(s_type, field) offsetof(s_type, field)54 #endif55 56 #define SizeOf(type, field) sizeof( ((type *) 0)->field )57 #define BLOCK_HEADER_SIZE() (ALIGN( XtOffsetOf(xc_block_t, size) + SizeOf(xc_block_t, size) ))58 59 #define BLOCK_MAGIC ((unsigned int) 0x87655678)60 61 /* }}} */62 static inline void xc_block_setup(xc_block_t *b, xc_memsize_t size, xc_block_t *next) /* {{{ */63 {64 #ifdef ALLOC_DEBUG_BLOCK_CHECK65 b->magic = BLOCK_MAGIC;66 #endif67 b->size = size;68 b->next = next;69 47 } 70 48 /* }}} */ 71 #ifdef ALLOC_DEBUG_BLOCK_CHECK72 static void xc_block_check(xc_block_t *b) /* {{{ */73 {74 if (b->magic != BLOCK_MAGIC) {75 fprintf(stderr, "0x%X != 0x%X magic wrong \n", b->magic, BLOCK_MAGIC);76 }77 }78 /* }}} */79 #else80 # define xc_block_check(b) do { } while(0)81 #endif82 83 84 static XC_MEM_MALLOC(xc_mem_malloc) /* {{{ */85 {86 xc_block_t *prev, *cur;87 xc_block_t *newb, *b;88 xc_memsize_t realsize;89 xc_memsize_t minsize;90 void *p;91 /* [xc_block_t:size|size] */92 realsize = BLOCK_HEADER_SIZE() + size;93 /* realsize is ALIGNed so next block start at ALIGNed address */94 realsize = ALIGN(realsize);95 96 TRACE("avail: %lu (%luKB). Allocate size: %lu realsize: %lu (%luKB)"97 , mem->avail, mem->avail / 102498 , size99 , realsize, realsize / 1024100 );101 do {102 p = NULL;103 if (mem->avail < realsize) {104 TRACE("%s", " oom");105 break;106 }107 108 b = NULL;109 minsize = ULONG_MAX;110 111 /* prev|cur */112 113 for (prev = mem->headblock; prev->next; prev = cur) {114 /* while (prev->next != 0) { */115 cur = prev->next;116 xc_block_check(cur);117 if (cur->size == realsize) {118 /* found a perfect fit, stop searching */119 b = prev;120 break;121 }122 /* make sure we can split on the block */123 else if (cur->size > (sizeof(xc_block_t) + realsize) &&124 cur->size < minsize) {125 /* cur is acceptable and memller */126 b = prev;127 minsize = cur->size;128 }129 prev = cur;130 }131 132 if (b == NULL) {133 TRACE("%s", " no fit chunk");134 break;135 }136 137 prev = b;138 139 cur = prev->next;140 p = PADD(cur, BLOCK_HEADER_SIZE());141 142 /* update the block header */143 mem->avail -= realsize;144 145 /* perfect fit, just unlink */146 if (cur->size == realsize) {147 prev->next = cur->next;148 TRACE(" perfect fit. Got: %p", p);149 break;150 }151 152 /* make new free block after alloced space */153 154 /* save, as it might be overwrited by newb (cur->size is ok) */155 b = cur->next;156 157 /* prev|cur |next=b */158 159 newb = (xc_block_t *)PADD(cur, realsize);160 xc_block_setup(newb, cur->size - realsize, b);161 cur->size = realsize;162 /* prev|cur|newb|next163 * `--^164 */165 166 TRACE(" -> avail: %lu (%luKB). new next: %p offset: %lu %luKB. Got: %p"167 , mem->avail, mem->avail / 1024168 , newb169 , PSUB(newb, mem), PSUB(newb, mem) / 1024170 , p171 );172 prev->next = newb;173 /* prev|cur|newb|next174 * `-----^175 */176 177 } while (0);178 179 return p;180 }181 /* }}} */182 static XC_MEM_FREE(xc_mem_free) /* {{{ return block size freed */183 {184 xc_block_t *cur, *b;185 int size;186 187 cur = (xc_block_t *) (CHAR_PTR(p) - BLOCK_HEADER_SIZE());188 TRACE("freeing: %p, size=%lu", p, cur->size);189 xc_block_check(cur);190 assert((char*)mem < (char*)cur && (char*)cur < (char*)mem + mem->size);191 192 /* find free block right before the p */193 b = mem->headblock;194 while (b->next != 0 && b->next < cur) {195 b = b->next;196 }197 198 /* restore block */199 cur->next = b->next;200 b->next = cur;201 size = cur->size;202 203 TRACE(" avail %lu (%luKB)", mem->avail, mem->avail / 1024);204 mem->avail += size;205 206 /* combine prev|cur */207 if (PADD(b, b->size) == (char *)cur) {208 b->size += cur->size;209 b->next = cur->next;210 cur = b;211 TRACE("%s", " combine prev");212 }213 214 /* combine cur|next */215 b = cur->next;216 if (PADD(cur, cur->size) == (char *)b) {217 cur->size += b->size;218 cur->next = b->next;219 TRACE("%s", " combine next");220 }221 TRACE(" -> avail %lu (%luKB)", mem->avail, mem->avail / 1024);222 return size;223 }224 /* }}} */225 static XC_MEM_CALLOC(xc_mem_calloc) /* {{{ */226 {227 xc_memsize_t realsize = memb * size;228 void *p = xc_mem_malloc(mem, realsize);229 230 if (p) {231 memset(p, 0, realsize);232 }233 return p;234 }235 /* }}} */236 static XC_MEM_REALLOC(xc_mem_realloc) /* {{{ */237 {238 void *newp = xc_mem_malloc(mem, size);239 if (p && newp) {240 memcpy(newp, p, size);241 xc_mem_free(mem, p);242 }243 return newp;244 }245 /* }}} */246 static XC_MEM_STRNDUP(xc_mem_strndup) /* {{{ */247 {248 void *p = xc_mem_malloc(mem, len + 1);249 if (p) {250 memcpy(p, str, len + 1);251 }252 return p;253 }254 /* }}} */255 static XC_MEM_STRDUP(xc_mem_strdup) /* {{{ */256 {257 return xc_mem_strndup(mem, str, strlen(str));258 }259 /* }}} */260 261 static XC_MEM_AVAIL(xc_mem_avail) /* {{{ */262 {263 return mem->avail;264 }265 /* }}} */266 static XC_MEM_SIZE(xc_mem_size) /* {{{ */267 {268 return mem->size;269 }270 /* }}} */271 272 static XC_MEM_FREEBLOCK_FIRST(xc_mem_freeblock_first) /* {{{ */273 {274 return mem->headblock->next;275 }276 /* }}} */277 XC_MEM_FREEBLOCK_NEXT(xc_mem_freeblock_next) /* {{{ */278 {279 return block->next;280 }281 /* }}} */282 XC_MEM_BLOCK_SIZE(xc_mem_block_size) /* {{{ */283 {284 return block->size;285 }286 /* }}} */287 XC_MEM_BLOCK_OFFSET(xc_mem_block_offset) /* {{{ */288 {289 return ((char *) block) - ((char *) mem);290 }291 /* }}} */292 293 static XC_MEM_INIT(xc_mem_init) /* {{{ */294 {295 xc_block_t *b;296 #define MINSIZE (ALIGN(sizeof(xc_mem_t)) + sizeof(xc_block_t))297 /* requires at least the header and 1 tail block */298 if (size < MINSIZE) {299 fprintf(stderr, "xc_mem_init requires %lu bytes at least\n", (unsigned long) MINSIZE);300 return NULL;301 }302 TRACE("size=%lu", size);303 mem->shm = shm;304 mem->size = size;305 mem->avail = size - MINSIZE;306 307 /* pointer to first block, right after ALIGNed header */308 b = mem->headblock;309 xc_block_setup(b, 0, (xc_block_t *) PADD(mem, ALIGN(sizeof(xc_mem_t))));310 311 /* first block*/312 b = b->next;313 xc_block_setup(b, mem->avail, 0);314 #undef MINSIZE315 316 return mem;317 }318 /* }}} */319 static XC_MEM_DESTROY(xc_mem_destroy) /* {{{ */320 {321 }322 /* }}} */323 324 49 #ifdef TEST 325 50 /* {{{ testing */ … … 333 58 #include <time.h> 334 59 335 int main()60 int testAllocator(const xc_allocator_vtable_t *allocator_vtable) 336 61 { 337 62 int count = 0; 338 63 void *p; 64 xc_allocator_t *allocator; 339 65 void *memory; 340 xc_mem_t *mem;341 66 void **ptrs; 342 67 int size, i; … … 350 75 CHECK(memory = malloc(size), "OOM"); 351 76 CHECK(ptrs = malloc(size * sizeof(void *)), "OOM"); 352 mem = (xc_mem_t *) memory; 353 CHECK(mem = xc_mem_init(NULL, mem, size), "Failed init memory allocator"); 77 allocator = (xc_allocator_t *) memory; 78 allocator->vtable = allocator_vtable; 79 CHECK(allocator = allocator->vtable->init(NULL, allocator, size), "Failed init memory allocator"); 354 80 355 while ((p = xc_mem_malloc(mem, 1))) {81 while ((p = allocator->vtable->malloc(allocator, 1))) { 356 82 ptrs[count ++] = p; 357 83 } … … 361 87 i = (random() % count); 362 88 fprintf(stderr, "freeing %d: ", i); 363 xc_mem_free(mem, ptrs[i]);89 allocator->vtable->free(allocator, ptrs[i]); 364 90 ptrs[i] = ptrs[count - 1]; 365 91 count --; … … 371 97 } 372 98 /* }}} */ 373 #endif 374 375 typedef struct { 376 const char *name; 377 const xc_mem_handlers_t *handlers; 378 } xc_mem_scheme_t; 379 static xc_mem_scheme_t xc_mem_schemes[10]; 380 381 int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers) /* {{{ */ 99 int main() /* {{{ */ 382 100 { 383 101 int i; 384 for (i = 0; i < 10; i ++) { 385 if (!xc_mem_schemes[i].name) {386 xc_mem_schemes[i].name = name; 387 xc_mem_schemes[i].handlers = handlers;388 return 1;389 }102 103 xc_allocator_init(); 104 105 for (i = 0; i < sizeof(xc_allocator_infos) / sizeof(xc_allocator_infos[0]) && xc_allocator_infos[i].name; i ++) { 106 fprintf(stderr, "testing %s...\n", xc_allocator_infos[i].name); 107 testAllocator(xc_allocator_infos[i].allocator_vtable); 390 108 } 391 109 return 0; 392 110 } 393 111 /* }}} */ 394 const xc_mem_handlers_t *xc_mem_scheme_find(const char *name) /* {{{ */ 395 { 396 int i; 397 for (i = 0; i < 10 && xc_mem_schemes[i].name; i ++) { 398 if (strcmp(xc_mem_schemes[i].name, name) == 0) { 399 return xc_mem_schemes[i].handlers; 400 } 401 } 402 return NULL; 403 } 404 /* }}} */ 405 406 static xc_mem_handlers_t xc_mem_mem_handlers = XC_MEM_HANDLERS(mem); 407 void xc_shm_mem_init() /* {{{ */ 408 { 409 memset(xc_mem_schemes, 0, sizeof(xc_mem_schemes)); 410 411 if (xc_mem_scheme_register("mem", &xc_mem_mem_handlers) == 0) { 412 zend_error(E_ERROR, "XCache: failed to register mem mem_scheme"); 413 } 414 } 415 /* }}} */ 112 #endif -
trunk/xcache/xc_allocator.h
r1062 r1135 1 #ifndef XC_ALLOCATOR_H_155E773CA8AFC18F3CCCDCF0831EE41D 2 #define XC_ALLOCATOR_H_155E773CA8AFC18F3CCCDCF0831EE41D 3 4 #if _MSC_VER > 1000 5 #pragma once 6 #endif /* _MSC_VER > 1000 */ 7 1 8 #include "xc_shm.h" 2 9 3 typedef struct _xc_ mem_handlers_t xc_mem_handlers_t;10 typedef struct _xc_allocator_vtable_t xc_allocator_vtable_t; 4 11 5 #ifndef XC_MEM_IMPL6 struct _xc_ mem_t {7 const xc_ mem_handlers_t *handlers;8 xc_shm_t *shm;12 #ifndef _xc_allocator_t 13 struct _xc_allocator_t { 14 const xc_allocator_vtable_t *vtable; 15 xc_shm_t *shm; 9 16 }; 10 # define XC_MEM_IMPL _xc_mem_t11 17 #endif 12 18 13 #ifndef XC_MEMBLOCK_IMPL 14 # define XC_MEMBLOCK_IMPL _xc_block_t 15 #endif 16 typedef struct XC_MEM_IMPL xc_mem_t; 17 typedef struct XC_MEMBLOCK_IMPL xc_block_t; 19 typedef struct _xc_allocator_t xc_allocator_t; 20 typedef struct _xc_allocator_block_t xc_allocator_block_t; 18 21 typedef xc_shmsize_t xc_memsize_t; 19 22 20 /* shm::mem */ 21 #define XC_MEM_MALLOC(func) void *func(xc_mem_t *mem, xc_memsize_t size) 22 #define XC_MEM_FREE(func) xc_memsize_t func(xc_mem_t *mem, const void *p) 23 #define XC_MEM_CALLOC(func) void *func(xc_mem_t *mem, xc_memsize_t memb, xc_memsize_t size) 24 #define XC_MEM_REALLOC(func) void *func(xc_mem_t *mem, const void *p, xc_memsize_t size) 25 #define XC_MEM_STRNDUP(func) char *func(xc_mem_t *mem, const char *str, xc_memsize_t len) 26 #define XC_MEM_STRDUP(func) char *func(xc_mem_t *mem, const char *str) 27 #define XC_MEM_AVAIL(func) xc_memsize_t func(const xc_mem_t *mem) 28 #define XC_MEM_SIZE(func) xc_memsize_t func(const xc_mem_t *mem) 29 #define XC_MEM_FREEBLOCK_FIRST(func) const xc_block_t *func(const xc_mem_t *mem) 30 #define XC_MEM_FREEBLOCK_NEXT(func) const xc_block_t *func(const xc_block_t *block) 31 #define XC_MEM_BLOCK_SIZE(func) xc_memsize_t func(const xc_block_t *block) 32 #define XC_MEM_BLOCK_OFFSET(func) xc_memsize_t func(const xc_mem_t *mem, const xc_block_t *block) 23 /* allocator */ 24 #define XC_ALLOCATOR_MALLOC(func) void *func(xc_allocator_t *allocator, xc_memsize_t size) 25 #define XC_ALLOCATOR_FREE(func) xc_memsize_t func(xc_allocator_t *allocator, const void *p) 26 #define XC_ALLOCATOR_CALLOC(func) void *func(xc_allocator_t *allocator, xc_memsize_t memb, xc_memsize_t size) 27 #define XC_ALLOCATOR_REALLOC(func) void *func(xc_allocator_t *allocator, const void *p, xc_memsize_t size) 28 #define XC_ALLOCATOR_AVAIL(func) xc_memsize_t func(const xc_allocator_t *allocator) 29 #define XC_ALLOCATOR_SIZE(func) xc_memsize_t func(const xc_allocator_t *allocator) 30 #define XC_ALLOCATOR_FREEBLOCK_FIRST(func) const xc_allocator_block_t *func(const xc_allocator_t *allocator) 31 #define XC_ALLOCATOR_FREEBLOCK_NEXT(func) const xc_allocator_block_t *func(const xc_allocator_block_t *block) 32 #define XC_ALLOCATOR_BLOCK_SIZE(func) xc_memsize_t func(const xc_allocator_block_t *block) 33 #define XC_ALLOCATOR_BLOCK_OFFSET(func) xc_memsize_t func(const xc_allocator_t *allocator, const xc_allocator_block_t *block) 33 34 34 #define XC_ MEM_INIT(func) xc_mem_t *func(xc_shm_t *shm, xc_mem_t *mem, xc_memsize_t size)35 #define XC_ MEM_DESTROY(func) void func(xc_mem_t *mem)35 #define XC_ALLOCATOR_INIT(func) xc_allocator_t *func(xc_shm_t *shm, xc_allocator_t *allocator, xc_memsize_t size) 36 #define XC_ALLOCATOR_DESTROY(func) void func(xc_allocator_t *allocator) 36 37 37 #define XC_ MEM_HANDLERS(name) { \38 #define XC_ALLOCATOR_VTABLE(name) { \ 38 39 xc_##name##_malloc \ 39 40 , xc_##name##_free \ 40 41 , xc_##name##_calloc \ 41 42 , xc_##name##_realloc \ 42 , xc_##name##_strndup \43 , xc_##name##_strdup \44 43 , xc_##name##_avail \ 45 44 , xc_##name##_size \ … … 53 52 } 54 53 55 struct _xc_mem_handlers_t { 56 XC_MEM_MALLOC((*malloc)); 57 XC_MEM_FREE((*free)); 58 XC_MEM_CALLOC((*calloc)); 59 XC_MEM_REALLOC((*realloc)); 60 XC_MEM_STRNDUP((*strndup)); 61 XC_MEM_STRDUP((*strdup)); 62 XC_MEM_AVAIL((*avail)); 63 XC_MEM_SIZE((*size)); 64 XC_MEM_FREEBLOCK_FIRST((*freeblock_first)); 65 XC_MEM_FREEBLOCK_NEXT((*freeblock_next)); 66 XC_MEM_BLOCK_SIZE((*block_size)); 67 XC_MEM_BLOCK_OFFSET((*block_offset)); 54 struct _xc_allocator_vtable_t { 55 XC_ALLOCATOR_MALLOC((*malloc)); 56 XC_ALLOCATOR_FREE((*free)); 57 XC_ALLOCATOR_CALLOC((*calloc)); 58 XC_ALLOCATOR_REALLOC((*realloc)); 59 XC_ALLOCATOR_AVAIL((*avail)); 60 XC_ALLOCATOR_SIZE((*size)); 61 XC_ALLOCATOR_FREEBLOCK_FIRST((*freeblock_first)); 62 XC_ALLOCATOR_FREEBLOCK_NEXT((*freeblock_next)); 63 XC_ALLOCATOR_BLOCK_SIZE((*block_size)); 64 XC_ALLOCATOR_BLOCK_OFFSET((*block_offset)); 68 65 69 XC_ MEM_INIT((*init));70 XC_ MEM_DESTROY((*destroy));66 XC_ALLOCATOR_INIT((*init)); 67 XC_ALLOCATOR_DESTROY((*destroy)); 71 68 }; 72 69 73 int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers); 74 const xc_mem_handlers_t *xc_mem_scheme_find(const char *name); 70 int xc_allocator_register(const char *name, const xc_allocator_vtable_t *allocator_vtable); 71 const xc_allocator_vtable_t *xc_allocator_find(const char *name); 72 73 #endif /* XC_ALLOCATOR_H_155E773CA8AFC18F3CCCDCF0831EE41D */ -
trunk/xcache/xc_malloc.c
r1129 r1135 1 1 #define XC_SHM_IMPL _xc_malloc_shm_t 2 #define XC_MEM_IMPL _xc_malloc_mem_t2 #define _xc_allocator_t _xc_allocator_malloc_t 3 3 #include <stdlib.h> 4 4 #include <stdio.h> … … 9 9 #endif 10 10 #include "xc_shm.h" 11 #include "php.h" 12 #include "xc_utils.h" 11 #include "xc_allocator.h" 12 #ifndef TEST 13 #include "xcache.h" 14 #endif 13 15 #include "util/xc_align.h" 14 16 15 struct _xc_ malloc_mem_t {16 const xc_ mem_handlers_t *handlers;17 xc_shm_t *shm;17 struct _xc_allocator_malloc_t { 18 const xc_allocator_vtable_t *vtable; 19 xc_shm_t *shm; 18 20 xc_memsize_t size; 19 21 xc_memsize_t avail; /* total free */ … … 25 27 xc_shmsize_t size; 26 28 xc_shmsize_t memoffset; 29 #ifndef TEST 27 30 HashTable blocks; 31 #endif 28 32 }; 29 33 /* }}} */ 30 34 31 #define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0) 32 33 static void *xc_add_to_blocks(xc_mem_t *mem, void *p, size_t size) /* {{{ */ 35 #ifndef TEST 36 # define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0) 37 #else 38 # define CHECK(x, e) do { if ((x) == NULL) { fprintf(stderr, "%s\n", "XCache: " e); goto err; } } while (0) 39 #endif 40 41 static void *xc_add_to_blocks(xc_allocator_t *allocator, void *p, size_t size) /* {{{ */ 34 42 { 35 43 if (p) { 36 zend_hash_add(&mem->shm->blocks, (void *) &p, sizeof(p), (void *) &size, sizeof(size), NULL); 44 #ifdef TEST 45 allocator->avail -= size; 46 #else 47 zend_hash_add(&allocator->shm->blocks, (void *) &p, sizeof(p), (void *) &size, sizeof(size), NULL); 48 #endif 37 49 } 38 50 return p; 39 51 } 40 52 /* }}} */ 41 static void xc_del_from_blocks(xc_mem_t *mem, void *p) /* {{{ */ 42 { 43 zend_hash_del(&mem->shm->blocks, (void *) &p, sizeof(p)); 44 } 45 /* }}} */ 46 47 static XC_MEM_MALLOC(xc_malloc_malloc) /* {{{ */ 48 { 49 return xc_add_to_blocks(mem, malloc(size), size); 50 } 51 /* }}} */ 52 static XC_MEM_FREE(xc_malloc_free) /* {{{ return block size freed */ 53 { 54 xc_del_from_blocks(mem, (void *) p); 53 static void xc_del_from_blocks(xc_allocator_t *allocator, void *p) /* {{{ */ 54 { 55 #ifdef TEST 56 /* TODO: allocator->avail += size; */ 57 #else 58 zend_hash_del(&allocator->shm->blocks, (void *) &p, sizeof(p)); 59 #endif 60 } 61 /* }}} */ 62 63 static XC_ALLOCATOR_MALLOC(xc_allocator_malloc_malloc) /* {{{ */ 64 { 65 return xc_add_to_blocks(allocator, malloc(size), size); 66 } 67 /* }}} */ 68 static XC_ALLOCATOR_FREE(xc_allocator_malloc_free) /* {{{ return block size freed */ 69 { 70 xc_del_from_blocks(allocator, (void *) p); 55 71 free((void *) p); 56 72 return 0; 57 73 } 58 74 /* }}} */ 59 static XC_MEM_CALLOC(xc_malloc_calloc) /* {{{ */ 60 { 61 return xc_add_to_blocks(mem, calloc(memb, size), size); 62 } 63 /* }}} */ 64 static XC_MEM_REALLOC(xc_malloc_realloc) /* {{{ */ 65 { 66 return xc_add_to_blocks(mem, realloc((void *) p, size), size); 67 } 68 /* }}} */ 69 static XC_MEM_STRNDUP(xc_malloc_strndup) /* {{{ */ 70 { 71 char *p = xc_add_to_blocks(mem, malloc(len), len); 72 if (!p) { 73 return NULL; 74 } 75 return memcpy(p, str, len); 76 } 77 /* }}} */ 78 static XC_MEM_STRDUP(xc_malloc_strdup) /* {{{ */ 79 { 80 return xc_malloc_strndup(mem, str, strlen(str) + 1); 81 } 82 /* }}} */ 83 84 static XC_MEM_AVAIL(xc_malloc_avail) /* {{{ */ 85 { 86 return mem->avail; 87 } 88 /* }}} */ 89 static XC_MEM_SIZE(xc_malloc_size) /* {{{ */ 90 { 91 return mem->size; 92 } 93 /* }}} */ 94 95 static XC_MEM_FREEBLOCK_FIRST(xc_malloc_freeblock_first) /* {{{ */ 75 static XC_ALLOCATOR_CALLOC(xc_allocator_malloc_calloc) /* {{{ */ 76 { 77 return xc_add_to_blocks(allocator, calloc(memb, size), size); 78 } 79 /* }}} */ 80 static XC_ALLOCATOR_REALLOC(xc_allocator_malloc_realloc) /* {{{ */ 81 { 82 return xc_add_to_blocks(allocator, realloc((void *) p, size), size); 83 } 84 /* }}} */ 85 86 static XC_ALLOCATOR_AVAIL(xc_allocator_malloc_avail) /* {{{ */ 87 { 88 return allocator->avail; 89 } 90 /* }}} */ 91 static XC_ALLOCATOR_SIZE(xc_allocator_malloc_size) /* {{{ */ 92 { 93 return allocator->size; 94 } 95 /* }}} */ 96 97 static XC_ALLOCATOR_FREEBLOCK_FIRST(xc_allocator_malloc_freeblock_first) /* {{{ */ 96 98 { 97 99 return (void *) -1; 98 100 } 99 101 /* }}} */ 100 XC_MEM_FREEBLOCK_NEXT(xc_malloc_freeblock_next) /* {{{ */102 static XC_ALLOCATOR_FREEBLOCK_NEXT(xc_allocator_malloc_freeblock_next) /* {{{ */ 101 103 { 102 104 return NULL; 103 105 } 104 106 /* }}} */ 105 XC_MEM_BLOCK_SIZE(xc_malloc_block_size) /* {{{ */106 { 107 return 0; 108 } 109 /* }}} */ 110 XC_MEM_BLOCK_OFFSET(xc_malloc_block_offset) /* {{{ */111 { 112 return 0; 113 } 114 /* }}} */ 115 116 static XC_ MEM_INIT(xc_mem_malloc_init) /* {{{ */117 { 118 #define MINSIZE (ALIGN(sizeof(xc_ mem_t)))107 static XC_ALLOCATOR_BLOCK_SIZE(xc_allocator_malloc_block_size) /* {{{ */ 108 { 109 return 0; 110 } 111 /* }}} */ 112 static XC_ALLOCATOR_BLOCK_OFFSET(xc_allocator_malloc_block_offset) /* {{{ */ 113 { 114 return 0; 115 } 116 /* }}} */ 117 118 static XC_ALLOCATOR_INIT(xc_allocator_malloc_init) /* {{{ */ 119 { 120 #define MINSIZE (ALIGN(sizeof(xc_allocator_t))) 119 121 /* requires at least the header and 1 tail block */ 120 122 if (size < MINSIZE) { 121 fprintf(stderr, "xc_ mem_malloc_init requires %lu bytes at least\n", (unsigned long) MINSIZE);123 fprintf(stderr, "xc_allocator_malloc_init requires %lu bytes at least\n", (unsigned long) MINSIZE); 122 124 return NULL; 123 125 } 124 mem->shm = shm;125 mem->size = size;126 mem->avail = size - MINSIZE;126 allocator->shm = shm; 127 allocator->size = size; 128 allocator->avail = size - MINSIZE; 127 129 #undef MINSIZE 128 130 129 return mem;130 } 131 /* }}} */ 132 static XC_ MEM_DESTROY(xc_mem_malloc_destroy) /* {{{ */131 return allocator; 132 } 133 /* }}} */ 134 static XC_ALLOCATOR_DESTROY(xc_allocator_malloc_destroy) /* {{{ */ 133 135 { 134 136 } … … 142 144 static XC_SHM_IS_READWRITE(xc_malloc_is_readwrite) /* {{{ */ 143 145 { 146 #ifndef TEST 144 147 HashPosition pos; 145 148 size_t *psize; … … 154 157 zend_hash_move_forward_ex(&shm->blocks, &pos); 155 158 } 159 #endif 156 160 157 161 return 0; … … 176 180 static XC_SHM_DESTROY(xc_malloc_destroy) /* {{{ */ 177 181 { 182 #ifndef TEST 178 183 zend_hash_destroy(&shm->blocks); 184 #endif 179 185 free(shm); 180 186 return; … … 187 193 shm->size = size; 188 194 195 #ifndef TEST 189 196 zend_hash_init(&shm->blocks, 64, NULL, NULL, 1); 197 #endif 190 198 return shm; 191 199 err: … … 196 204 static XC_SHM_MEMINIT(xc_malloc_meminit) /* {{{ */ 197 205 { 198 xc_mem_t*mem;206 void *mem; 199 207 if (shm->memoffset + size > shm->size) { 208 #ifndef TEST 200 209 zend_error(E_ERROR, "XCache: internal error at %s#%d", __FILE__, __LINE__); 210 #endif 201 211 return NULL; 202 212 } 203 213 shm->memoffset += size; 204 CHECK(mem = calloc(1, sizeof(xc_mem_t)), "mem OOM"); 205 mem->handlers = shm->handlers->memhandlers; 206 mem->handlers->init(shm, mem, size); 214 CHECK(mem = calloc(1, size), "mem OOM"); 207 215 return mem; 208 216 err: … … 212 220 static XC_SHM_MEMDESTROY(xc_malloc_memdestroy) /* {{{ */ 213 221 { 214 mem->handlers->destroy(mem);215 222 free(mem); 216 223 } 217 224 /* }}} */ 218 225 219 #define xc_malloc_destroy xc_mem_malloc_destroy 220 #define xc_malloc_init xc_mem_malloc_init 221 static xc_mem_handlers_t xc_mem_malloc_handlers = XC_MEM_HANDLERS(malloc); 222 #undef xc_malloc_init 223 #undef xc_malloc_destroy 226 static xc_allocator_vtable_t xc_allocator_malloc_vtable = XC_ALLOCATOR_VTABLE(allocator_malloc); 224 227 static xc_shm_handlers_t xc_shm_malloc_handlers = XC_SHM_HANDLERS(malloc); 228 void xc_allocator_malloc_register() /* {{{ */ 229 { 230 if (xc_allocator_register("malloc", &xc_allocator_malloc_vtable) == 0) { 231 #ifndef TEST 232 zend_error(E_ERROR, "XCache: failed to register malloc mem_scheme"); 233 #endif 234 } 235 } 236 /* }}} */ 237 238 #ifndef TEST 225 239 void xc_shm_malloc_register() /* {{{ */ 226 240 { 227 if (xc_mem_scheme_register("malloc", &xc_mem_malloc_handlers) == 0) {228 zend_error(E_ERROR, "XCache: failed to register malloc mem_scheme");229 }230 231 CHECK(xc_shm_malloc_handlers.memhandlers = xc_mem_scheme_find("malloc"), "cannot find malloc handlers");232 241 if (xc_shm_scheme_register("malloc", &xc_shm_malloc_handlers) == 0) { 233 242 zend_error(E_ERROR, "XCache: failed to register malloc shm_scheme"); 234 243 } 235 err: 236 return; 237 } 238 /* }}} */ 244 } 245 /* }}} */ 246 #endif -
trunk/xcache/xc_shm.c
r982 r1135 23 23 void xc_shm_init_modules() /* {{{ */ 24 24 { 25 extern void xc_ shm_mem_init();25 extern void xc_allocator_init(); 26 26 #ifdef HAVE_XCACHE_TEST 27 27 extern void xc_shm_malloc_register(); … … 30 30 31 31 memset(xc_shm_schemes, 0, sizeof(xc_shm_schemes)); 32 xc_ shm_mem_init();32 xc_allocator_init(); 33 33 #ifdef HAVE_XCACHE_TEST 34 34 xc_shm_malloc_register(); -
trunk/xcache/xc_shm.h
r1040 r1135 1 1 #ifndef XC_SHM_H 2 2 #define XC_SHM_H 3 4 #include <stdlib.h> 5 3 6 typedef struct _xc_shm_handlers_t xc_shm_handlers_t; 4 7 … … 13 16 typedef size_t xc_shmsize_t; 14 17 15 #include "xc_mem.h"16 17 18 /* shm */ 18 19 #define XC_SHM_CAN_READONLY(func) int func(xc_shm_t *shm) … … 25 26 #define XC_SHM_DESTROY(func) void func(xc_shm_t *shm) 26 27 27 #define XC_SHM_MEMINIT(func) xc_mem_t *func(xc_shm_t *shm, xc_memsize_t size)28 #define XC_SHM_MEMDESTROY(func) void func( xc_mem_t*mem)28 #define XC_SHM_MEMINIT(func) void *func(xc_shm_t *shm, xc_shmsize_t size) 29 #define XC_SHM_MEMDESTROY(func) void func(void *mem) 29 30 30 31 #define XC_SHM_HANDLERS(name) { \ 31 NULL \ 32 , xc_##name##_can_readonly \ 32 xc_##name##_can_readonly \ 33 33 , xc_##name##_is_readwrite \ 34 34 , xc_##name##_is_readonly \ … … 44 44 45 45 struct _xc_shm_handlers_t { 46 const xc_mem_handlers_t *memhandlers;47 46 XC_SHM_CAN_READONLY((*can_readonly)); 48 47 XC_SHM_IS_READWRITE((*is_readwrite)); -
trunk/xcache/xc_shm_mmap.c
r983 r1135 295 295 static XC_SHM_MEMINIT(xc_mmap_meminit) /* {{{ */ 296 296 { 297 xc_mem_t*mem;297 void *mem; 298 298 if (shm->memoffset + size > shm->size) { 299 299 zend_error(E_ERROR, "XCache: internal error at %s#%d", __FILE__, __LINE__); 300 300 return NULL; 301 301 } 302 mem = (xc_mem_t *)PTR_ADD(shm->ptr, shm->memoffset);302 mem = PTR_ADD(shm->ptr, shm->memoffset); 303 303 shm->memoffset += size; 304 mem->handlers = shm->handlers->memhandlers;305 mem->handlers->init(shm, mem, size);306 304 return mem; 307 305 } … … 315 313 void xc_shm_mmap_register() /* {{{ */ 316 314 { 317 CHECK(xc_shm_mmap_handlers.memhandlers = xc_mem_scheme_find("mem"), "cannot find mem handlers");318 315 if (xc_shm_scheme_register("mmap", &xc_shm_mmap_handlers) == 0) { 319 316 zend_error(E_ERROR, "XCache: failed to register mmap shm_scheme"); 320 317 } 321 err:322 318 return; 323 319 }

