From dcf389228c9f1f65da9983226cfe5e6ca6904298 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 11 Feb 2021 16:51:08 +0300 Subject: [PATCH] Avoid useless SHM data duplication --- ext/opcache/zend_persist.c | 12 ++++++++++-- ext/opcache/zend_persist_calc.c | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c index 139bac438b..e5aad26133 100644 --- a/ext/opcache/zend_persist.c +++ b/ext/opcache/zend_persist.c @@ -210,6 +210,9 @@ static void zend_persist_zval(zval *z) if (new_ptr) { Z_ARR_P(z) = new_ptr; Z_TYPE_FLAGS_P(z) = 0; + } else if (!ZCG(current_persistent_script)->corrupted + && zend_accel_in_shm(Z_ARR_P(z))) { + /* pass */ } else { Bucket *p; @@ -237,7 +240,8 @@ static void zend_persist_zval(zval *z) if (new_ptr) { Z_AST_P(z) = new_ptr; Z_TYPE_FLAGS_P(z) = 0; - } else if (!zend_accel_in_shm(Z_AST_P(z))) { + } else if (ZCG(current_persistent_script)->corrupted + || !zend_accel_in_shm(Z_AST_P(z))) { zend_ast_ref *old_ref = Z_AST_P(z); Z_AST_P(z) = zend_shared_memdup_put(Z_AST_P(z), sizeof(zend_ast_ref)); zend_persist_ast(GC_AST(old_ref)); @@ -260,7 +264,8 @@ static HashTable *zend_persist_attributes(HashTable *attributes) uint32_t i; zval *v; - if (zend_accel_in_shm(attributes)) { + if (!ZCG(current_persistent_script)->corrupted + && zend_accel_in_shm(attributes)) { return attributes; } @@ -792,6 +797,9 @@ static void zend_persist_class_constant(zval *zv) if (c) { Z_PTR_P(zv) = c; return; + } else if (!ZCG(current_persistent_script)->corrupted + && zend_accel_in_shm(Z_PTR_P(zv))) { + return; } c = Z_PTR_P(zv) = zend_shared_memdup_put(Z_PTR_P(zv), sizeof(zend_class_constant)); zend_persist_zval(&c->value); diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c index 5728414eec..d708758a33 100644 --- a/ext/opcache/zend_persist_calc.c +++ b/ext/opcache/zend_persist_calc.c @@ -105,6 +105,10 @@ static void zend_persist_zval_calc(zval *z) } break; case IS_ARRAY: + if (!ZCG(current_persistent_script)->corrupted + && zend_accel_in_shm(Z_ARR_P(z))) { + return; + } size = zend_shared_memdup_size(Z_ARR_P(z), sizeof(zend_array)); if (size) { Bucket *p; @@ -120,7 +124,8 @@ static void zend_persist_zval_calc(zval *z) } break; case IS_CONSTANT_AST: - if (!zend_accel_in_shm(Z_AST_P(z))) { + if (ZCG(current_persistent_script)->corrupted + || !zend_accel_in_shm(Z_AST_P(z))) { size = zend_shared_memdup_size(Z_AST_P(z), sizeof(zend_ast_ref)); if (size) { ADD_SIZE(size); @@ -137,7 +142,8 @@ static void zend_persist_zval_calc(zval *z) static void zend_persist_attributes_calc(HashTable *attributes) { if (!zend_shared_alloc_get_xlat_entry(attributes) - && !zend_accel_in_shm(attributes)) { + && (ZCG(current_persistent_script)->corrupted + || !zend_accel_in_shm(attributes))) { zend_attribute *attr; uint32_t i; @@ -352,6 +358,10 @@ static void zend_persist_class_constant_calc(zval *zv) zend_class_constant *c = Z_PTR_P(zv); if (!zend_shared_alloc_get_xlat_entry(c)) { + if (!ZCG(current_persistent_script)->corrupted + && zend_accel_in_shm(Z_PTR_P(zv))) { + return; + } zend_shared_alloc_register_xlat_entry(c, c); ADD_SIZE(sizeof(zend_class_constant)); zend_persist_zval_calc(&c->value); -- 2.50.1