diff options
| author | Ondřej Surý <ondrej@sury.org> | 2013-06-21 13:48:35 +0200 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2013-06-21 13:48:35 +0200 |
| commit | 706ac6417162d94eb701952d40df136cd9528b56 (patch) | |
| tree | 1858b0f397d16519dbd73c998d7a89001af362d2 /ext/opcache | |
| parent | e2d52710fa3134e72662116b3b495f5a22cf9c72 (diff) | |
| download | php-706ac6417162d94eb701952d40df136cd9528b56.tar.gz | |
New upstream version 5.5.0+dfsgupstream/5.5.0+dfsg
Diffstat (limited to 'ext/opcache')
| -rw-r--r-- | ext/opcache/ZendAccelerator.c | 14 | ||||
| -rw-r--r-- | ext/opcache/ZendAccelerator.h | 4 | ||||
| -rw-r--r-- | ext/opcache/zend_accelerator_util_funcs.c | 47 | ||||
| -rw-r--r-- | ext/opcache/zend_accelerator_util_funcs.h | 1 | ||||
| -rw-r--r-- | ext/opcache/zend_shared_alloc.c | 4 |
5 files changed, 63 insertions, 7 deletions
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index b62f245f4..875a4727a 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1126,6 +1126,10 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr return new_persistent_script; } + if (!compact_persistent_script(new_persistent_script)) { + return new_persistent_script; + } + /* exclusive lock */ zend_shared_alloc_lock(TSRMLS_C); @@ -1613,10 +1617,12 @@ static zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int from_shared_memory = 0; persistent_script = compile_and_cache_file(file_handle, type, key, key_length, &op_array, &from_shared_memory TSRMLS_CC); - /* Something went wrong during compilation, returning NULL */ + /* Caching is disabled, returning op_array; + * or something went wrong during compilation, returning NULL + */ if (!persistent_script) { SHM_PROTECT(); - return op_array; /* Presently always NULL, but not necessary in the future */ + return op_array; } } else { @@ -2579,7 +2585,9 @@ static int accel_startup(zend_extension *extension) ZCG(include_path_key) = NULL; if (ZCG(include_path) && *ZCG(include_path)) { ZCG(include_path_len) = strlen(ZCG(include_path)); - if (!zend_accel_hash_is_full(&ZCSG(include_paths))) { + ZCG(include_path_key) = zend_accel_hash_find(&ZCSG(include_paths), ZCG(include_path), ZCG(include_path_len) + 1); + if (!ZCG(include_path_key) && + !zend_accel_hash_is_full(&ZCSG(include_paths))) { char *key; zend_shared_alloc_lock(TSRMLS_C); diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index 85f95708a..733e544e1 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -168,7 +168,7 @@ typedef time_t accel_time_t; typedef enum _zend_accel_restart_reason { ACCEL_RESTART_OOM, /* restart because of out of memory */ ACCEL_RESTART_HASH, /* restart because of hash overflow */ - ACCEL_RESTART_USER /* restart sheduled by opcache_reset() */ + ACCEL_RESTART_USER /* restart scheduled by opcache_reset() */ } zend_accel_restart_reason; typedef struct _zend_persistent_script { @@ -268,7 +268,7 @@ typedef struct _zend_accel_shared_globals { unsigned long blacklist_misses; unsigned long oom_restarts; /* number of restarts because of out of memory */ unsigned long hash_restarts; /* number of restarts because of hash overflow */ - unsigned long manual_restarts; /* number of restarts sheduled by opcache_reset() */ + unsigned long manual_restarts; /* number of restarts scheduled by opcache_reset() */ zend_accel_hash hash; /* hash table for cached scripts */ zend_accel_hash include_paths; /* used "include_path" values */ diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index 33ecf7f18..c24d9f130 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -86,6 +86,53 @@ zend_persistent_script* create_persistent_script(void) return persistent_script; } +static int compact_hash_table(HashTable *ht) +{ + uint i = 3; + uint nSize; + Bucket **t; + + if (!ht->nNumOfElements) { + /* Empty tables don't allocate space for Buckets */ + return 1; + } + + if (ht->nNumOfElements >= 0x80000000) { + /* prevent overflow */ + nSize = 0x80000000; + } else { + while ((1U << i) < ht->nNumOfElements) { + i++; + } + nSize = 1 << i; + } + + if (nSize >= ht->nTableSize) { + /* Keep the size */ + return 1; + } + + t = (Bucket **)pemalloc(nSize * sizeof(Bucket *), ht->persistent); + if (!t) { + return 0; + } + + pefree(ht->arBuckets, ht->persistent); + + ht->arBuckets = t; + ht->nTableSize = nSize; + ht->nTableMask = ht->nTableSize - 1; + zend_hash_rehash(ht); + + return 1; +} + +int compact_persistent_script(zend_persistent_script *persistent_script) +{ + return compact_hash_table(&persistent_script->function_table) && + compact_hash_table(&persistent_script->class_table); +} + void free_persistent_script(zend_persistent_script *persistent_script, int destroy_elements) { if (destroy_elements) { diff --git a/ext/opcache/zend_accelerator_util_funcs.h b/ext/opcache/zend_accelerator_util_funcs.h index a926145c9..ddaae86b2 100644 --- a/ext/opcache/zend_accelerator_util_funcs.h +++ b/ext/opcache/zend_accelerator_util_funcs.h @@ -28,6 +28,7 @@ void zend_accel_copy_internal_functions(TSRMLS_D); zend_persistent_script* create_persistent_script(void); +int compact_persistent_script(zend_persistent_script *script); void free_persistent_script(zend_persistent_script *persistent_script, int destroy_elements); void zend_accel_free_user_functions(HashTable *ht TSRMLS_DC); diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c index d752afea1..cf4e0ff0f 100644 --- a/ext/opcache/zend_shared_alloc.c +++ b/ext/opcache/zend_shared_alloc.c @@ -99,9 +99,9 @@ void zend_shared_alloc_create_lock(void) } #endif -static void no_memory_bailout(int allocate_size, char *error) +static void no_memory_bailout(size_t allocate_size, char *error) { - zend_accel_error(ACCEL_LOG_FATAL, "Unable to allocate shared memory segment of %d bytes: %s: %s (%d)", allocate_size, error?error:"unknown", strerror(errno), errno ); + zend_accel_error(ACCEL_LOG_FATAL, "Unable to allocate shared memory segment of %ld bytes: %s: %s (%d)", allocate_size, error?error:"unknown", strerror(errno), errno ); } static void copy_shared_segments(void *to, void *from, int count, int size) |
