From c78277ae84b21067744d1701949e4e1fadd8872a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 16 Oct 2018 17:25:35 +0300 Subject: [PATCH] Preloadsing support for opcache restart --- ext/opcache/ZendAccelerator.c | 33 ++++++++++++++++++++++++++++----- ext/opcache/ZendAccelerator.h | 2 ++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index c0794dfa632..03d3349f3ed 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -2421,6 +2421,17 @@ int accel_activate(INIT_FUNC_ARGS) } zend_shared_alloc_restore_state(); + if (ZCSG(preload_script)) { + zend_accel_hash_update(&ZCSG(hash), ZSTR_VAL(ZCSG(preload_script)->script.filename), ZSTR_LEN(ZCSG(preload_script)->script.filename), 0, ZCSG(preload_script)); + if (ZCSG(saved_scripts)) { + zend_persistent_script **p = ZCSG(saved_scripts); + while (*p) { + zend_accel_hash_update(&ZCSG(hash), ZSTR_VAL((*p)->script.filename), ZSTR_LEN((*p)->script.filename), 0, *p); + p++; + } + } + ZCSG(map_ptr_last) = ZCSG(saved_map_ptr_last); + } ZCSG(accelerator_enabled) = ZCSG(cache_status_before_restart); if (ZCSG(last_restart_time) < ZCG(request_time)) { ZCSG(last_restart_time) = ZCG(request_time); @@ -3616,6 +3627,7 @@ static int accel_preload(const char *config) if (ret == SUCCESS) { zend_persistent_script *script; zend_string *filename; + int i; preload_link(); preload_remove_empty_includes(); @@ -3704,13 +3716,24 @@ static int accel_preload(const char *config) EG(persistent_classes_count) = EG(class_table)->nNumUsed; /* Store individual scripts with unlinked classes */ + HANDLE_BLOCK_INTERRUPTIONS(); + SHM_UNPROTECT(); + + i = 0; + zend_shared_alloc_lock(); + ZCSG(saved_scripts) = zend_shared_alloc((zend_hash_num_elements(preload_scripts) + 1) * sizeof(void*)); + zend_shared_alloc_unlock(); ZEND_HASH_FOREACH_PTR(preload_scripts, script) { - HANDLE_BLOCK_INTERRUPTIONS(); - SHM_UNPROTECT(); - preload_script_in_shared_memory(script); - SHM_PROTECT(); - HANDLE_UNBLOCK_INTERRUPTIONS(); + ZCSG(saved_scripts)[i++] = preload_script_in_shared_memory(script); } ZEND_HASH_FOREACH_END(); + ZCSG(saved_scripts)[i] = NULL; + + ZCSG(saved_map_ptr_last) = ZCSG(map_ptr_last); + zend_shared_alloc_save_state(); + accel_interned_strings_save_state(); + + SHM_PROTECT(); + HANDLE_UNBLOCK_INTERRUPTIONS(); zend_shared_alloc_destroy_xlat_table(); } diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index ec13bc514b6..d0b1744d743 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -288,6 +288,8 @@ typedef struct _zend_accel_shared_globals { /* Preloading */ zend_persistent_script *preload_script; + zend_persistent_script **saved_scripts; + size_t saved_map_ptr_last; /* uninitialized HashTable Support */ uint32_t uninitialized_bucket[-HT_MIN_MASK];