PHP kernel research (memory management 1)

Source: Internet
Author: User
PHP kernel (memory management 1) PHP memory management
  • Before 5.3, PHP used the reference counting method.
  • PHP adopted a new garbage collection mechanism after 5.3
  • The operating system calls back when applying for memory space.
  • When the operating system applies for memory space, it will switch the CPU from the user state to the kernel state, the switching cost is very high (will cause performance problems)
  • PHP default maximum memory usage 32 M
    In php. ini

    memory_limit=32M

    Or use the dynamic mode to modify the maximum memory:

      

  • Obtain current memory usage

    Memory_get_usage () // Current memory size used by the PHP script memory_get_peak_usage () // return the memory usage peak at the current position, so that you can know the memory peak autoload () // avoid containing classes that may not be used at one time

  • PHP memory distribution and management

    | Application-layer Applecation |
    | ----- |
    | Interface layer Emalloc/efree | Heap | storage layer Storange |
    | Malloc | win32 | mmap_anon | mmap_zero |

  • Storage layer: use malloc and mmap to apply for real space from the system and release the space using the free function.
  • Control Layer: controls the entire memory management process (control layer is the core of PHP memory management)
  • Use macro definition to separate upper and lower layers (facade mode)
  • Memory management
  • Initialization:

    Zend_mm_startup (); // initialize the storage layer zend_mm_startup_ex (); // initialize the heap layer ZEND_MM_SEG_SIZE // Default 256 * 1024ZEND_MM_SEG_SIZE // Four default memory allocation schemes

  • PHP memory maintenance list
    1. Small memory table: free_buckets
    2. Large memory table: larg_free_buckets
    3. Remaining memory table: rest_buckets

      The first two are HashTable, and each HashTable has its own hash function.

    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.