Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: iostats: Rewrite intro, remove outdated formats

The introduction discussed stat file formats for very old kernel versions,
which obscured key information that readers may find useful. Additionally,
the example file contents and the reference to "15 fields" did not account
for the flush fields added in b6866318657 ("block: add iostat counters for
flush requests") [1].

Rewrite the introduction to focus only on the current kernel's disk I/O stat
file formats. Also, clean up wording for conciseness.

Link: https://lore.kernel.org/lkml/157433282607.7928.5202409984272248322.stgit@buzz/T/ [1]

Signed-off-by: David Reaver <me@davidreaver.com>
Link: https://lore.kernel.org/r/20250215180114.157948-1-me@davidreaver.com
Signed-off-by: Jonathan Corbet <corbet@lwn.net>

authored by

David Reaver and committed by
Jonathan Corbet
85df12c5 15f73829

+26 -49
+26 -49
Documentation/admin-guide/iostats.rst
··· 2 2 I/O statistics fields 3 3 ===================== 4 4 5 - Since 2.4.20 (and some versions before, with patches), and 2.5.45, 6 - more extensive disk statistics have been introduced to help measure disk 7 - activity. Tools such as ``sar`` and ``iostat`` typically interpret these and do 8 - the work for you, but in case you are interested in creating your own 9 - tools, the fields are explained here. 5 + The kernel exposes disk statistics via ``/proc/diskstats`` and 6 + ``/sys/block/<device>/stat``. These stats are usually accessed via tools 7 + such as ``sar`` and ``iostat``. 10 8 11 - In 2.4 now, the information is found as additional fields in 12 - ``/proc/partitions``. In 2.6 and upper, the same information is found in two 13 - places: one is in the file ``/proc/diskstats``, and the other is within 14 - the sysfs file system, which must be mounted in order to obtain 15 - the information. Throughout this document we'll assume that sysfs 16 - is mounted on ``/sys``, although of course it may be mounted anywhere. 17 - Both ``/proc/diskstats`` and sysfs use the same source for the information 18 - and so should not differ. 9 + Here are examples using a disk with two partitions:: 19 10 20 - Here are examples of these different formats:: 11 + /proc/diskstats: 12 + 259 0 nvme0n1 255999 814 12369153 47919 996852 81 36123024 425995 0 301795 580470 0 0 0 0 60602 106555 13 + 259 1 nvme0n1p1 492 813 17572 96 848 81 108288 210 0 76 307 0 0 0 0 0 0 14 + 259 2 nvme0n1p2 255401 1 12343477 47799 996004 0 36014736 425784 0 344336 473584 0 0 0 0 0 0 21 15 22 - 2.4: 23 - 3 0 39082680 hda 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 24 - 3 1 9221278 hda1 35486 0 35496 38030 0 0 0 0 0 38030 38030 16 + /sys/block/nvme0n1/stat: 17 + 255999 814 12369153 47919 996858 81 36123056 426009 0 301809 580491 0 0 0 0 60605 106562 25 18 26 - 2.6+ sysfs: 27 - 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 28 - 35486 38030 38030 38030 19 + /sys/block/nvme0n1/nvme0n1p1/stat: 20 + 492 813 17572 96 848 81 108288 210 0 76 307 0 0 0 0 0 0 29 21 30 - 2.6+ diskstats: 31 - 3 0 hda 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 32 - 3 1 hda1 35486 38030 38030 38030 22 + Both files contain the same 17 statistics. ``/sys/block/<device>/stat`` 23 + contains the fields for ``<device>``. In ``/proc/diskstats`` the fields 24 + are prefixed with the major and minor device numbers and the device 25 + name. In the example above, the first stat value for ``nvme0n1`` is 26 + 255999 in both files. 33 27 34 - 4.18+ diskstats: 35 - 3 0 hda 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 0 0 0 0 28 + The sysfs ``stat`` file is efficient for monitoring a small, known set 29 + of disks. If you're tracking a large number of devices, 30 + ``/proc/diskstats`` is often the better choice since it avoids the 31 + overhead of opening and closing multiple files for each snapshot. 36 32 37 - On 2.4 you might execute ``grep 'hda ' /proc/partitions``. On 2.6+, you have 38 - a choice of ``cat /sys/block/hda/stat`` or ``grep 'hda ' /proc/diskstats``. 39 - 40 - The advantage of one over the other is that the sysfs choice works well 41 - if you are watching a known, small set of disks. ``/proc/diskstats`` may 42 - be a better choice if you are watching a large number of disks because 43 - you'll avoid the overhead of 50, 100, or 500 or more opens/closes with 44 - each snapshot of your disk statistics. 45 - 46 - In 2.4, the statistics fields are those after the device name. In 47 - the above example, the first field of statistics would be 446216. 48 - By contrast, in 2.6+ if you look at ``/sys/block/hda/stat``, you'll 49 - find just the 15 fields, beginning with 446216. If you look at 50 - ``/proc/diskstats``, the 15 fields will be preceded by the major and 51 - minor device numbers, and device name. Each of these formats provides 52 - 15 fields of statistics, each meaning exactly the same things. 53 - All fields except field 9 are cumulative since boot. Field 9 should 54 - go to zero as I/Os complete; all others only increase (unless they 55 - overflow and wrap). Wrapping might eventually occur on a very busy 56 - or long-lived system; so applications should be prepared to deal with 57 - it. Regarding wrapping, the types of the fields are either unsigned 58 - int (32 bit) or unsigned long (32-bit or 64-bit, depending on your 59 - machine) as noted per-field below. Unless your observations are very 60 - spread in time, these fields should not wrap twice before you notice it. 33 + All fields are cumulative, monotonic counters, except for field 9, which 34 + resets to zero as I/Os complete. The remaining fields reset at boot, on 35 + device reattachment or reinitialization, or when the underlying counter 36 + overflows. Applications reading these counters should detect and handle 37 + resets when comparing stat snapshots. 61 38 62 39 Each set of stats only applies to the indicated device; if you want 63 40 system-wide stats you'll have to find all the devices and sum them all up.