diff --git a/crates/metal2vulkan-validation/src/authored_compile.rs b/crates/metal2vulkan-validation/src/authored_compile.rs index 87dea6b4b..319f10aff 100644 --- a/crates/metal2vulkan-validation/src/authored_compile.rs +++ b/crates/metal2vulkan-validation/src/authored_compile.rs @@ -356,7 +356,7 @@ pub struct Cost { pub elapsed: Duration, /// The slowest compile's time. pub slowest: Duration, - /// The largest sampled process-group RSS of a compile worker. + /// The largest sampled process-group memory of a compile worker. pub peak_resident_bytes: Option, /// The largest counting-allocator peak a compile worker reported. pub allocator_peak_bytes: Option, @@ -478,7 +478,7 @@ pub const CASE_WORKER_ARG: &str = "--authored-compile-case-worker"; /// runs [`compile_case`] over the corpus at `root`, reading private sources by the byte ranges the /// index at `index` records (`source::use_source_index`). The case's admission, its sources, its linked /// modules, its templates, and its compile inputs live in that child, under the 500-MiB ceiling -/// (its process group's RSS and its counting allocator), and go with it; the census's process +/// (its process group's memory and its counting allocator), and go with it; the census's process /// holds the committed cases and the cells, whatever the cases' sizes. The child's wall ceiling is /// a safety rail of [`CaseWorkers::deadline`]: each compile in it has its own 20-s ceiling. pub struct CaseWorkers { @@ -1287,12 +1287,13 @@ pub struct Report { pub blessed: bool, pub written: bool, /// Of the cells compiled in this run: the slowest single compile, the slowest cell (its - /// compiles summed), and the largest worker RSS and allocator peak. + /// compiles summed), and the largest worker memory and allocator peak. pub slowest_compile: Option, pub slowest_cell: Option, pub peak_resident: Option, pub peak_allocator: Option, - /// Of the case workers this run spawned: the slowest, and the largest RSS and allocator peak. + /// Of the case workers this run spawned: the slowest, and the largest memory and allocator + /// peak. pub case_workers: usize, /// How the case workers found the private sources they read: by the index's byte ranges, or /// by parsing a whole shard (a source the index does not locate). diff --git a/crates/metal2vulkan-validation/src/bin/corpus-pipeline.rs b/crates/metal2vulkan-validation/src/bin/corpus-pipeline.rs index 038e4379f..ad1eec9ad 100644 --- a/crates/metal2vulkan-validation/src/bin/corpus-pipeline.rs +++ b/crates/metal2vulkan-validation/src/bin/corpus-pipeline.rs @@ -615,10 +615,10 @@ struct Tally { /// The current row's compile worker time, when the worker reported one: its row's last /// column. row_compile: Option, - /// The peak compile-worker process-group RSS. + /// The peak compile-worker process-group memory. peak_compile_rss: Option<(String, u64)>, - /// The largest counting-allocator peak a compile worker reported, which the RSS sampler can - /// miss. + /// The largest counting-allocator peak a compile worker reported, which the memory sampler + /// can miss. peak_compile_allocator: Option<(String, u64)>, } diff --git a/crates/metal2vulkan-validation/src/bin/corpus-triage.rs b/crates/metal2vulkan-validation/src/bin/corpus-triage.rs index d80493740..74ca874e5 100644 --- a/crates/metal2vulkan-validation/src/bin/corpus-triage.rs +++ b/crates/metal2vulkan-validation/src/bin/corpus-triage.rs @@ -165,7 +165,7 @@ fn run() -> Result<(), String> { } "-h" | "--help" => { println!( - "usage: corpus-triage [--corpus DIR] [--private-corpus DIR] [--index PATH] [--limit N] [--jobs N] [--summary-only] [--audit authoring-capabilities [--reclassify-all] | --audit rasterization-rate-maps|sample-rate|ulong-textures|fragment-varyings|linked-functions|tile-functions|mesh-draws|bitcode-reader [--after SHA256] | --audit bitcode-reader --library-modules [--after SHA256] | --audit translation --profile P... [--after SHA256] [--current-fingerprint | --retry-failures | --hash-file PATH] | --audit budgets --profile P... | --audit specialization --profile P... [--hash-file PATH] | --audit authored-compile [--expectations PATH] [--bless [--profile P]... | --bless-additions | --case ID... [--profile P]...]]\n\n--audit authored-compile compiles every committed authored case of --corpus without a device, with the requests the engine executor builds for it (its constants, linked modules, bind shape, dispatch, and companion stage), on each profile of the expectation file (--expectations, by default authored-compile.tsv under the corpus root), each pipeline in a compile worker under the 20-s and 500-MiB ceilings, --jobs cases at once. Each case's outcome on each profile (compiled, or the executor's refusal label) is cached in the index under the product's census key, the executor ABI, and the census's version, so a warm rerun compiles nothing; failures are never cached. It fails on any failed cell (an internal error, a worker stop, a case that does not check or map) and on any difference from the expectation file (a regression, a changed refusal, a newly compiled case, a new or removed case). --bless rewrites the file from the run and prints the differences (never with a failed cell); with --profile it compiles those profiles instead of the file's. --bless-additions (each train's gate step) compiles the file's profiles plus every C3 venue's profile the file lacks (crates/metal2vulkan-validation/cutover/c3-venues.json), fails as a check does on any failed cell and on any changed cell of a case and profile the file holds, writing nothing, and otherwise writes the file with the new cases and profiles added and the removed cases dropped, only when that changes it; its authored-compile-additions line counts what it added and removed. Each case is admitted, prepared, and compiled in its own case worker (a child of this binary under the 500-MiB ceiling, its wall ceiling 20 s plus 40 s per profile), so this process holds only the committed cases and their cells; a case worker reads each private source by the byte range --index records (read only, never repaired), and one the index does not locate by parsing its whole shard (counted as sources_by_range and sources_by_shard). --case ID (repeatable) is a probe: it compiles only those committed cases (on --profile's profiles when named, else the file's), prints an authored-compile-cell line per cell with its outcome or failure and what its compiles measured, and compares those cases' rows with the expectation file when it exists; it never blesses.\n\n--audit translation translates each row's retained bitcode (a public .ll row, which retains none, is assembled with llvm-as) with the engine for every --profile P (a committed profile under crates/metal2vulkan-validation/profiles, derived under the default untrusted policy), one profile after another, and records typed outcome classes under a per-profile census key (the product sources, SEMANTICS_VERSION, the lane's version, the profile, and the llvm-as and spirv-val versions; no other validation source); its summary is the non-gating shadow census. Rows stream from the index through the workers, so the parent's memory does not grow with --limit. --jobs defaults to the host's available logical CPU count (the equivalent of nproc). An explicit --jobs N overrides that default. --hash-file reads a whitespace-delimited SHA-256 from the first field of each non-empty line and audits exactly those indexed sources. --audit bitcode-reader decodes each selected row's retained bitcode with the engine's reader and compares its structure with llvm-dis (METAL2VULKAN_LLVM_DIS); it also reports the intrinsic census (calls decoded to air.*/llvm.* and every name kept as an unknown intrinsic, with rows, calls, and whether the decoder lists its family as not decoded) and every function called but declared without a body that is no intrinsic (what the module needs linked), with rows and calls; without --summary-only, each row's such functions too. Without --library-modules it only reads the index. With --library-modules it first syncs the library-module index with the module shards on disk (incrementally: only a new or changed shard is opened, and a warm index opens none), then selects the indexed library modules (the linked dependencies harvest retains apart from the sources) instead of the sources, in module-hash order after --after, at most --limit, reading only the selected modules' byte ranges. --audit bitcode-reader runs each attempt (a row's decode) in its own killable worker under the 20-s and 500-MiB ceilings: a stopped attempt is reported as worker-stopped and counted in worker_stopped, beside the workers' peak RSS, allocator peak, and slowest time. --audit budgets reports the budget gates of each --profile P from the rows the current engine fingerprint recorded (slowest row, p50/p99 attempt time, peak worker RSS and the largest counting-allocator peak a worker reported, and the ledger >= 0.7 x allocator-peak check); a row stopped at the memory ceiling or by a worker abort, or refused at an in-process budget, fails it whatever its measure. It only reads the index and fails when a gate fails. Timeouts are transient and never recorded, so --audit budgets cannot see them; instead --audit translation exits non-zero when its batch has a budget stop (a timeout, OOM, worker abort, or in-process budget refusal) or a row above the 20-s or 500-MiB ceiling (its sampled RSS or its allocator peak), after reporting every profile (translation-audit-budgets-failure lines name them). Its outcome classes, shadow census, and batch ledger lines stay non-gating. --audit specialization first plans, in killable workers, every indexed row without a plan under the planner key (the product's sources, the lane's version, the census tools) or whose authored cases changed: the row's declared function constants and their value sets (the authored cases' sets; zero and one, which leave optional constants undefined; zero_defined and one_defined; a strength-2 binary covering array over every constant), kept whole when over the 16-set bound and reported. It plans at most --limit rows, in hash order (a row not yet planned has no set selected; the summaries count them). Then, for each --profile P in turn, it translates each planned set of each planned row, and each row whose current plain engine census outcome (which must cover every indexed row) is needs_input other than a function constant under the inputs set (no constants), at most --limit attempts (whole rows), each attempt in its own killable worker under the 20-s and 500-MiB ceilings, deriving the inputs the row's AIR states (a kernel's stage-input descriptor, a post-tessellation vertex descriptor, tile attachment formats, a storage texture's format, a visible function's retained module). Attempts are recorded in the lane's own table under the profile's engine census key extended by the lane's version; transient outcomes are not recorded. It prints the planning batch and the plans' summary (with the fifth function-constant operand's agreement with \"required\"), then per profile the batch (with its lanes and budgets) and the report over every recorded attempt: rows by plain outcome, outcomes by kind, inputs derived and left with their reasons, refusal classes ranked by rows with their value-dependent rows (ray-tracing classes listed apart), and the recorded attempts' budgets. With --hash-file (read as the translation audit reads it) it plans and attempts only those rows, and prints, per profile, one specialization-row line per selected row: a prefix of its hash, its plain outcome and key, how many sets it was attempted and translated under, under which sets it translates (every, some, none, or unattempted), and every other outcome with the number of sets that reached it. It exits non-zero, after reporting everything, when a planning or attempt worker was stopped at or ran above a ceiling, or an attempt's ledger peak is below 7/10 of its allocator peak (each compile of an attempt is metered and measured on its own, and the attempt's cost is its last compile's)." + "usage: corpus-triage [--corpus DIR] [--private-corpus DIR] [--index PATH] [--limit N] [--jobs N] [--summary-only] [--audit authoring-capabilities [--reclassify-all] | --audit rasterization-rate-maps|sample-rate|ulong-textures|fragment-varyings|linked-functions|tile-functions|mesh-draws|bitcode-reader [--after SHA256] | --audit bitcode-reader --library-modules [--after SHA256] | --audit translation --profile P... [--after SHA256] [--current-fingerprint | --retry-failures | --hash-file PATH] | --audit budgets --profile P... | --audit specialization --profile P... [--hash-file PATH] | --audit authored-compile [--expectations PATH] [--bless [--profile P]... | --bless-additions | --case ID... [--profile P]...]]\n\n--audit authored-compile compiles every committed authored case of --corpus without a device, with the requests the engine executor builds for it (its constants, linked modules, bind shape, dispatch, and companion stage), on each profile of the expectation file (--expectations, by default authored-compile.tsv under the corpus root), each pipeline in a compile worker under the 20-s and 500-MiB ceilings, --jobs cases at once. Each case's outcome on each profile (compiled, or the executor's refusal label) is cached in the index under the product's census key, the executor ABI, and the census's version, so a warm rerun compiles nothing; failures are never cached. It fails on any failed cell (an internal error, a worker stop, a case that does not check or map) and on any difference from the expectation file (a regression, a changed refusal, a newly compiled case, a new or removed case). --bless rewrites the file from the run and prints the differences (never with a failed cell); with --profile it compiles those profiles instead of the file's. --bless-additions (each train's gate step) compiles the file's profiles plus every C3 venue's profile the file lacks (crates/metal2vulkan-validation/cutover/c3-venues.json), fails as a check does on any failed cell and on any changed cell of a case and profile the file holds, writing nothing, and otherwise writes the file with the new cases and profiles added and the removed cases dropped, only when that changes it; its authored-compile-additions line counts what it added and removed. Each case is admitted, prepared, and compiled in its own case worker (a child of this binary under the 500-MiB ceiling, its wall ceiling 20 s plus 40 s per profile), so this process holds only the committed cases and their cells; a case worker reads each private source by the byte range --index records (read only, never repaired), and one the index does not locate by parsing its whole shard (counted as sources_by_range and sources_by_shard). --case ID (repeatable) is a probe: it compiles only those committed cases (on --profile's profiles when named, else the file's), prints an authored-compile-cell line per cell with its outcome or failure and what its compiles measured, and compares those cases' rows with the expectation file when it exists; it never blesses.\n\n--audit translation translates each row's retained bitcode (a public .ll row, which retains none, is assembled with llvm-as) with the engine for every --profile P (a committed profile under crates/metal2vulkan-validation/profiles, derived under the default untrusted policy), one profile after another, and records typed outcome classes under a per-profile census key (the product sources, SEMANTICS_VERSION, the lane's version, the profile, and the llvm-as and spirv-val versions; no other validation source); its summary is the non-gating shadow census. Rows stream from the index through the workers, so the parent's memory does not grow with --limit. --jobs defaults to the host's available logical CPU count (the equivalent of nproc). An explicit --jobs N overrides that default. --hash-file reads a whitespace-delimited SHA-256 from the first field of each non-empty line and audits exactly those indexed sources. --audit bitcode-reader decodes each selected row's retained bitcode with the engine's reader and compares its structure with llvm-dis (METAL2VULKAN_LLVM_DIS); it also reports the intrinsic census (calls decoded to air.*/llvm.* and every name kept as an unknown intrinsic, with rows, calls, and whether the decoder lists its family as not decoded) and every function called but declared without a body that is no intrinsic (what the module needs linked), with rows and calls; without --summary-only, each row's such functions too. Without --library-modules it only reads the index. With --library-modules it first syncs the library-module index with the module shards on disk (incrementally: only a new or changed shard is opened, and a warm index opens none), then selects the indexed library modules (the linked dependencies harvest retains apart from the sources) instead of the sources, in module-hash order after --after, at most --limit, reading only the selected modules' byte ranges. --audit bitcode-reader runs each attempt (a row's decode) in its own killable worker under the 20-s and 500-MiB ceilings: a stopped attempt is reported as worker-stopped and counted in worker_stopped, beside the workers' peak memory, allocator peak, and slowest time. --audit budgets reports the budget gates of each --profile P from the rows the current engine fingerprint recorded (slowest row, p50/p99 attempt time, peak worker memory and the largest counting-allocator peak a worker reported, and the ledger >= 0.7 x allocator-peak check); a row stopped at the memory ceiling or by a worker abort, or refused at an in-process budget, fails it whatever its measure. It only reads the index and fails when a gate fails. Timeouts are transient and never recorded, so --audit budgets cannot see them; instead --audit translation exits non-zero when its batch has a budget stop (a timeout, OOM, worker abort, or in-process budget refusal) or a row above the 20-s or 500-MiB ceiling (its sampled memory or its allocator peak), after reporting every profile (translation-audit-budgets-failure lines name them). Its outcome classes, shadow census, and batch ledger lines stay non-gating. --audit specialization first plans, in killable workers, every indexed row without a plan under the planner key (the product's sources, the lane's version, the census tools) or whose authored cases changed: the row's declared function constants and their value sets (the authored cases' sets; zero and one, which leave optional constants undefined; zero_defined and one_defined; a strength-2 binary covering array over every constant), kept whole when over the 16-set bound and reported. It plans at most --limit rows, in hash order (a row not yet planned has no set selected; the summaries count them). Then, for each --profile P in turn, it translates each planned set of each planned row, and each row whose current plain engine census outcome (which must cover every indexed row) is needs_input other than a function constant under the inputs set (no constants), at most --limit attempts (whole rows), each attempt in its own killable worker under the 20-s and 500-MiB ceilings, deriving the inputs the row's AIR states (a kernel's stage-input descriptor, a post-tessellation vertex descriptor, tile attachment formats, a storage texture's format, a visible function's retained module). Attempts are recorded in the lane's own table under the profile's engine census key extended by the lane's version; transient outcomes are not recorded. It prints the planning batch and the plans' summary (with the fifth function-constant operand's agreement with \"required\"), then per profile the batch (with its lanes and budgets) and the report over every recorded attempt: rows by plain outcome, outcomes by kind, inputs derived and left with their reasons, refusal classes ranked by rows with their value-dependent rows (ray-tracing classes listed apart), and the recorded attempts' budgets. With --hash-file (read as the translation audit reads it) it plans and attempts only those rows, and prints, per profile, one specialization-row line per selected row: a prefix of its hash, its plain outcome and key, how many sets it was attempted and translated under, under which sets it translates (every, some, none, or unattempted), and every other outcome with the number of sets that reached it. It exits non-zero, after reporting everything, when a planning or attempt worker was stopped at or ran above a ceiling, or an attempt's ledger peak is below 7/10 of its allocator peak (each compile of an attempt is metered and measured on its own, and the attempt's cost is its last compile's)." ); return Ok(()); } @@ -3088,7 +3088,7 @@ mod tests { Measured::default(), ), "oom", - "worker exceeded 1 byte process-group resident-memory budget (measured 2 bytes): ", + "worker exceeded 1 byte process-group memory budget (measured 2 bytes): ", ), ( WorkerFailure::Exit("abort".into(), Measured::default()), diff --git a/crates/metal2vulkan-validation/src/budgets.rs b/crates/metal2vulkan-validation/src/budgets.rs index 8e9a4b0a9..2aa218064 100644 --- a/crates/metal2vulkan-validation/src/budgets.rs +++ b/crates/metal2vulkan-validation/src/budgets.rs @@ -1,12 +1,12 @@ //! Budget gates over recorded engine rows. //! //! Every engine translation sweep records each row's measured cost (the worker's wall time -//! and process-group RSS, the meter's ledger peak and work units, the counting allocator's peak +//! and process-group memory, the meter's ledger peak and work units, the counting allocator's peak //! attributable bytes, the final words, and each strategy's emitted words). [`BudgetReport`] //! derives the L7 gates from those rows: //! -//! - **Time and memory:** the slowest row, the p50/p99 attempt time, and the peak worker RSS, -//! including rows the worker boundary stopped (their wall time and peak RSS up to the stop). +//! - **Time and memory:** the slowest row, the p50/p99 attempt time, and the peak worker memory, +//! including rows the worker boundary stopped (their wall time and peak memory up to the stop). //! Every row the boundary stopped (`failed timeout`, `failed oom`, `failed worker_exit`) and //! every in-process budget refusal (`limit_exceeded budget`, which trips before the ceilings) //! fails the gate whatever its measure, because a stop is a breach even when the sample that @@ -193,10 +193,10 @@ pub struct BudgetReport { pub p99_ms: Option, pub peak_resident: Option<(String, u64)>, /// The largest counting-allocator peak a worker reported (above its budget's baseline), and - /// its row: exact where the 10-ms RSS sampler behind [`BudgetReport::peak_resident`] can miss a - /// short peak. It is recorded evidence the worker's in-child budget bounds by 500 MiB (an - /// allocation past it aborts the worker, a budget stop), not an independent gate, and it covers - /// only the [`BudgetReport::allocator_measured`] rows. + /// its row: exact where the 10-ms memory sampler behind [`BudgetReport::peak_resident`] can + /// miss a short peak. It is recorded evidence the worker's in-child budget bounds by 500 MiB + /// (an allocation past it aborts the worker, a budget stop), not an independent gate, and it + /// covers only the [`BudgetReport::allocator_measured`] rows. pub peak_allocator: Option<(String, u64)>, /// Timed rows whose worker reported an allocator peak: rows recorded previously have none, so /// [`BudgetReport::peak_allocator`] is over these rows, not every timed one. @@ -305,7 +305,7 @@ impl BudgetReport { /// The per-attempt ceiling breaches (AGENTS.md: 20 s and 500 MiB per translation attempt), /// one line each: every budget stop, the slowest row above the deadline, and the peak worker - /// RSS above the memory limit. Each is a failing result on its own, so the engine + /// memory above the memory limit. Each is a failing result on its own, so the engine /// translation sweep exits non-zero on any of them in the batch it ran; the ledger gate is /// [`BudgetReport::failures`]' alone. pub fn ceiling_breaches(&self) -> Vec { @@ -735,7 +735,7 @@ mod tests { assert!(breaches[0].starts_with("time: slow took 20001 ms")); assert!(breaches[1].starts_with("memory: big peaked at")); - // A short peak the RSS sampler missed is recorded from the allocator, up to the most the + // A short peak the memory sampler missed is recorded from the allocator, up to the most the // in-child budget admits (the whole budget), which is no breach; a row recorded before // the allocator was measured is not counted as measured. let missed = [ diff --git a/crates/metal2vulkan-validation/src/specialization/audit.rs b/crates/metal2vulkan-validation/src/specialization/audit.rs index 811506356..1bf4a9aa4 100644 --- a/crates/metal2vulkan-validation/src/specialization/audit.rs +++ b/crates/metal2vulkan-validation/src/specialization/audit.rs @@ -40,8 +40,10 @@ use std::path::Path; /// not their sum. 6: a visible-function table's stop is structural, taken after a compile that /// translated and used a table, where it was taken at the compile's `NeedsInput` before; a row /// whose table has candidates is translated with them, and every row whose table the stop reached -/// records it, with no candidate where there was none to link. -pub const SPECIALIZATION_AUDIT_VERSION: u32 = 6; +/// records it, with no candidate where there was none to link. 7: a planning or attempt worker's +/// group member is charged what the system compressed or swapped out of its memory beside what it +/// holds resident. +pub const SPECIALIZATION_AUDIT_VERSION: u32 = 7; const PRODUCT_FINGERPRINT: &str = env!("METAL2VULKAN_PRODUCT_FINGERPRINT"); diff --git a/crates/metal2vulkan-validation/src/translation_audit.rs b/crates/metal2vulkan-validation/src/translation_audit.rs index 14519d239..ce6a21859 100644 --- a/crates/metal2vulkan-validation/src/translation_audit.rs +++ b/crates/metal2vulkan-validation/src/translation_audit.rs @@ -41,8 +41,9 @@ const PRODUCT_FINGERPRINT: &str = env!("METAL2VULKAN_PRODUCT_FINGERPRINT"); /// in its L3 stage, a fresh image of itself, so an attempt's peak is the larger of its /// translation's and its validation's, not their sum. 7: a fragment function refused for writing /// more colors than the profile draws at once is translated in color groups, one module a group, -/// each checked by L3. 8: such a function keeps its limit refusal. -pub const ENGINE_CENSUS_VERSION: u32 = 8; +/// each checked by L3. 8: such a function keeps its limit refusal. 9: a worker group member is +/// charged what the system compressed or swapped out of its memory beside what it holds resident. +pub const ENGINE_CENSUS_VERSION: u32 = 9; /// The external tools a census row can depend on: `llvm-as` (a public row's bitcode) and /// `spirv-val` (L3). Each is keyed by its `--version` output. @@ -203,10 +204,10 @@ pub struct EngineAuditResult { pub struct WorkerMeasure { /// From preparing the worker's input through decoding its result. pub elapsed_ms: u64, - /// The worker process group's peak sampled RSS (worker, `spirv-val`, and any descendant). + /// The worker process group's peak sampled memory (worker, `spirv-val`, and any descendant). #[serde(default, skip_serializing_if = "Option::is_none")] pub peak_resident_bytes: Option, - /// The worker's counting-allocator peak, as its report states it: exact where the 10-ms RSS + /// The worker's counting-allocator peak, as its report states it: exact where the 10-ms memory /// sampler can miss a short peak. Absent when the worker reported no result, and in rows /// recorded before it was measured. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -214,8 +215,9 @@ pub struct WorkerMeasure { } impl WorkerMeasure { - /// The larger of the sampled RSS and the allocator peak ([`crate::worker::Measured::peak_bytes`]): - /// the measure the 500-MiB ceiling is checked against. + /// The larger of the sampled memory and the allocator peak + /// ([`crate::worker::Measured::peak_bytes`]): the measure the 500-MiB ceiling is checked + /// against. pub fn peak_bytes(&self) -> Option { self.peak_resident_bytes.max(self.allocator_peak_bytes) } diff --git a/crates/metal2vulkan-validation/src/worker.rs b/crates/metal2vulkan-validation/src/worker.rs index 51ee796f4..408658552 100644 --- a/crates/metal2vulkan-validation/src/worker.rs +++ b/crates/metal2vulkan-validation/src/worker.rs @@ -10,12 +10,13 @@ //! [`run_json`] is the one parent-side exchange: the input goes to the child's stdin from a //! scratch file (no feeder thread per row), the child writes one JSON report to stdout //! ([`report`]: its result, its counting allocator's process peak and its resident high water), -//! and every scratch file is removed before the call returns. The parent samples the group's RSS -//! every 10 ms, which can miss a short peak or a whole worker that runs between two samples: the -//! result's peak also takes the high water the worker states, and the allocator's peak, counted -//! exactly in the child, is recorded beside it in every result ([`Measured`]). Each member is -//! charged only memory of its own, never its parent's while it still runs in it ([`process`]), -//! and a supervising process gives its large freed buffers back to the system +//! and every scratch file is removed before the call returns. The parent samples the group's +//! memory (each member's resident memory and what the system compressed or swapped out of it, +//! [`process`]) every 10 ms, which can miss a short peak or a whole worker that runs between two +//! samples: the result's peak also takes the high water the worker states, and the allocator's +//! peak, counted exactly in the child, is recorded beside it in every result ([`Measured`]). Each +//! member is charged only memory of its own, never its parent's while it still runs in it +//! ([`process`]), and a supervising process gives its large freed buffers back to the system //! ([`alloc::release_large_frees`]), so its own RSS does not grow from sweep to sweep. //! [`compile`] runs every engine pipeline compile of a device-holding tool (L4 acceptance, the //! engine candidate, the device tests) through it, and [`audit`] every attempt of the canon and @@ -47,7 +48,8 @@ use std::time::{Duration, Instant}; /// The per-attempt wall ceiling, from handing the input to the worker through its report. pub const DEADLINE: Duration = Duration::from_secs(20); -/// The per-attempt memory ceiling: the worker's process-group RSS (sampled by the parent) and +/// The per-attempt memory ceiling: the worker's process-group memory (sampled by the parent: each +/// member's resident memory and what the system compressed or swapped out of it, [`process`]) and /// the live heap bytes its counting allocator admits above its startup state. pub const MEMORY_LIMIT_BYTES: u64 = 500 * 1024 * 1024; @@ -56,20 +58,20 @@ pub const MEMORY_LIMIT_BYTES: u64 = 500 * 1024 * 1024; pub struct Measured { /// From preparing the input through the result or the stop. pub elapsed: Duration, - /// The peak resident size up to the result or the stop: for a worker that exited, the larger - /// of the sampled process-group RSS and the kernel's peak for the worker at its reap + /// The peak memory up to the result or the stop: for a worker that exited, the larger of the + /// sampled process-group memory ([`process`]) and the kernel's peak for the worker at its reap /// ([`ProcessExit::peak_resident_bytes`]), and for one that reported, of its own resident /// high water as its report states it ([`report`]), so known for every worker that reported /// on Linux and macOS; for a stopped one, the sampled peak alone. pub peak_resident_bytes: Option, /// The worker's counting-allocator peak ([`alloc::peak_bytes`]): the most live heap bytes it - /// held at once, which the RSS sampler can miss. `None` when the worker reported no result + /// held at once, which the memory sampler can miss. `None` when the worker reported no result /// (a stop, an exit, an unreadable report) or counts no allocations. pub allocator_peak_bytes: Option, } impl Measured { - /// The larger of the sampled RSS and the allocator peak, whichever are known: the measure + /// The larger of the peak memory and the allocator peak, whichever are known: the measure /// the 500-MiB ceiling ([`MEMORY_LIMIT_BYTES`]) is checked against. pub fn peak_bytes(&self) -> Option { self.peak_resident_bytes.max(self.allocator_peak_bytes) @@ -262,7 +264,7 @@ impl WorkerFailure { #[derive(Debug)] pub struct WorkerRun { pub result: R, - /// The larger of the peak sampled process-group RSS (the worker and every descendant, e.g. + /// The larger of the peak sampled process-group memory (the worker and every descendant, e.g. /// `spirv-val`, summed), the kernel's peak for the worker alone at its reap /// ([`ProcessExit::peak_resident_bytes`]), and the worker's own resident high water as its /// report states it ([`report`]). @@ -441,7 +443,7 @@ mod tests { .unwrap(); assert_eq!(run.result, vec![1, 2]); assert!(run.elapsed < DEADLINE); - // The allocator's peak is recorded beside the sampled RSS. + // The allocator's peak is recorded beside the sampled memory. assert_eq!(run.allocator_peak_bytes, Some(4096)); let measured = run.measured(); assert_eq!(measured.allocator_peak_bytes, Some(4096)); diff --git a/crates/metal2vulkan-validation/src/worker/alloc.rs b/crates/metal2vulkan-validation/src/worker/alloc.rs index 66ad57586..502986459 100644 --- a/crates/metal2vulkan-validation/src/worker/alloc.rs +++ b/crates/metal2vulkan-validation/src/worker/alloc.rs @@ -3,7 +3,7 @@ //! A worker binary installs [`CountingAllocator`] as its `#[global_allocator]`. It counts live //! heap bytes, keeps a resettable peak, and can refuse allocations above a byte limit, so a row //! that grows past the 500-MiB budget fails as an allocation failure inside the worker (the -//! process-group RSS watchdog in [`super::process`] stays the backstop). +//! process-group memory watchdog in [`super::process`] stays the backstop). //! //! [`measure`] reports the peak live bytes attributable to one closure: the peak during the //! closure minus the live bytes when it started. The counters are process-global, so measurements @@ -13,7 +13,7 @@ //! //! [`peak_bytes`] is the high-water mark of live bytes above the budget's baseline (the live bytes //! at [`enable_budget`], the fixed runtime state the budget does not charge), which no measurement -//! resets: a worker reports it beside the parent's sampled RSS in every result +//! resets: a worker reports it beside the parent's sampled memory in every result //! ([`super::report`]), since a sampler polling every 10 ms can miss a short peak that the //! allocator counts exactly. Under the budget it never exceeds the budget: an allocation past it is //! refused, uncounted, and aborts the worker. diff --git a/crates/metal2vulkan-validation/src/worker/audit.rs b/crates/metal2vulkan-validation/src/worker/audit.rs index 5fd426e6c..65c6fc791 100644 --- a/crates/metal2vulkan-validation/src/worker/audit.rs +++ b/crates/metal2vulkan-validation/src/worker/audit.rs @@ -78,7 +78,7 @@ pub fn read(program: &Path, blob_b64: &str) -> Result<(Reading, Measured), Worke } /// What a lane's attempt workers measured over a sweep: how many ran, how many the boundary -/// stopped, the most resident memory and the largest counting-allocator peak any of them +/// stopped, the most memory and the largest counting-allocator peak any of them /// reached, and the slowest. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct Tally { diff --git a/crates/metal2vulkan-validation/src/worker/compile.rs b/crates/metal2vulkan-validation/src/worker/compile.rs index 28842faf5..9a7971b10 100644 --- a/crates/metal2vulkan-validation/src/worker/compile.rs +++ b/crates/metal2vulkan-validation/src/worker/compile.rs @@ -6,7 +6,7 @@ //! process, never in the process that holds the Vulkan device. [`compile_compute`], //! [`compile_compute_request`], and [`compile_render_request`] run one child per pipeline //! through [`super::run_json`], so the 20-second -//! deadline (input preparation through decoding the artifact), the 500-MiB process-group RSS +//! deadline (input preparation through decoding the artifact), the 500-MiB process-group memory //! limit, and the process-group kill apply to the compile. //! //! The recipe (`docs/HOWTO.md` section 5), step by step: @@ -22,7 +22,8 @@ //! 500-MiB budget, and compiles through the public API ([`compile_pipeline`]: //! `Device::compile_compute_pipeline` or `Device::compile_render_pipeline`) under a `Budget` //! with the 20-s deadline. -//! 3. The parent polls the group (deadline, RSS) and kills it on any breach ([`super::run_json`]). +//! 3. The parent polls the group (deadline, memory) and kills it on any breach +//! ([`super::run_json`]). //! 4. The child writes the pipeline's cache artifact bytes (`PipelineArtifact::to_bytes`) to the //! file the parent names in [`ARTIFACT_FILE`], a chunk at a time (`PipelineArtifact::write_to`), //! so reporting holds little beside the pipeline: a constant blob the ledger admits is never @@ -109,7 +110,7 @@ impl CompileWorker { /// This crate's lib test binary, the running one, serving each compile through its fixture /// test ([`LIB_TESTS_FIXTURE`]) as a binary serves it: in a child of its own process group, - /// under the deadline, the process-group RSS limit and the allocator budget, its scratch + /// under the deadline, the process-group memory limit and the allocator budget, its scratch /// removed. Any selection that runs the lib's tests holds it, where a `--lib` build builds no /// package binary. #[cfg(test)] @@ -214,7 +215,7 @@ pub struct WorkerCompile

{ pub result: Result, /// Peak live heap bytes the compile allocated in the worker (its counting allocator). pub allocator_peak: Option, - /// From preparing the input through decoding the artifact, and the group's peak RSS. + /// From preparing the input through decoding the artifact, and the group's peak memory. pub measured: Measured, } @@ -1112,7 +1113,7 @@ mod tests { /// Never answer: the deadline stops the worker. Stall, /// Hold resident memory the counting allocator never sees (as a driver's or a tool's - /// would be) past the limit: the process-group RSS watchdog stops the worker. + /// would be) past the limit: the process-group memory watchdog stops the worker. Resident, /// Allocate close to the 500-MiB budget, then past it: the allocator admits the first and /// refuses the second, which aborts the worker. diff --git a/crates/metal2vulkan-validation/src/worker/process.rs b/crates/metal2vulkan-validation/src/worker/process.rs index 8b3f08c53..db25a7cb8 100644 --- a/crates/metal2vulkan-validation/src/worker/process.rs +++ b/crates/metal2vulkan-validation/src/worker/process.rs @@ -3,12 +3,15 @@ //! It began as a copy of the product's `src/process.rs`, which 0.2.0 deleted with the old engine's //! CLI: the engine is in-process only, so the killable worker boundary is validation tooling //! and the consumer's out-of-process recipe (`docs/HOWTO.md` section 5), not a product -//! API. It charges a group member only the memory that is its own (`process/linux.rs`). +//! API. It charges a group member only the memory that is its own (`process/linux.rs`): what it +//! holds resident and what the system compressed or swapped out of that (`process_charged_bytes`), +//! since under memory pressure a worker's pages leave its resident set and a sum of resident +//! memory alone stops counting them. #[cfg(target_os = "linux")] mod linux; #[cfg(target_os = "linux")] -use linux::member_resident_bytes; +use linux::member_charged_bytes; #[cfg(any(target_os = "linux", all(test, target_os = "macos")))] use std::fs; @@ -36,7 +39,7 @@ impl std::fmt::Display for ProcessFailure { match self { Self::DeadlineExceeded => f.write_str("worker deadline exceeded"), Self::Cancelled => f.write_str("worker cancelled"), - Self::MemoryLimitExceeded { limit, measured } => write!(f, "worker exceeded {limit} byte process-group resident-memory budget (measured {measured} bytes)"), + Self::MemoryLimitExceeded { limit, measured } => write!(f, "worker exceeded {limit} byte process-group memory budget (measured {measured} bytes)"), Self::Monitoring(error) => write!(f, "worker monitoring: {error}"), } } @@ -44,12 +47,13 @@ impl std::fmt::Display for ProcessFailure { impl std::error::Error for ProcessFailure {} -/// Why [`MonitoredChild::wait`] stopped a child, with the group's peak sampled RSS up to the +/// Why [`MonitoredChild::wait`] stopped a child, with the group's peak sampled memory up to the /// stop: a stopped attempt is measured like a finished one. #[derive(Debug)] pub struct ProcessStop { pub failure: ProcessFailure, - /// Maximum sampled process-group RSS before the stop when memory monitoring was enabled. + /// Maximum sampled process-group memory (`worker_charged_bytes`) before the stop when memory + /// monitoring was enabled. pub peak_resident_bytes: Option, } @@ -82,7 +86,8 @@ impl ProcessControl<'_> { #[derive(Debug)] pub struct ProcessExit { pub status: ExitStatus, - /// The larger of the process group's peak sampled RSS (with memory monitoring) and the + /// The larger of the process group's peak sampled memory (with memory monitoring; + /// `worker_charged_bytes`: resident, and compressed or swapped out) and the /// kernel's peak resident size of the leader at its reap (`ru_maxrss` from `wait4`) where that /// figure is the leader's own (`own_kernel_peak`). The sampler sums every member but samples /// only while the leader runs, every 1 ms until a sample finds memory of the group's own and @@ -167,14 +172,14 @@ impl MonitoredChild { Err(error) => return Err(ProcessFailure::Monitoring(error.to_string())), } if let Some(limit) = control.memory_limit_bytes { - if let Some(resident) = - worker_resident_bytes(self.id()).map_err(ProcessFailure::Monitoring)? + if let Some(charged) = + worker_charged_bytes(self.id()).map_err(ProcessFailure::Monitoring)? { - peak = Some(peak.unwrap_or(0).max(resident)); - if resident > limit { + peak = Some(peak.unwrap_or(0).max(charged)); + if charged > limit { return Err(ProcessFailure::MemoryLimitExceeded { limit, - measured: resident, + measured: charged, }); } } @@ -222,34 +227,34 @@ impl Drop for MonitoredChild { #[cfg(any(target_os = "macos", target_os = "linux"))] const MAX_WORKER_GROUP_MEMBERS: usize = 1024; -/// The group's resident bytes: the sum of what each member holds on its own, or `None` when no -/// member was left to sample. +/// The group's memory: the sum of what each member is charged on its own +/// (`process_charged_bytes`), or `None` when no member was left to sample. #[cfg(any(target_os = "macos", target_os = "linux"))] -fn worker_resident_bytes(group: u32) -> Result, String> { - let mut resident = None::; +fn worker_charged_bytes(group: u32) -> Result, String> { + let mut charged = None::; for pid in worker_group_members(group)? { - if let Some(bytes) = member_resident_bytes(group, pid)? { - resident = Some( - resident + if let Some(bytes) = member_charged_bytes(group, pid)? { + charged = Some( + charged .unwrap_or(0) .checked_add(bytes) - .ok_or("worker process-group resident sum overflow")?, + .ok_or("worker process-group memory sum overflow")?, ); } } - Ok(resident) + Ok(charged) } -/// What member `pid` of `group` holds resident, or `None` once it is gone or has left the group. -/// macOS's `posix_spawn` creates a process and its image in one call, so a spawned member never -/// runs in its parent's memory, the Linux case. +/// What member `pid` of `group` is charged (`process_charged_bytes`), or `None` once it is gone or +/// has left the group. macOS's `posix_spawn` creates a process and its image in one call, so a +/// spawned member never runs in its parent's memory, the Linux case. #[cfg(target_os = "macos")] -fn member_resident_bytes(group: u32, pid: u32) -> Result, String> { +fn member_charged_bytes(group: u32, pid: u32) -> Result, String> { // Recheck membership because a process can exit between enumeration and sampling. if process_group(pid)? != Some(group) { return Ok(None); } - process_resident_bytes(pid) + process_charged_bytes(pid) } #[cfg(any(target_os = "macos", target_os = "linux"))] @@ -318,8 +323,9 @@ fn worker_group_members(group: u32) -> Result, String> { Ok(members) } +/// Process `pid`'s usage as the kernel states it (`proc_pid_rusage`), or `None` once it is gone. #[cfg(target_os = "macos")] -fn process_resident_bytes(pid: u32) -> Result, String> { +fn process_usage(pid: u32) -> Result, String> { let mut usage = std::mem::MaybeUninit::::zeroed(); let result = unsafe { libc::proc_pid_rusage( @@ -329,32 +335,66 @@ fn process_resident_bytes(pid: u32) -> Result, String> { ) }; if result == 0 { - Ok(Some(unsafe { usage.assume_init() }.ri_resident_size)) + Ok(Some(unsafe { usage.assume_init() })) } else if std::io::Error::last_os_error().raw_os_error() == Some(libc::ESRCH) { Ok(None) } else { Err(format!( - "read translation worker resident memory: {}", + "read translation worker memory: {}", std::io::Error::last_os_error() )) } } -#[cfg(target_os = "linux")] +/// Process `pid`'s resident bytes, or `None` once it is gone. +#[cfg(target_os = "macos")] fn process_resident_bytes(pid: u32) -> Result, String> { - let path = format!("/proc/{pid}/status"); - let status = match fs::read_to_string(&path) { - Ok(status) => status, - Err(error) if process_gone(&error) => return Ok(None), - Err(error) => return Err(format!("read {path}: {error}")), - }; - Ok(status_charged_bytes(&status)) + Ok(process_usage(pid)?.map(|usage| usage.ri_resident_size)) } -/// What the watchdog charges a member whose `/proc//status` reads `status`. +/// What the watchdog charges process `pid`, or `None` once it is gone: the larger of its resident +/// size and its physical footprint. The footprint is the kernel's ledger of the dirty memory the +/// process owns, compressed or swapped out included, so it keeps counting the pages the +/// compressor takes out of the resident set under memory pressure; it leaves out clean +/// file-backed pages, which the resident size counts, so the larger of the two never charges less +/// than the resident size alone. +#[cfg(target_os = "macos")] +fn process_charged_bytes(pid: u32) -> Result, String> { + Ok(process_usage(pid)?.map(|usage| usage.ri_resident_size.max(usage.ri_phys_footprint))) +} + +/// Process `pid`'s `/proc//status`, or `None` once it is gone. +#[cfg(target_os = "linux")] +fn process_status(pid: u32) -> Result, String> { + let path = format!("/proc/{pid}/status"); + match fs::read_to_string(&path) { + Ok(status) => Ok(Some(status)), + Err(error) if process_gone(&error) => Ok(None), + Err(error) => Err(format!("read {path}: {error}")), + } +} + +/// Process `pid`'s resident bytes (`VmRSS`), or `None` once it is gone. +#[cfg(target_os = "linux")] +fn process_resident_bytes(pid: u32) -> Result, String> { + Ok(process_status(pid)?.and_then(|status| status_bytes(&status, "VmRSS:"))) +} + +/// What the watchdog charges process `pid` (`status_charged_bytes`), or `None` once it is gone. +#[cfg(target_os = "linux")] +fn process_charged_bytes(pid: u32) -> Result, String> { + Ok(process_status(pid)?.and_then(|status| status_charged_bytes(&status))) +} + +/// What the watchdog charges a process whose `/proc//status` reads `status`: its resident +/// memory (`VmRSS`) and its anonymous memory swapped out (`VmSwap`), to a disk or to compressed +/// RAM such as zram, which under memory pressure leaves the resident set; `None` for a status +/// with no `VmRSS` (a zombie's), as before. The kernel prints `VmSwap` beside `VmRSS` +/// (`task_mem`), so one read states both. #[cfg(target_os = "linux")] fn status_charged_bytes(status: &str) -> Option { - status_bytes(status, "VmRSS:") + let resident = status_bytes(status, "VmRSS:")?; + Some(resident.saturating_add(status_bytes(status, "VmSwap:").unwrap_or(0))) } /// Whether reading a group member's `/proc//status` failed because the member is gone: its @@ -367,12 +407,13 @@ fn process_gone(error: &std::io::Error) -> bool { } #[cfg(not(any(target_os = "macos", target_os = "linux")))] -fn worker_resident_bytes(_pid: u32) -> Result, String> { +fn worker_charged_bytes(_pid: u32) -> Result, String> { Ok(None) } -/// This process's resident bytes now, as its workers' are read; `None` where RSS monitoring is -/// unsupported or the read failed. A supervisor reports its own memory beside its workers'. +/// This process's resident bytes now (`VmRSS`, or `ri_resident_size` on macOS), without the +/// compressed or swapped memory a worker is charged beside them (`process_charged_bytes`); `None` +/// where it cannot be read. A supervisor reports its own memory beside its workers'. pub fn own_resident_bytes() -> Option { #[cfg(any(target_os = "macos", target_os = "linux"))] { @@ -390,7 +431,7 @@ pub fn own_resident_bytes() -> Option { /// may be the parent's own (`own_kernel_peak`), but the worker knows its own high water. On Linux /// it is the image's own `VmHWM`, not `getrusage`'s `ru_maxrss`, which holds the spawner's high /// water folded in at the exec; on macOS it is `ru_maxrss`, which is the process's own -/// (`member_resident_bytes`). +/// (`member_charged_bytes`). pub fn own_peak_resident_bytes() -> Option { #[cfg(target_os = "linux")] { @@ -485,7 +526,7 @@ fn own_memory(peak: Option) -> Option { /// alone. (The kernel records a high water before an unmap lowers the resident size, though not /// before reclaim does, so a supervisor whose pages were reclaimed between the exec and the reap /// is the one case this can misread.) macOS's `posix_spawn` starts the child in its own memory -/// (`member_resident_bytes`), so there the figure is the worker's. +/// (`member_charged_bytes`), so there the figure is the worker's. fn own_kernel_peak(kernel_peak_bytes: u64) -> Option { #[cfg(target_os = "linux")] { @@ -719,8 +760,8 @@ mod tests { if members.len() != 2 || !members.contains(&worker.id()) { return Err(format!("unexpected fixture process group: {members:?}")); } - let leader = process_resident_bytes(worker.id())?.ok_or("leader disappeared")?; - let group = worker_resident_bytes(worker.id())?.ok_or("group disappeared")?; + let leader = process_charged_bytes(worker.id())?.ok_or("leader disappeared")?; + let group = worker_charged_bytes(worker.id())?.ok_or("group disappeared")?; Ok((leader, group)) })(); terminate_child(&mut worker); diff --git a/crates/metal2vulkan-validation/src/worker/process/linux.rs b/crates/metal2vulkan-validation/src/worker/process/linux.rs index d6944d923..37cac88fb 100644 --- a/crates/metal2vulkan-validation/src/worker/process/linux.rs +++ b/crates/metal2vulkan-validation/src/worker/process/linux.rs @@ -1,12 +1,13 @@ -//! What a Linux process-group member holds resident on its own. +//! What a Linux process-group member is charged of its own memory. //! -//! The watchdog sums the resident memory of every member of a worker's process group. On Linux a -//! process started through glibc's `posix_spawn` (which `std::process::Command` uses) or `vfork` -//! runs in its parent's memory from its creation until its `exec` installs its own image, and the -//! kernel lets the parent go on before that switch. `/proc` then reports the parent's resident -//! memory as the child's: a worker sampled just after its spawn would be charged the supervisor's -//! memory, and a tool the worker starts would charge the worker's memory a second time. So a -//! member is charged only memory that is its own: +//! The watchdog sums the memory of every member of a worker's process group: what it holds +//! resident and what it has swapped out (`process_charged_bytes`). On Linux a process started +//! through glibc's `posix_spawn` (which `std::process::Command` uses) or `vfork` runs in its +//! parent's memory from its creation until its `exec` installs its own image, and the kernel lets +//! the parent go on before that switch. `/proc` then reports the parent's memory as the child's: a +//! worker sampled just after its spawn would be charged the supervisor's memory, and a tool the +//! worker starts would charge the worker's memory a second time. So a member is charged only +//! memory that is its own: //! //! - One read of `/proc//stat` states its process group, its parent, and its flags together: //! the kernel takes the process's exec lock for that read, the lock an exec holds across the @@ -22,8 +23,8 @@ //! is a member. Where the kernel refuses the comparison (a container whose seccomp filter refuses //! `kcmp` without `CAP_SYS_PTRACE`, a kernel built without it), the member is counted as before, //! so the measure can briefly overcount and never undercounts. -//! - Every other member is charged its own `VmRSS`, read after its flags, so it is the resident -//! size of its own image. +//! - Every other member is charged its own `VmRSS` and `VmSwap` (`process_charged_bytes`), read +//! after its flags, so they are its own image's. /// `PF_FORKNOEXEC` (`include/linux/sched.h`): the process has not completed an `exec` since its /// creation. @@ -41,9 +42,9 @@ struct Stat { before_exec: bool, } -/// The resident bytes `pid`, a member of `group` (whose leader is the supervisor's spawn), holds -/// on its own; `None` once it has left the group or is gone. -pub(super) fn member_resident_bytes(group: u32, pid: u32) -> Result, String> { +/// The bytes `pid`, a member of `group` (whose leader is the supervisor's spawn), is charged of +/// its own memory; `None` once it has left the group or is gone. +pub(super) fn member_charged_bytes(group: u32, pid: u32) -> Result, String> { let Some(stat) = stat(pid)? else { return Ok(None); }; @@ -53,7 +54,7 @@ pub(super) fn member_resident_bytes(group: u32, pid: u32) -> Result, if stat.before_exec && (pid == group || shares_address_space(pid, stat.parent)) { return Ok(Some(0)); } - super::process_resident_bytes(pid) + super::process_charged_bytes(pid) } /// One read of `/proc//stat`, or `None` when the process is gone. The read waits while the @@ -122,7 +123,7 @@ fn shares_address_space(pid: u32, other: u32) -> bool { #[cfg(test)] mod tests { use super::super::{ - process_resident_bytes, worker_resident_bytes, MonitoredChild, ProcessControl, + process_charged_bytes, worker_charged_bytes, MonitoredChild, ProcessControl, ProcessFailure, ProcessStop, }; use super::*; @@ -295,14 +296,14 @@ mod tests { let held = hold(CEILING + 100 * MIB); let leader = SharedMemoryChild::start(Some(0)); let group = leader.pid as u32; - let reported = process_resident_bytes(group).unwrap().unwrap(); + let reported = process_charged_bytes(group).unwrap().unwrap(); assert!( reported > CEILING, "the shared leader reads as the supervisor's {} MiB, not {} MiB", held.len() as u64 / MIB, reported / MIB ); - assert_eq!(worker_resident_bytes(group), Ok(Some(0))); + assert_eq!(worker_charged_bytes(group), Ok(Some(0))); drop(leader); drop(held); } diff --git a/crates/metal2vulkan-validation/tests/integration/compile_worker.rs b/crates/metal2vulkan-validation/tests/integration/compile_worker.rs index e429d63e7..6d7dc2011 100644 --- a/crates/metal2vulkan-validation/tests/integration/compile_worker.rs +++ b/crates/metal2vulkan-validation/tests/integration/compile_worker.rs @@ -85,7 +85,7 @@ fn every_device_tool_serves_the_compile_worker_with_the_public_apis_pipeline() { assert!(compiled.measured.peak_resident_bytes.is_some(), "{program}"); } // The worker's report carries its counting allocator's process peak beside the sampled - // RSS: at least the compile's own peak, which it contains. + // memory: at least the compile's own peak, which it contains. let process_peak = compiled.measured.allocator_peak_bytes; assert!( process_peak.is_some_and(|peak| peak >= compiled.allocator_peak.unwrap()), diff --git a/docs/HOWTO.md b/docs/HOWTO.md index a30b6242e..6aee0ad07 100644 --- a/docs/HOWTO.md +++ b/docs/HOWTO.md @@ -121,9 +121,10 @@ down, or a hard memory ceiling must hold, compile in a child process: keys). 2. In the child, install a counting global allocator that refuses allocations above a budget, build the `Device`, and compile with the same `Budget`. -3. In the parent, poll the deadline, cancellation and the process group's resident memory. On a - breach, kill the whole group and remove its scratch files. A result that arrives late is a - timeout. +3. In the parent, poll the deadline, cancellation and the process group's memory: each member's + resident memory and what the system compressed or swapped out of it, which leaves the resident + set under memory pressure. On a breach, kill the whole group and remove its scratch files. A + result that arrives late is a timeout. 4. Load the result with `PipelineArtifact::from_bytes` against the parent's own `Device`, and check that its key is the one the parent computed (`Device::compute_pipeline_key`, `render_pipeline_key`).