Skip to content

Commit 31ef9e8

Browse files
author
Andi Gutmans
committed
- Real MFH of memory fragmentation patch
1 parent 8ef5510 commit 31ef9e8

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Zend/zend_alloc.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ ZEND_API void start_memory_manager(ALS_D)
394394
memset(AG(fast_cache_list_head), 0, sizeof(AG(fast_cache_list_head)));
395395
memset(AG(cache_count), 0, sizeof(AG(cache_count)));
396396

397+
#if 0
397398
#ifndef ZTS
398399
/* Initialize cache, to prevent fragmentation */
399400
/* We can't do this in ZTS mode, because calling emalloc() from within start_memory_manager()
@@ -410,6 +411,7 @@ ZEND_API void start_memory_manager(ALS_D)
410411
}
411412
}
412413
#endif
414+
#endif
413415

414416
#if ZEND_DEBUG
415417
memset(AG(cache_stats), 0, sizeof(AG(cache_stats)));
@@ -438,6 +440,19 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache)
438440
AG(fast_cache_list_head)[fci] = NULL;
439441
}
440442

443+
if (1 || clean_cache) {
444+
zend_mem_header *ptr;
445+
446+
for (i=1; i<MAX_CACHED_MEMORY; i++) {
447+
for (j=0; j<AG(cache_count)[i]; j++) {
448+
ptr = (zend_mem_header *) AG(cache)[i][j];
449+
REMOVE_POINTER_FROM_LIST(ptr);
450+
free(ptr);
451+
}
452+
AG(cache_count)[i] = 0;
453+
}
454+
}
455+
441456
p = AG(head);
442457
t = AG(head);
443458
while (t) {
@@ -478,13 +493,6 @@ ZEND_API void shutdown_memory_manager(int silent, int clean_cache)
478493
}
479494
}
480495

481-
if (clean_cache) {
482-
for (i=1; i<MAX_CACHED_MEMORY; i++) {
483-
for (j=0; j<AG(cache_count)[i]; j++) {
484-
free(AG(cache)[i][j]);
485-
}
486-
}
487-
}
488496
#if MEMORY_LIMIT
489497
AG(memory_exhausted)=0;
490498
#endif

0 commit comments

Comments
 (0)