]> granicus.if.org Git - php/commitdiff
Added ability to control memory consumption between request using ZEND_MM_COMPACT...
authorDmitry Stogov <dmitry@php.net>
Thu, 25 Oct 2007 07:30:29 +0000 (07:30 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 25 Oct 2007 07:30:29 +0000 (07:30 +0000)
NEWS
Zend/zend_alloc.c

diff --git a/NEWS b/NEWS
index c5fc470a676657f931d228869b072a238652e4f1..061954eea468a2e706e681e6641f45e103a0e53c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2007, PHP 5.2.5RC2
+- Added ability to control memory consumption between request using
+  ZEND_MM_COMPACT environment variable. (Dmitry)
 
 18 Oct 2007, PHP 5.2.5RC1
 - Upgraded PCRE to version 7.3 (Nuno)
index 7801750b90037cf37baf6a0f1fa225cf0d402321..78d71168966578075cc22de7b7d9d1b4b03359dc 100644 (file)
@@ -396,6 +396,7 @@ struct _zend_mm_heap {
        size_t              free_bitmap;
        size_t              large_free_bitmap;
        size_t              block_size;
+       size_t              compact_size;
        zend_mm_segment    *segments_list;
        zend_mm_storage    *storage;
        size_t                          real_size;
@@ -1028,6 +1029,7 @@ ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_mem_handlers *handlers,
 
        heap->storage = storage;
        heap->block_size = block_size;
+       heap->compact_size = 0;
        heap->segments_list = NULL;
        zend_mm_init(heap);
 # if ZEND_MM_CACHE_STAT
@@ -1078,6 +1080,7 @@ ZEND_API zend_mm_heap *zend_mm_startup(void)
        char *mem_type = getenv("ZEND_MM_MEM_TYPE");
        char *tmp;
        const zend_mm_mem_handlers *handlers;
+       zend_mm_heap *heap;
 
        if (mem_type == NULL) {
                i = 0;
@@ -1109,7 +1112,16 @@ ZEND_API zend_mm_heap *zend_mm_startup(void)
                seg_size = ZEND_MM_SEG_SIZE;
        }
 
-       return zend_mm_startup_ex(handlers, seg_size, ZEND_MM_RESERVE_SIZE, 0, NULL);
+       heap = zend_mm_startup_ex(handlers, seg_size, ZEND_MM_RESERVE_SIZE, 0, NULL);
+       if (heap) {
+               tmp = getenv("ZEND_MM_COMPACT");
+               if (tmp) {
+                       heap->compact_size = zend_atoi(tmp, 0);
+               } else {
+                       heap->compact_size = 2 * 1024 * 1024;
+               }
+       }
+       return heap;
 }
 
 #if ZEND_DEBUG
@@ -1563,7 +1575,9 @@ ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, int full_shutdown, int silent
 #ifdef HAVE_MEM_WIN32
                /* FIX for bug #41713 */
                /* TODO: add new "compact" handler */
-               if (storage->handlers->dtor == zend_mm_mem_win32_dtor &&
+               if (heap->compact_size &&
+                   heap->real_peak > heap->compact_size &&
+                   storage->handlers->dtor == zend_mm_mem_win32_dtor &&
                    storage->handlers->init == zend_mm_mem_win32_init) {
                    HeapDestroy((HANDLE)storage->data);
                    storage->data = (void*)HeapCreate(HEAP_NO_SERIALIZE, 0, 0);