summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ZendAccelerator.c17
-rw-r--r--zend_accelerator_module.c3
-rw-r--r--zend_shared_alloc.c38
-rw-r--r--zend_shared_alloc.h1
4 files changed, 29 insertions, 30 deletions
diff --git a/ZendAccelerator.c b/ZendAccelerator.c
index bb571a4805..87b60f1e01 100644
--- a/ZendAccelerator.c
+++ b/ZendAccelerator.c
@@ -71,8 +71,6 @@ typedef int gid_t;
#include <sys/stat.h>
#include <errno.h>
-#define MIN_FREE_MEMORY 64*1024
-
#define SHM_PROTECT() \
do { \
if (ZCG(accel_directives).protect_memory) { \
@@ -853,6 +851,7 @@ static inline int do_validate_timestamps(zend_persistent_script *persistent_scri
static void zend_accel_schedule_restart_if_necessary(TSRMLS_D)
{
if ((((double) ZSMMG(wasted_shared_memory)) / ZCG(accel_directives).memory_consumption) >= ZCG(accel_directives).max_wasted_percentage) {
+ ZSMMG(memory_exhausted) = 1;
zend_accel_schedule_restart(TSRMLS_C);
}
}
@@ -1031,14 +1030,12 @@ static void zend_accel_add_key(char *key, unsigned int key_length, zend_accel_ha
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(TSRMLS_C);
} else {
char *new_key = zend_shared_alloc(key_length + 1);
if (new_key) {
memcpy(new_key, key, key_length + 1);
zend_accel_hash_update(&ZCSG(hash), new_key, key_length + 1, 1, bucket);
- } else {
- zend_accel_error(ACCEL_LOG_DEBUG, "No more memory!");
- ZSMMG(memory_exhausted) = 1;
}
}
}
@@ -1060,7 +1057,7 @@ 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(TSRMLS_C);
+ zend_accel_schedule_restart(TSRMLS_C);
zend_shared_alloc_unlock(TSRMLS_C);
return new_persistent_script;
}
@@ -1088,11 +1085,6 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
/* Allocate shared memory */
ZCG(mem) = zend_shared_alloc(memory_used);
if (!ZCG(mem)) {
- zend_accel_error(ACCEL_LOG_DEBUG, "No more memory!");
- zend_accel_schedule_restart_if_necessary(TSRMLS_C);
- if (zend_shared_alloc_get_largest_free_block() < MIN_FREE_MEMORY) {
- ZSMMG(memory_exhausted) = 1;
- }
zend_shared_alloc_unlock(TSRMLS_C);
return new_persistent_script;
}
@@ -1126,6 +1118,7 @@ static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_scr
if (!zend_accel_hash_update(&ZCSG(hash), key, key_length + 1, 1, bucket)) {
zend_accel_error(ACCEL_LOG_DEBUG, "No more entries in hash table!");
ZSMMG(memory_exhausted) = 1;
+ zend_accel_schedule_restart(TSRMLS_C);
}
}
@@ -1469,6 +1462,7 @@ static zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int
persistent_script->corrupted = 1;
persistent_script->timestamp = 0;
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
+ zend_accel_schedule_restart_if_necessary(TSRMLS_C);
}
zend_shared_alloc_unlock(TSRMLS_C);
persistent_script = NULL;
@@ -1489,6 +1483,7 @@ static zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int
persistent_script->corrupted = 1;
persistent_script->timestamp = 0;
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
+ zend_accel_schedule_restart_if_necessary(TSRMLS_C);
}
zend_shared_alloc_unlock(TSRMLS_C);
persistent_script = NULL;
diff --git a/zend_accelerator_module.c b/zend_accelerator_module.c
index 701820f228..c7c3b6058f 100644
--- a/zend_accelerator_module.c
+++ b/zend_accelerator_module.c
@@ -496,7 +496,8 @@ static ZEND_FUNCTION(accelerator_get_status)
MAKE_STD_ZVAL(statistics);
array_init(statistics);
add_assoc_long(statistics, "num_cached_scripts", ZCSG(hash).num_direct_entries);
- add_assoc_long(statistics, "max_cached_scripts", ZCSG(hash).max_num_entries);
+ add_assoc_long(statistics, "num_cached_keys", ZCSG(hash).num_entries);
+ add_assoc_long(statistics, "max_cached_keys", ZCSG(hash).max_num_entries);
add_assoc_long(statistics, "hits", ZCSG(hits));
add_assoc_long(statistics, "last_restart_time", ZCSG(last_restart_time));
add_assoc_long(statistics, "misses", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses));
diff --git a/zend_shared_alloc.c b/zend_shared_alloc.c
index b6040cf0ad..1a983aeea7 100644
--- a/zend_shared_alloc.c
+++ b/zend_shared_alloc.c
@@ -256,10 +256,29 @@ void zend_shared_alloc_shutdown(void)
#endif
}
+static size_t zend_shared_alloc_get_largest_free_block(void)
+{
+ int i;
+ size_t largest_block_size = 0;
+
+ for (i = 0; i < ZSMMG(shared_segments_count); i++) {
+ size_t block_size = ZSMMG(shared_segments)[i]->size - ZSMMG(shared_segments)[i]->pos;
+
+ if (block_size>largest_block_size) {
+ largest_block_size = block_size;
+ }
+ }
+ return largest_block_size;
+}
+
+#define MIN_FREE_MEMORY 64*1024
+
#define SHARED_ALLOC_FAILED() do { \
zend_accel_error(ACCEL_LOG_WARNING, "Not enough free shared space to allocate %ld bytes (%ld bytes free)", (long)size, (long)ZSMMG(shared_free)); \
- ZSMMG(memory_exhausted) = 1; \
- zend_accel_schedule_restart(TSRMLS_C); \
+ if (zend_shared_alloc_get_largest_free_block() < MIN_FREE_MEMORY) { \
+ ZSMMG(memory_exhausted) = 1; \
+ zend_accel_schedule_restart(TSRMLS_C); \
+ } \
} while (0)
void *zend_shared_alloc(size_t size)
@@ -425,21 +444,6 @@ size_t zend_shared_alloc_get_free_memory(void)
return ZSMMG(shared_free);
}
-size_t zend_shared_alloc_get_largest_free_block(void)
-{
- int i;
- size_t largest_block_size = 0;
-
- for (i = 0; i < ZSMMG(shared_segments_count); i++) {
- size_t block_size = ZSMMG(shared_segments)[i]->size - ZSMMG(shared_segments)[i]->pos;
-
- if (block_size>largest_block_size) {
- largest_block_size = block_size;
- }
- }
- return largest_block_size;
-}
-
void zend_shared_alloc_save_state(void)
{
int i;
diff --git a/zend_shared_alloc.h b/zend_shared_alloc.h
index 77ef723fbb..c8411b5624 100644
--- a/zend_shared_alloc.h
+++ b/zend_shared_alloc.h
@@ -159,7 +159,6 @@ void *zend_shared_alloc_get_xlat_entry(const void *old);
size_t zend_shared_alloc_get_free_memory(void);
void zend_shared_alloc_save_state(void);
void zend_shared_alloc_restore_state(void);
-size_t zend_shared_alloc_get_largest_free_block(void);
const char *zend_accel_get_shared_model(void);
/* memory write protection */