Research notes / Storage observability
Where Linux charges I/O: cache reads, mapped writes and cancelled writeback
/ Updated / Measured API behavior and source synthesis
A process can read 4 MiB with no increase in read_bytes, modify 4 MiB with no increase in wchar, or cancel writeback charged to another process. We observed all three. Before turning Linux counters into a dashboard, decide which layer and which owner the metric describes.
On this page13 sections
The same payload appears in different counters
Each scenario used a fresh 4 MiB file. The values below are per-process counter increases, in MiB, not rates. All 5 repetitions produced the same displayed values. Raw snapshots retain byte precision and syscall counts.
Observed on Linux 6.8.0-146-generic, x86_64; each row names the process whose counters were read. The last two rows belong to a truncator, not its writer.
| Action / measured owner | rcharMiB | wcharMiB | read_bytesMiB | write_bytesMiB | cancelled_write_bytesMiB |
|---|---|---|---|---|---|
| Cached file read | 4 | 0 | 0 | 0 | 0 |
| Shared mmap modification | 0 | 0 | 0 | 4 | 0 |
| Buffered writer, before truncation | 0 | 4 | 0 | 4 | 0 |
| Other process truncates dirty file | 0 | 0 | 0 | 0 | 4 |
| Other process truncates after fsync | 0 | 0 | 0 | 0 | 0 |
The cached reader returned and checked every byte. Its rchar increased by 4,194,304, while read_bytes stayed unchanged. It made 64 successful 64 KiB reads plus one EOF read, explaining the recorded 65 read syscalls. Preparation had written and synchronized the file without evicting its cached contents.
The mapping case changed every byte of a shared mapping and verified the resulting file contents. It recorded 4 MiB in write_bytes, but zero in both wchar and syscw. Counting write-family calls alone would miss this modification path. See the separate mapping, visibility and synchronization experiments for the persistence boundary.
Why writes are charged before writeback finishes
Linux distinguishes bytes returned through read/write-family interfaces from storage-related accounting. Kernel documentation places write_bytes accounting at page-dirtying time: the process that changes cached data can be identified then, even if a different execution context writes it back later. A larger counter therefore does not certify that those bytes have completed physical I/O. [1, section 3.3]
This design rationale is easy to miss in current monitoring summaries. The 2007 paper Where is your application stuck? discusses Andrew Morton's per-task I/O accounting as related work. Section 3.5 explains the attribution problem with delayed writes and illustrates why syscall counters miss memory-mapped modifications. Its original demonstration used a different, much larger mapping. Our small experiment checks the mechanism on a later kernel; it is not a numerical replication of that example. [3, pp. 75-77]
The process cancelling a write need not have written anything
In the dirty-file case, worker A wrote 4 MiB and stopped. Worker B then opened that same file and shortened it to zero. A remained alive and stopped throughout B's operation, so the observation does not rely on a process disappearing or its counters being reset.
A retained its 4 MiB charge. B gained 4 MiB in cancelled_write_bytes and zero in write_bytes. Subtracting B's two increases yields -4 MiB. Nothing flowed backwards through a disk: the subtraction combines a write charge with cancellation of somebody else's dirty data.
The control changed one step: A completed fsync() before B truncated. B's cancellation increase was then zero in every repetition. That comparison supports the dirty-writeback interpretation, while neither counter sequence measures physical media traffic.
The kernel documentation explicitly allows this cross-process attribution. The manual describes cancelled_write_bytes as writeback avoided for data already charged, and warns that a process's derived net can be negative. Background writeback can reduce or eliminate the cancellation seen in a rerun; zero cancellation is a valid result. [1] [2]
A parent's counter can rise without a new write
We extended the experiment to follow one child through four states: stopped before writing, stopped after writing and synchronizing, exited but not reaped, and reaped by its parent. The parent performed no file writes. Its /proc/PID/io gained the child's contribution only at the last step.
Changes in wchar, in MiB. Parent columns use the stopped baseline; the own-task column measures the reaping step. Each payload was tested 5 times on Linux 6.8.0-146-generic; every repetition gave the displayed values. The zero-payload child is a no-write control.
| Child payload MiB | Parent after write MiB | Parent after WNOWAIT MiB | Parent after reap MiB | Own task during reap MiB | Incorrect retained sum MiB |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 2 |
| 4 | 0 | 0 | 4 | 0 | 8 |
The distinction is between observing termination and consuming its status. The parent first used waitid(..., WEXITED | WNOWAIT), which left the exited child waitable; the observer confirmed its zombie state. A subsequent waitpid() reaped it. Waiting for an earlier stopped state had not transferred its counters either. [4]
The upstream Linux v6.8 implementation explains the boundary: wait_task_zombie() takes the WNOWAIT path before adding the child's accounting to the parent's shared signal structure. The ordinary reap path adds both the child's task counters and its accumulated group counters. Separately, do_io_accounting() includes the shared totals for the process view, but uses the individual task counters for the thread view. These are version-pinned source observations, not a claim that every vendor kernel has identical code. [5] [6]
We also sampled /proc/PID/task/PID/io for the single-threaded parent. Its own wchar and write_bytes stayed unchanged at reaping. The process view gained 1 or 4 MiB in both counters, matching the child; the no-write control gained neither. Thus the increase describes inherited accounting, not a second write or a new burst of disk traffic.
Monitoring consequence: retaining a child's completed total and adding it to a parent total that now includes that child double-counts the contribution. For the 4 MiB trial, that mistaken sum is 8 MiB. A parent's rate can also jump when it reaps old work, rather than when the child performed the writes. Track process identity and lifecycle, and choose whether a series represents an individual task or an inclusive process total. Merely switching to the leader's task path would omit other threads in a multithreaded process; sampling tasks alone can also miss short-lived work.
The child-inheritance harness is standalone; its separate JSON result preserves all 15 trials, seven counters, raw snapshots and source hash. Run python3 observe_children.py --repetitions 5 --mib 0 1 4 --output children.json. Signals and anonymous shared memory coordinate the workers, so control messages do not inflate their file-I/O counters.
The observer reads the child at its last stop before _exit(); no payload work remains after that stop. Reading the zombie's I/O file failed with permission denied on this host, so the protocol checks zombie state without requiring that read. The inherited totals matched the pre-exit snapshot for every recorded counter. This tests one parent and one child with default SIGCHLD handling, not orphan adoption, subreapers, concurrent threads or a whole process-tree collector. The original four-scenario data remain unchanged.
Build the metric around the question
For application demand: distinguish returned read/write bytes from memory-mapped access. Our reader and mapping rows show why neither rchar nor wchar alone describes all file activity.
For process attribution: retain write and cancellation counters separately. A derived signed difference may be useful if named accurately, but treating it as an always-increasing counter, interpreting a decrease as a reset, or silently clamping it to zero changes its meaning. This is a monitoring implication of the measured negative difference, not a claim about a particular exporter.
For device work: measure the relevant device layer and align the observation interval. The process table does not establish request completion, latency or controller-internal writes. In particular, write_bytes / wchar is not a NAND write-amplification estimate: the mapped-write row has a zero denominator despite modifying a file. Compare write amplification and the existing IOPS and transfer-size accounting explanation.
For process trees: the manual says this interface includes waited-for children. Summing historical child counters with an ancestor after reaping can count the same contribution twice. The child-reaping experiment above measures that transfer separately from the original cache and truncation scenarios. The interface also has permission checks and documented non-atomic-counter caveats on some systems. [2]
Service I/O volume and stalled time answer different questions
This section reviews Linux 6.12 documentation and the IOCost paper; the experiments above did not test cgroup accounting or pressure.
The cgroup v2 I/O controller exposes io.stat by device major:minor number. io.max limits bytes or operations per second, with temporary bursts allowed. Buffered writeback has per-inode ownership rather than exact per-writer attribution; simultaneous writers from different groups can be mischarged. Check filesystem support before treating the counters as a service ledger. [7] [8]
Pressure Stall Information instead measures task stalls. In io.pressure, some means at least one task stalled; full means all non-idle tasks stalled together. Each line's total accumulates stall time in microseconds; full is a subset of some, so do not add their totals. avg10, avg60 and avg300 are percentage trends. Specify system or cgroup scope. These values are neither device utilization nor request-latency percentiles, and neither accounting interface certifies durable data. [9]
Weights need a cost model. IOCost estimates device occupancy from request direction, access pattern and size, then adjusts the issue rate using device feedback. Equal byte or operation counts therefore need not represent equal modeled cost. Its memory-reclaim example is subtler: an over-budget group's swap I/O may proceed on credit because delaying it would block another group's allocation. Charging the owner and choosing whom to delay are separate decisions. These are mechanisms described by Heo and colleagues, not measurements from our host. The paper's main experiments use three SSD classes and Linux 5.6 with IOCost changes from 5.15; they are not a universal ranking of today's schedulers. [10]
Dirty-memory limits are not durable-write deadlines
Dirty-page throttling regulates tasks modifying cached file data. A write can be charged to a process before writeback completes, while its producer is slowed by dirty-memory pressure. This Linux 6.12 source synthesis adds no kernel experiment or recommended settings. [23]
| VM control | Meaning | Not established |
|---|---|---|
dirty_background_bytesdirty_background_ratio | Background writeback threshold | Completion of a particular file |
dirty_bytesdirty_ratio | Dirty-memory inputs to writer regulation | An exact per-file quota |
dirty_expire_centisecs | Age for periodic writeout eligibility, in hundredths of a second | A persistence deadline |
dirty_writeback_centisecs | Periodic flusher wakeup interval, in hundredths of a second | All writeback triggers |
For each byte/ratio pair, setting one makes the other read as zero: they are alternatives, not cumulative allowances. Ratios use eligible available memory rather than installed RAM. Zero for the wakeup interval disables periodic writeback, not every other cause of writeout. [22]
The v6.12 implementation adjusts writers progressively in normal operation and apportions allowances among writeback instances using completion shares and configured bounds. It is not simply unrestricted writing until one threshold followed by a universal stop. [23, __wb_calc_thresh]
The accounting boundary matters: writer throttling counts dirty pages plus pages under writeback. Background triggering excludes pages already under writeback when deciding whether to start more work. A falling dirty count alone therefore cannot certify that the storage operation finished. [23, domain_dirty_avail]
With supported cgroup writeback, the more restrictive of global and group dirty-memory constraints applies. Byte knobs become ratios for groups; they do not grant every group the same byte allowance. Memory-controller limits, system clean memory and per-inode ownership still matter. [8]
Do not confuse this with block-layer WBT, which responds to read latency. Neither mechanism replaces a persistence protocol: check synchronization errors, and synchronize directory entries when required. An elapsed timer or increasing write_bytes is not an fsync() success result. [24] [25]
There is a second reason to separate cache state from persistence. Rebello et al. injected individual transient block-write faults into ext4, XFS and Btrfs on Linux 5.2.11. Their workloads continued after the failure: pages could be marked clean despite failed writes, and retrying fsync() did not necessarily repair the lost update. These historical fault-injection results do not establish the behavior of every later kernel or measure dirty-throttling performance. [26, sections 3.2-3.3] See the separate fsync failure analysis for recovery implications.
Fewer swap-ins can accompany worse service
Transparent Memory Offloading (TMO) uses pressure feedback to choose how much memory to reclaim. In the ASPLOS 2022 paper's Web load tests on Skylake 64GB hosts, throughput was evaluated at a target tail latency. The faster SSD supported more swap-ins and more requests per second than the slower SSD. Ranking these configurations by swap-in count alone would reverse the performance conclusion. These are the authors' results, not a new experiment here. [19, section 4.3, Figure 12]
File cache matters as well as anonymous memory. Evicting a reusable file page can replace a swap-in with a file refault, without removing the application's wait. The paper balances the two and separately regulates SSD writes; its endurance threshold belongs to that fleet, not every drive. [19, sections 3.4 and 4.4-4.5]
zswap caches compressed pages in RAM ahead of backing swap. Pool eviction or store rejection can lead to backing I/O. Linux 6.12 documents a per-cgroup writeback control, but warns of inefficient reclaim when rejected pages are repeatedly reconsidered. A smaller RAM pool does not by itself prove fewer SSD writes. [21]
Evaluation rule: compare application throughput and request latency under the same offered load, alongside memory and I/O pressure, resident memory, refaults and device writes. Keep device writes distinct from NAND writes. This is a measurement design derived from the mechanisms above, not a conversion from PSI to an application latency percentile. The memory.reclaim interface requests work; its write return is not a reclaimed-byte measurement.
Keep the observation window with the pressure number
For the same resource, state and counter lifetime, divide the change in total by elapsed microseconds and multiply by 100. Retain some and full separately. A counter decrease or recreated cgroup needs a new baseline, not an invented negative rate. [9]
The three rows below use constructed reported totals: 50,000 microseconds of some growth and 20,000 of full growth in the first half-second, then no further growth. They are arithmetic examples, not observed kernel samples or a simulation of scheduling.
| Window | Elapsed (us) | Some delta (us) | Some (%) | Full delta (us) | Full (%) |
|---|---|---|---|---|---|
| First 0.5 s | 500000 | 50000 | 10.00 | 20000 | 4.00 |
| Next 4.5 s | 4500000 | 0 | 0.00 | 0 | 0.00 |
| Whole 5 s | 5000000 | 50000 | 1.00 | 20000 | 0.40 |
Averaging the first two some percentages without weighting gives 5%, while the full interval is 1%: 50,000 / 5,000,000 times 100. Adding some and full would count part of the pressure twice. Neither operation estimates request latency.
Implementation detail: Linux v6.12 weights per-CPU samples by non-idle time. The totals are normalized pressure, not a sum of individual task waits or an exact global all-tasks-stopped timeline. Its avg10 uses exponential decay, not the rectangular interval calculation in this table. The averaging code also documents sample carryover across boundaries; a very short custom interval is not an atomic timing experiment. [20, collect_percpu_times and update_averages]
Pressure notifications have another boundary: a trigger is attached to an open descriptor and removed when it closes. Notifications are rate-limited per tracking window; their count is not the count of stalled requests. [9, Monitoring for pressure thresholds]
Reproduce the table with the standalone arithmetic module and its tests, using node --test psi-window.test.mjs with both files in one directory. Inputs are decimal strings so subtraction remains exact above JavaScript's safe-integer range. The helper rejects mismatched identities and counter decreases; it preserves and flags over-window deltas instead of silently clipping them. It does not collect live PSI or predict its triggers.
Read iowait alongside workload stalls
Linux iowait is CPU accounting, not a disk's busy percentage. The /proc/stat CPU lines report time in USER_HZ units, with an aggregate line and per-CPU lines. The Linux v6.12 account_idle_time() helper charges idle time to iowait when the current runqueue has a positive nr_iowait; otherwise it charges ordinary idle time. This is a version-scoped implementation example. [16] [17]
A blocked task can coexist with another task doing useful CPU work. Low iowait therefore does not rule out a slow I/O-dependent application. Conversely, iowait alone cannot identify the responsible device or request. The kernel documentation also warns that the field can decrease and that per-CPU attribution is difficult on multicore systems. A negative delta is not, by itself, evidence of a reboot. [16]
Choose the accounting scope before comparing a dashboard's percentages or rates. This comparison is source synthesis, separate from the measured file-I/O experiments above.
| Interface | Quantity and scope | Not established |
|---|---|---|
/proc/stat iowait | CPU accounting in USER_HZ units | Which disk is busy or a request's latency |
PSI io.pressure | System or cgroup stall intervals; total in microseconds | A sum of request latencies or device utilization |
/proc/PID/io | Selected process I/O byte and syscall counts | Elapsed stall time or physical-media traffic |
For PSI, some and full distinguish at least one stalled task from all non-idle tasks stalled together. For a slow service, inspect that workload's pressure and appropriately scoped request timings alongside byte counts. This diagnostic combination follows from the interfaces' different meanings; it is not a conversion formula between iowait and PSI. [9] [2]
A stronger bottleneck question is how much earlier the workload could finish without a particular wait. Ousterhout et al. instrumented Spark tasks and replayed scheduling with disk or network blocked time removed. Overlapping work and changing task start times make simply subtracting a host counter insufficient. Their model estimates a best-case improvement, not a guaranteed speedup; removing one wait can expose another. The study used two SQL benchmarks and one production workload, not every storage application. Hesela uses this methodological distinction here, without replicating the experiment or predicting gains for the reader's system. [18]
Count overlapping cache states without adding them
cachestat() samples a file range, not a process's cumulative I/O. The interface arrived in Linux 6.5 and reports cached, dirty, writeback and eviction-related page counts. Results may already be stale when returned. [11]
In a separate five-trial observation on Linux 6.8.0-146-generic, each newly written, locked two-page file reported nr_cache = 2 and nr_dirty = 2. Adding them would invent four pages. The v6.8 implementation increments cached pages first, then independently checks dirty and writeback marks: these are overlapping states, not a partition. [13]
Check the byte boundary. The manual's notation looks inclusive at off + len, but the reviewed v6.8 and v6.16 code computes the last page from off + len - 1 for positive, non-overflowing lengths. A zero length selects the remaining range, not zero bytes. The following native observations distinguish the two interpretations. [11] [12] [13]
Page size: 4096 bytes. Both pages were resident and locked with mlock; all five trials returned these counts after fsync. Offset and length are bytes; the result counts pages, not transferred bytes.
| Offset (B) | Length (B) | Cached pages |
|---|---|---|
| 0 | 1 | 1 |
| 0 | 4096 | 1 |
| 4095 | 1 | 1 |
| 4095 | 2 | 2 |
| 4096 | 4096 | 1 |
| 4096 | 0 | 1 |
The complete results, C probe and Python runner preserve every counter, source hashes, compiler and environment. Run python3 observe.py --output results.json beside the probe in a writable test directory. Each trial creates and immediately unlinks its own file, verifies its contents and locks only two pages; no system-wide cache drop or privileged operation is used. Invalid-descriptor and invalid-flags controls are also checked. The filesystem magic identifies the ext family, not a particular version. This is a boundary test, not a workload benchmark, eviction study or power-loss test.
Disclosure is permission-sensitive. Linux v6.16 checks a writable descriptor, inode ownership or relevant capability, or file write permission, returning EPERM when disclosure is denied. That policy is sourced to v6.16, not inferred from the older test kernel. Conversely, mincore may mask a denied mapping with all-one bytes. Gruss and colleagues' CCS 2019 paper explains why residency disclosure can expose other processes' access patterns, and why restricting direct queries does not eliminate every timing channel. No attack was reproduced here. [12] [14, section 9]
Read attack results with their patch history. Neela and colleagues' Eviction Notice (NDSS 2026) revisits page-cache disclosure, but explicitly records a February 2025 cachestat mitigation, CVE-2025-21691. Its artifact appendix says the patched syscall no longer supports the paper's cross-user scenario. Distribution backports matter: a kernel version label alone is insufficient. Our self-owned-file tests establish range semantics, not cross-user exposure or a security assessment. [15, sections III-D, IV, VII and artifact appendix]
For monitoring, retain the counters separately and state the queried range. Cache residency does not establish which process read a page, a cache-hit ratio, or the application's durable-commit boundary.
Reproduce the four scenarios
The standalone Python harness needs Linux, Python 3 and GNU stat. It creates a private temporary directory, checks returned bytes and contents, and removes its files. It changes no mount settings, cache policy or system tunables, and never opens an existing data file or block device.
python3 observe.py --repetitions 5 --mib 4 --output my-results.jsonA separate parent reads /proc/PID/io while each worker is stopped with SIGSTOP, both before and after the action. The workers do not read their own counters, and no control-pipe payload contaminates their byte totals. A timeout bounds the run. Use --temp-dir to choose an existing disposable test area; the output path must not already exist.
The measured JSON records every before/after snapshot, source SHA-256, timestamp and environment. The published run used Python 3.12.3; stat -f returned ext2/ext3, a magic-number label that does not distinguish ext-family versions. Repetitions check consistency on this host, not a population failure rate.
Cache residency and writeback scheduling remain uncontrolled. The harness therefore validates operations and arithmetic without requiring every host to reproduce the exact cancellation or cache-hit values. It does not test NFS, SMB, direct I/O, cgroup accounting, firmware counters, power loss or performance.
Corpus: process I/O accounting and page cache.
Primary sources
- Linux kernel documentation: /proc/PID/io accounting, section 3.3
- Linux man-pages 6.19: proc_pid_io(5)
- Nagar, Singh, Kashyap, Seetharaman, Sharoff and Banerjee: Where is your application stuck? Linux Symposium 2007, vol. 2, pp. 71-78, section 3.5
- Linux man-pages: wait(2), waitid WNOWAIT semantics
- Linux v6.8 kernel/exit.c: wait_task_zombie and child I/O accumulation
- Linux v6.8 fs/proc/base.c: process and task I/O accounting views
- Linux 6.12: cgroup v2 I/O interface and writeback
- Linux 6.12: cgroup writeback ownership
- Linux 6.12: Pressure Stall Information and cgroup2 interface
- Heo et al.: IOCost: Block IO Control for Containers in Datacenters, ASPLOS 2022, sections 3.2, 3.3, 3.5 and 4; DOI 10.1145/3503222.3507727
- Linux man-pages 6.19: cachestat(2), API, history and snapshot caveat
- Linux v6.16 mm/filemap.c: filemap_cachestat and cachestat syscall
- Linux v6.8 mm/filemap.c: cachestat range calculation and independent counter increments
- Gruss et al. Page Cache Attacks. CCS 2019, section 9. DOI: 10.1145/3319535.3339809
- Neela et al. Eviction Notice: Reviving and Advancing Page Cache Attacks. NDSS 2026; artifact appendix. DOI: 10.14722/ndss.2026.240006
- Linux 6.12: /proc/stat CPU accounting and iowait limitations
- Linux v6.12 kernel/sched/cputime.c: account_idle_time
- Ousterhout et al. Making Sense of Performance in Data Analytics Frameworks. NSDI 2015, pp. 293-307, section 2.3
- Weiner et al. TMO: Transparent Memory Offloading in Datacenters. ASPLOS 2022, pp. 609-621; DOI 10.1145/3503222.3507731.
- Linux v6.12 kernel/sched/psi.c: CPU normalization, calc_avgs, update_averages and trigger windows
- Linux 6.12 zswap: compressed cache, backing swap and writeback controls
- Linux 6.12 VM sysctl documentation: dirty thresholds, age and periodic writeback
- Linux v6.12 mm/page-writeback.c: __wb_calc_thresh and balance_dirty_pages
- Linux man-pages: fsync(2), synchronization, directory entries and errors
- Linux v6.12 block/blk-wbt.c: read-latency feedback for write throttling
- Rebello et al., Can Applications Recover from fsync Failures? USENIX ATC 2020, sections 3.2-3.3