Skip to content

Stdlib: memory_get_usage()/memory_get_peak_usage() real_usage peaks must dominate emalloc (zend_alloc.c) #4933

Closed

Description

@PurHur

Category

stdlib

Problem

When real_usage=true, Zend reports malloc/system memory (RSS / zend_mm_heap real size). The emalloc subset (real_usage=false) is always ≤ the real peak in normal processes.

VmMemory currently uses RSS for both code paths (readEmallocApprox() calls readRssBytes()), so peaks are tracked in separate counters from the same source and ordering breaks:

memory_get_usage(true) >= memory_get_usage(false);        // Zend: true
memory_get_peak_usage(true) >= memory_get_peak_usage(false); // Zend: true

VM today prints false for both comparisons (maintainer probe 2026-06-03).

Distinct from broad tracker #3280 (stdlib introspection batch) — this is the real_usage vs emalloc semantics bug in VmMemory / phpc_memory.c.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/memory_real_usage_order.php
php bin/vm.php test/repro-maintainer/memory_real_usage_order.php'
Check Zend PHP 8.2 bin/vm.php
memory_get_usage(true) >= memory_get_usage(false) true false
memory_get_peak_usage(true) >= memory_get_peak_usage(false) true false

Scope

Path Notes
ext/standard/VmMemory.php stop conflating emalloc peak with RSS
lib/AOT/runtime/phpc_memory.c mirror Zend dual counters for AOT
Tests test/compliance/cases/stdlib/memory_real_usage_order.phpt

Done when

  • real_usage=false uses emalloc/custom heap approximation (not RSS)
  • real_usage=true uses RSS / zend_mm real size
  • Peak counters satisfy real >= emalloc after warm-up calls
  • ./script/ci-fast.sh --filter memory_real_usage_order green

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 3, 2026
  2. PurHur commented on Jun 3, 2026

    @PurHur
    OwnerAuthor

    Repro script (add under test/repro-maintainer/)

    ```php

    =emalloc: ', ($ur >= $u ? 'true' : 'false'), PHP_EOL; echo 'peak real>=emalloc: ', ($pur >= $pu ? 'true' : 'false'), PHP_EOL; \`\`\` Zend prints both `true`; VM currently prints both `false` when `VmMemory` maps both paths to RSS.
  3. PurHur commented on Jul 12, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-b — starting this run

  4. PurHur commented on Jul 12, 2026

    @PurHur
    OwnerAuthor

    claim released: repro green on master — both memory_get_usage(true) >= memory_get_usage(false) and peak ordering return true on VM (Docker php-env). VmMemory already uses MemoryAccounting for emalloc and RSS for real_usage. Pivoting.

  5. PurHur commented on Jul 17, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-b — verifying prior fix / closing if green

    Trust gates (master):

    • php script/bootstrap-inventory.php --check → OK 5310/5310
    • ./script/release-readiness.sh --json → user_release_ready: yes (inventory, spine, north-star5-fast, vm-driver-probe all ok)

    Repro (Docker php-env):

    ZEND: usage real>=emalloc: true / peak real>=emalloc: true
    VM:   usage real>=emalloc: true / peak real>=emalloc: true
    

    Inline probe matches prior release comment (2026-07-12): VmMemory already separates emalloc vs RSS. Closing as done.

  6. PurHur commented on Jul 17, 2026

    @PurHur
    OwnerAuthor

    Closed: done-when already met on master (no PR needed).

    Verified 2026-07-17 in Docker:

    • memory_get_usage(true) >= memory_get_usage(false) → true (VM + Zend)
    • memory_get_peak_usage(true) >= memory_get_peak_usage(false) → true (VM + Zend)

    Prior worker note (2026-07-12) was correct — dual counters via MemoryAccounting/RSS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions