Files
rustfs/docs/operations/multipart-memory.md
T
Chris An 2381096448 fix(scanner): preserve restart progress and background admission (#9341)
* fix(scanner): retain unpublished bucket progress across leader changes

* test(scanner): verify remote completion reuse and publication floors

* fix(scanner): persist read-only checkpoint continuity

* test(scanner): avoid cloning the final activity fixture

* fix(scanner): resolve receipt owner before store startup

* fix(scanner): gate read-only handoff behind reader-first rollout

* test(scanner): accept consumed markers after heal startup

* test(scanner): run handoff rollback in the pinned release lane

* fix(scanner): preserve background admission during cache saves

* fix(scanner): admit remote cache publications as background I/O

* fix: handle disabled cgroup controllers in resource sampling

* fix(scanner): wait for namespace RPC preflight admission

* fix(scanner): align metric loops with current clippy

* fix: resolve Rust 1.100 workspace lint diagnostics

* fix(heal): simplify Linux test opt-in check

* chore(scanner): expose admission and allocator diagnostics

* fix(scanner): retry transient resource samples within one bracket

* fix(protos): retain cancelled RPC streams during response grace

* feat(diagnostics): track live Rust allocation bytes

* docs(diagnostics): explain unsafe allocator test scope

* fix(ecstore): reduce multipart recovery stack usage

* chore: refresh PR verification

* fix(protos): retain reset streams for the full cancelled burst

The branch's channel reset tests cancel 80 batches of 64 streams; main's 4096 cap spends the protocol-error budget on that burst, so keep the 8192 capacity under main's constant.

* fix(scanner): complete budget-stopped cycles with carried buckets pending

Align with main's partial-carry semantics: a work budget that stops a bucket whose certified value is carried completes the cycle with that bucket pending and the snapshot unconverged, instead of forcing the cycle incomplete.
2026-11-21 09:12:23 +08:00

7.4 KiB

Multipart upload memory diagnosis

Use this when: sustained multipart uploads increase process memory or end in an OOM kill, and you need to distinguish request buffers, background work, and allocator retention.

Record the actual workload

Record the image digest, source revision, architecture, allocator version, I/O backend, data filesystem and mounts, container memory/swap limits, and the client version. Docker directories sharing one device are not equivalent to separate physical disks. Keep any local-test disk-check bypass out of production configuration.

Count active UploadPart requests independently from file/upload concurrency. Record part size, parts per upload, retries, completed uploads, aborted uploads, TLS, throughput, and request latency. A distributed client's concurrency applies per client. Warp multipart-put also performs create and complete operations; its PUTPART summary alone does not count successful completions.

Run a short baseline followed by a sustained isolated run long enough to cross the reported growth window. Keep a defined idle observation window after uploads, completion, abort and cleanup. Bound disk use as well as memory: a successful long upload test can fill the test filesystem.

Separate memory measurements

Collect these measurements on the same time axis:

  • Process RssAnon/Pss_Anon, file RSS, swap and total RSS from Linux procfs.
  • Cgroup memory.current, memory.stat anon/file and memory.events. Docker stats is not a substitute for this split.
  • Allocator reserved and committed bytes, and requested bytes only when their live statistics are available.
  • Active requests, EC producer/queue/writer bytes, GET buffered bytes, tasks, threads, file descriptors, and scanner/heal/replication activity.

The EC queue budget controls queued encoded blocks, not complete per-request or process memory. Admission permits constrain concurrent operations; they do not establish an RSS limit or release allocations retained by completed work.

Allocator statistics

Mimalloc JSON count statistics have direct current, peak and total fields. Scalar counters contain only cumulative totals. In particular, a scalar malloc_requested must never be interpreted as current live bytes or a peak. The malloc_normal/huge statistics are not a reliable replacement for requested live bytes in release builds.

Use rustfs_memory_allocator_malloc_requested_bytes only when rustfs_memory_allocator_malloc_requested_bytes_available equals 1. A value of 0 for availability means the live statistic could not be established; it does not mean the heap is empty. An all-zero requested count may mean accounting was compiled out. A supported count whose current becomes zero while peak/total remain nonzero is a valid drained heap observation.

A previously published gauge can remain visible after a statistic becomes unavailable. Filter it by the availability metric. The malloc_requested_total_bytes metric is cumulative allocation activity and can grow indefinitely in a healthy process. Do not use its slope as evidence of retained memory.

The rustfs_memory_allocator_allocated_bytes gauge reports the allocator's allocated.current block accounting when rustfs_memory_allocator_allocated_bytes_available is one. It includes size-class rounding and can lag page or thread statistics merges. Availability means the field was present and valid, not that accounting was enabled. This observation is distinct from live requested bytes, committed bytes and RSS; zero or a change alone does not prove a drained heap or a leak.

When live requested bytes are unavailable, capture a supported heap profile or allocation/free trace. Preserve attribution to allocation stacks and lifetime; committed bytes and RSS alone cannot establish a leak. Other raw allocator statistics, including page accounting, depend on the allocator build and are not interchangeable with live application bytes.

Diagnostic allocator and runtime metrics

Build with --features diagnostic-allocator-live to count live requested bytes for Rust allocations routed through the binary's MiMalloc GlobalAlloc wrapper. Read rustfs_memory_allocator_rust_global_requested_live_bytes together with rustfs_memory_allocator_rust_global_requested_live_bytes_available. Availability is 1 for this feature on non-Windows builds when the hotpath and hotpath-alloc combination is inactive. Direct native allocations are outside this counter. The wrapper records successful allocations, zeroed allocations, reallocations, and frees using allocation-free atomic updates. Per-allocation accounting adds overhead, so collect diagnostic and throughput measurements in separate runs.

The memory sampler also exports rustfs_runtime_worker_threads. With RUSTFLAGS="--cfg tokio_unstable", it exports serving-runtime blocking-thread total, idle, and active gauges under rustfs_runtime_blocking_threads_*, with rustfs_runtime_blocking_pool_metrics_available = 1. An ordinary build reports availability 0. These metrics describe the serving runtime; isolated disk fsync and cleanup runtimes have their own execution ownership. Enable the allocator feature separately when both views are needed. Tokio's tokio_unstable configuration uses the stable compiler and opts into Tokio's unstable telemetry API.

Linux transparent huge pages

Linux RustFS binaries disable transparent huge pages for mimalloc by default. This reduces resident memory when reclaimable allocations occupy only part of a huge page. Check THP_enabled in /proc/<pid>/status and AnonHugePages in /proc/<pid>/smaps_rollup to verify the running process. Both values should be zero with the default. The Linux binary also defaults to immediately purging free arena ranges. Set MIMALLOC_PURGE_DELAY before startup to override the delay in milliseconds.

Idle reclaim

The reclaim loop waits for request, delete-tail, scanner, heal, EC and GET-buffer activity to become idle. Continuous traffic can skip reclaim. Check the activity gauges, skipped reasons and idle streak rather than assuming that waiting a fixed period guarantees collection.

A successful MiMalloc collect call collects the executing thread's heap. The reclaim ok counter does not prove that all Tokio worker or blocking-thread heaps have been collected. It cannot by itself rule out allocator retention. Avoid adding forced collection to each request without a measured cause and performance evidence.

Isolate the retaining path

Compare the same upload ID and part number overwritten repeatedly with new upload IDs and parts. Test UploadPart without completion, complete cycles, abort, disconnect, timeout and slow storage separately. Compare TLS and plaintext only at matched workload and throughput. Correlate background activity rather than disabling durability or checksums.

A live-heap leak requires evidence that allocations stay reachable or unfreed after their owner should finish. Stable live allocations with growing committed/RSS point toward allocator retention or fragmentation. Growth tracking metadata cardinality or background queues needs a bounded-state investigation. Accept stable caches and explain their bounds; do not require every byte of RSS to disappear after idle.

Verify any fix with the same workload, failure paths and idle window. Preserve S3 part/checksum semantics, cancellation cleanup, commit fencing, write quorum and durability. Raising memory limits or reducing concurrency can be a diagnostic control, but does not prove a leak is fixed.