Skip to content

php-in-php: VmMemory RSS path — remove host getrusage() fallback for bootstrap self-host (#4862, #3280) #7287

Description

@PurHur

Category

php-in-php | bootstrap

Problem

ext/standard/VmMemory.php::readRssBytes() falls back to host getrusage() when /proc/self/statm is unreadable:

if (\function_exists('getrusage')) {
    $ru = getrusage();
    ...
}

On the self-host path (native AOT binary, no Zend PHP), this either calls a host builtin during bootstrap or returns 0 silently — breaking parity for memory_get_usage(true) / memory_get_peak_usage(true) and gc_status() memory fields tracked in #3280.

Bootstrap inventory flags any function_exists('getrusage') delegation in compiler-owned paths.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
# Host path may work; AOT binary without Zend must not call host getrusage:
grep -n getrusage ext/standard/VmMemory.php
php bin/vm.php -r "echo memory_get_usage(true), PHP_EOL;"
# After fix: same numeric semantics via /proc or emalloc table only
'

Build AOT hello-world and verify memory_get_usage(true) > 0 without host PHP installed (#1492 M3 probe).

Scope (this repo)

Path Work
ext/standard/VmMemory.php /proc/self/statm primary; optional phpc_read_rss thin ABI if needed — delete host getrusage()
ext/standard/JitMemory.php / lib/JIT/Builtin/MemoryRuntime.php Mirror RSS source for JIT/AOT
ext/standard/memory_get_usage.php Document real_usage path
Tests Extend test/compliance/cases/stdlib/memory_get_usage*.phpt

Shrink C if adding ABI; prefer pure PHP /proc read already used in JIT path.

Done when

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 7, 2026
  2. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (#7287: remove host getrusage() fallback from VmMemory, align VM with MemoryRuntime /proc path).

  3. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Unclaiming #7287 this run — switching to #7189 (hash_crypto_jit_runtime.c ~800 lines, primary remaining JIT C runtime). #7287 remains a quick follow-up.

  4. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — resuming #7287 (remove VmMemory getrusage fallback).

  5. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Merged via PR #7288.

    Change: VmMemory::readRssBytes() now reads RSS exclusively from /proc/self/statm — removed host getrusage() fallback so bootstrap/AOT binaries do not delegate to Zend PHP for memory_get_usage(true).

    Verification (Docker):

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    vendor/bin/phpunit test/unit/VmMemoryTest.php
    php bin/vm.php test/repro-maintainer/memory_native.php
    php bin/vm.php -r "echo memory_get_usage(true), PHP_EOL;"
    '
    • VmMemoryTest: OK (2/2)
    • memory_native repro: grow / peak / real
    • memory_get_usage(true) > 0 on Linux harness
  6. added a commit that references this issue on Jun 10, 2026
    918fc95
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:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions