PHP Memory Management

Source: Internet
Author: User

PHP memory management is divided into three levels interface layer-"heap layer-" storage layer (malloc) by Zend Engine processing

PHP underlying memory management, around the Block Memory list (free_buckets), block
Memory list (large_free_buckets) and the remaining memory list (Rest_buckets) three lists to be layered into. ZENDMM to
The system enters the memory request, does not have the need to apply to the system immediately,? is the first zendmm (heap layer) to the system
Please?? Block of memory, through the three kinds of list of the fill, build?? A management mechanism similar to a memory pool. Need to make the program operational?
Memory, ZENDMM allocates the appropriate memory in the memory pool. The benefit of this is to avoid PHP's frequent system-wide
Deposit Request Operation

ZENDMM the processing of memory allocation mainly has the following steps:
TIPI: Deep understanding of PHP kernel release_2012-04-04_v0.7.3
1. Memory check. For the memory to be applied?? Check in, if too? (out of Memory_limit is reported out of Memory);
2. If the cache is hit, Fastcache get the memory block (see section Fifth), then go directly to step 5th;
3. Search for the appropriate ZENDMM in the heap storage managed by?? Block of memory, in this? Step ZENDMM through the
Zend_mm_max_small_size into???? The memory requests are divided into two types: large and small. Small
Type of the request will first make the Zend_mm_low_bit function look in the free_buckets in Mm_heap, and the
The same type of large: The Zend_mm_search_large_block function in the "? Block" Memory
(_zend_mm_heap->large_free_buckets) in-the-go search. If you haven't been able to fill??? Requirements of the memory, the most
After the rest_buckets in the search. In other words, the allocation of memory is in three kinds of lists? Find a way to make
After the block, enter the 5th step;
4. If the search for the 3rd step has not found a resource that can be made (the requested memory over?), need to make?
The Zend_mm_storage_alloc function applies to the system again. Block Memory (??? Less for
zend_mm_seg_size), then assign the aligned address directly to this request. Jump to the 6th step;
5. The Zend_mm_remove_from_free_list function will already have the block node removed in the Zend_mm_free_block;
6. Memory allocation completed, the ZEND_MM_HEAP structure of the various types of identification variables in the maintenance, including Large_free_buckets,
Peak,size, etc.;
7. Return the allocated memory address

Garbage collection mechanism see this http://blog.csdn.net/phpkernel/article/details/5734743.

Cow copy when writing see this http://www.laruence.com/2008/09/19/520.html

PHP Memory Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.