At 12:46 02/09/2003, Vesselin Atanasov wrote:
Hello.
The memory cache code in zend_alloc.c has serious problems with memory fragmentation.
When a big script is run which allocates both lots of small objects and
a few big objects, the memory cache grows until the allowed limits
(11 buckets x 256 blocks each) keeping all of the cached memory occupied although
the script uses much less memory. This is caused by the cache code which caches small
objects and does not allow the low level memory manager (either the zend_mm.c or the
C runtime malloc) to merge small free blocks into bigger free blocks. From the point
of view of the low level memory manager there are lots of occupied memory blocks
interspersed among the allocated memory segment. the occupied memory blocks are
actually cached by the high level cache code. So when the script is run a new segment
is allocated although there is free memory. With each call new segment(s) are allocated
until the memory cache is full. This scenario happens when a script first creates lots
of small objects and then a few large objects. Even if the small objects are freed,
the memory is fragmented and a new block is occupied for the big object(s). So with
each request the lost memory increases, effectively this is like a memory leak.
I attach a patch which adds --disable-memory-cache option which disables the memory
cache.

Vesselin,


The memory fragmentation issues were reported by Sterling a few weeks ago - we know they're there. The simplest solution appears to be decreasing the zend_mm block size to 16KB instead of 256KB. Due to bugs elsewhere (libxml2), making this change appeared to cause problems, but with these bugs now fixed - it appears to work fine. After we perform some more benchmarks we'll commit this change.
Disabling memory caching altogether is probably not a good idea since PHP allocates and frees small blocks VERY often.


Zeev

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to