Skip to content

Commit

Permalink
Fixed bug #75720 (File cache not populated after SHM runs full)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Dec 28, 2017
1 parent 7c96e97 commit 60b2d67
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PHP NEWS
. Fixed bug #75679 (Path 260 character problem). (Anatol)

- Opcache:
. Fixed bug #75720 (File cache not populated after SHM runs full). (Dmitry)
. Fixed bug #75579 (Interned strings buffer overflow may cause crash).
(Dmitry)

Expand Down
59 changes: 40 additions & 19 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,19 +1214,10 @@ static void zend_accel_add_key(char *key, unsigned int key_length, zend_accel_ha
}

#ifdef HAVE_OPCACHE_FILE_CACHE
static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script *new_persistent_script, int *from_shared_memory)
static zend_persistent_script *store_script_in_file_cache(zend_persistent_script *new_persistent_script)
{
uint memory_used;

/* Check if script may be stored in shared memory */
if (!zend_accel_script_persistable(new_persistent_script)) {
return new_persistent_script;
}

if (!zend_optimize_script(&new_persistent_script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level)) {
return new_persistent_script;
}

zend_shared_alloc_init_xlat_table();

/* Calculate the required memory size */
Expand Down Expand Up @@ -1266,9 +1257,23 @@ static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script

zend_file_cache_script_store(new_persistent_script, 0);

*from_shared_memory = 1;
return new_persistent_script;
}

static zend_persistent_script *cache_script_in_file_cache(zend_persistent_script *new_persistent_script, int *from_shared_memory)
{
/* Check if script may be stored in shared memory */
if (!zend_accel_script_persistable(new_persistent_script)) {
return new_persistent_script;
}

if (!zend_optimize_script(&new_persistent_script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level)) {
return new_persistent_script;
}

*from_shared_memory = 1;
return store_script_in_file_cache(new_persistent_script);
}
#endif

static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_script *new_persistent_script, char *key, unsigned int key_length, int *from_shared_memory)
Expand All @@ -1288,14 +1293,6 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
/* exclusive lock */
zend_shared_alloc_lock();

if (zend_accel_hash_is_full(&ZCSG(hash))) {
zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
ZSMMG(memory_exhausted) = 1;
zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH);
zend_shared_alloc_unlock();
return new_persistent_script;
}

/* Check if we still need to put the file into the cache (may be it was
* already stored by another process. This final check is done under
* exclusive lock) */
Expand All @@ -1314,6 +1311,19 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
}
}

if (zend_accel_hash_is_full(&ZCSG(hash))) {
zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
ZSMMG(memory_exhausted) = 1;
zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH);
zend_shared_alloc_unlock();
#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
new_persistent_script = store_script_in_file_cache(new_persistent_script);
*from_shared_memory = 1;
}
#endif
return new_persistent_script;
}

zend_shared_alloc_init_xlat_table();

Expand All @@ -1332,6 +1342,12 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
zend_shared_alloc_destroy_xlat_table();
zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM);
zend_shared_alloc_unlock();
#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
new_persistent_script = store_script_in_file_cache(new_persistent_script);
*from_shared_memory = 1;
}
#endif
return new_persistent_script;
}

Expand Down Expand Up @@ -1867,6 +1883,11 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
if (ZSMMG(memory_exhausted) || ZCSG(restart_pending)) {
SHM_PROTECT();
HANDLE_UNBLOCK_INTERRUPTIONS();
#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
return file_cache_compile_file(file_handle, type);
}
#endif
return accelerator_orig_compile_file(file_handle, type);
}

Expand Down

0 comments on commit 60b2d67

Please sign in to comment.