14f4cfa6cSMauro Carvalho Chehab===================== 24f4cfa6cSMauro Carvalho ChehabI/O statistics fields 34f4cfa6cSMauro Carvalho Chehab===================== 44f4cfa6cSMauro Carvalho Chehab 54f4cfa6cSMauro Carvalho ChehabSince 2.4.20 (and some versions before, with patches), and 2.5.45, 64f4cfa6cSMauro Carvalho Chehabmore extensive disk statistics have been introduced to help measure disk 74f4cfa6cSMauro Carvalho Chehabactivity. Tools such as ``sar`` and ``iostat`` typically interpret these and do 84f4cfa6cSMauro Carvalho Chehabthe work for you, but in case you are interested in creating your own 94f4cfa6cSMauro Carvalho Chehabtools, the fields are explained here. 104f4cfa6cSMauro Carvalho Chehab 114f4cfa6cSMauro Carvalho ChehabIn 2.4 now, the information is found as additional fields in 124f4cfa6cSMauro Carvalho Chehab``/proc/partitions``. In 2.6 and upper, the same information is found in two 134f4cfa6cSMauro Carvalho Chehabplaces: one is in the file ``/proc/diskstats``, and the other is within 144f4cfa6cSMauro Carvalho Chehabthe sysfs file system, which must be mounted in order to obtain 154f4cfa6cSMauro Carvalho Chehabthe information. Throughout this document we'll assume that sysfs 164f4cfa6cSMauro Carvalho Chehabis mounted on ``/sys``, although of course it may be mounted anywhere. 174f4cfa6cSMauro Carvalho ChehabBoth ``/proc/diskstats`` and sysfs use the same source for the information 184f4cfa6cSMauro Carvalho Chehaband so should not differ. 194f4cfa6cSMauro Carvalho Chehab 204f4cfa6cSMauro Carvalho ChehabHere are examples of these different formats:: 214f4cfa6cSMauro Carvalho Chehab 224f4cfa6cSMauro Carvalho Chehab 2.4: 234f4cfa6cSMauro Carvalho Chehab 3 0 39082680 hda 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 244f4cfa6cSMauro Carvalho Chehab 3 1 9221278 hda1 35486 0 35496 38030 0 0 0 0 0 38030 38030 254f4cfa6cSMauro Carvalho Chehab 264f4cfa6cSMauro Carvalho Chehab 2.6+ sysfs: 274f4cfa6cSMauro Carvalho Chehab 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 284f4cfa6cSMauro Carvalho Chehab 35486 38030 38030 38030 294f4cfa6cSMauro Carvalho Chehab 304f4cfa6cSMauro Carvalho Chehab 2.6+ diskstats: 314f4cfa6cSMauro Carvalho Chehab 3 0 hda 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 324f4cfa6cSMauro Carvalho Chehab 3 1 hda1 35486 38030 38030 38030 334f4cfa6cSMauro Carvalho Chehab 344f4cfa6cSMauro Carvalho Chehab 4.18+ diskstats: 354f4cfa6cSMauro Carvalho Chehab 3 0 hda 446216 784926 9550688 4382310 424847 312726 5922052 19310380 0 3376340 23705160 0 0 0 0 364f4cfa6cSMauro Carvalho Chehab 374f4cfa6cSMauro Carvalho ChehabOn 2.4 you might execute ``grep 'hda ' /proc/partitions``. On 2.6+, you have 384f4cfa6cSMauro Carvalho Chehaba choice of ``cat /sys/block/hda/stat`` or ``grep 'hda ' /proc/diskstats``. 394f4cfa6cSMauro Carvalho Chehab 404f4cfa6cSMauro Carvalho ChehabThe advantage of one over the other is that the sysfs choice works well 414f4cfa6cSMauro Carvalho Chehabif you are watching a known, small set of disks. ``/proc/diskstats`` may 424f4cfa6cSMauro Carvalho Chehabbe a better choice if you are watching a large number of disks because 434f4cfa6cSMauro Carvalho Chehabyou'll avoid the overhead of 50, 100, or 500 or more opens/closes with 444f4cfa6cSMauro Carvalho Chehabeach snapshot of your disk statistics. 454f4cfa6cSMauro Carvalho Chehab 464f4cfa6cSMauro Carvalho ChehabIn 2.4, the statistics fields are those after the device name. In 474f4cfa6cSMauro Carvalho Chehabthe above example, the first field of statistics would be 446216. 484f4cfa6cSMauro Carvalho ChehabBy contrast, in 2.6+ if you look at ``/sys/block/hda/stat``, you'll 49d94cdae1SAlbert Vaca Cintorafind just the 15 fields, beginning with 446216. If you look at 50d94cdae1SAlbert Vaca Cintora``/proc/diskstats``, the 15 fields will be preceded by the major and 514f4cfa6cSMauro Carvalho Chehabminor device numbers, and device name. Each of these formats provides 52d94cdae1SAlbert Vaca Cintora15 fields of statistics, each meaning exactly the same things. 534f4cfa6cSMauro Carvalho ChehabAll fields except field 9 are cumulative since boot. Field 9 should 544f4cfa6cSMauro Carvalho Chehabgo to zero as I/Os complete; all others only increase (unless they 55d94cdae1SAlbert Vaca Cintoraoverflow and wrap). Wrapping might eventually occur on a very busy 56d94cdae1SAlbert Vaca Cintoraor long-lived system; so applications should be prepared to deal with 57d94cdae1SAlbert Vaca Cintorait. Regarding wrapping, the types of the fields are either unsigned 58d94cdae1SAlbert Vaca Cintoraint (32 bit) or unsigned long (32-bit or 64-bit, depending on your 59d94cdae1SAlbert Vaca Cintoramachine) as noted per-field below. Unless your observations are very 60d94cdae1SAlbert Vaca Cintoraspread in time, these fields should not wrap twice before you notice it. 614f4cfa6cSMauro Carvalho Chehab 624f4cfa6cSMauro Carvalho ChehabEach set of stats only applies to the indicated device; if you want 634f4cfa6cSMauro Carvalho Chehabsystem-wide stats you'll have to find all the devices and sum them all up. 644f4cfa6cSMauro Carvalho Chehab 65d94cdae1SAlbert Vaca CintoraField 1 -- # of reads completed (unsigned long) 664f4cfa6cSMauro Carvalho Chehab This is the total number of reads completed successfully. 674f4cfa6cSMauro Carvalho Chehab 68d94cdae1SAlbert Vaca CintoraField 2 -- # of reads merged, field 6 -- # of writes merged (unsigned long) 694f4cfa6cSMauro Carvalho Chehab Reads and writes which are adjacent to each other may be merged for 704f4cfa6cSMauro Carvalho Chehab efficiency. Thus two 4K reads may become one 8K read before it is 714f4cfa6cSMauro Carvalho Chehab ultimately handed to the disk, and so it will be counted (and queued) 724f4cfa6cSMauro Carvalho Chehab as only one I/O. This field lets you know how often this was done. 734f4cfa6cSMauro Carvalho Chehab 74d94cdae1SAlbert Vaca CintoraField 3 -- # of sectors read (unsigned long) 754f4cfa6cSMauro Carvalho Chehab This is the total number of sectors read successfully. 764f4cfa6cSMauro Carvalho Chehab 77d94cdae1SAlbert Vaca CintoraField 4 -- # of milliseconds spent reading (unsigned int) 784f4cfa6cSMauro Carvalho Chehab This is the total number of milliseconds spent by all reads (as 79*b089f167SNaohiro Aota measured from blk_mq_alloc_request() to __blk_mq_end_request()). 804f4cfa6cSMauro Carvalho Chehab 81d94cdae1SAlbert Vaca CintoraField 5 -- # of writes completed (unsigned long) 824f4cfa6cSMauro Carvalho Chehab This is the total number of writes completed successfully. 834f4cfa6cSMauro Carvalho Chehab 84d94cdae1SAlbert Vaca CintoraField 6 -- # of writes merged (unsigned long) 854f4cfa6cSMauro Carvalho Chehab See the description of field 2. 864f4cfa6cSMauro Carvalho Chehab 87d94cdae1SAlbert Vaca CintoraField 7 -- # of sectors written (unsigned long) 884f4cfa6cSMauro Carvalho Chehab This is the total number of sectors written successfully. 894f4cfa6cSMauro Carvalho Chehab 90d94cdae1SAlbert Vaca CintoraField 8 -- # of milliseconds spent writing (unsigned int) 914f4cfa6cSMauro Carvalho Chehab This is the total number of milliseconds spent by all writes (as 92*b089f167SNaohiro Aota measured from blk_mq_alloc_request() to __blk_mq_end_request()). 934f4cfa6cSMauro Carvalho Chehab 94d94cdae1SAlbert Vaca CintoraField 9 -- # of I/Os currently in progress (unsigned int) 954f4cfa6cSMauro Carvalho Chehab The only field that should go to zero. Incremented as requests are 964f4cfa6cSMauro Carvalho Chehab given to appropriate struct request_queue and decremented as they finish. 974f4cfa6cSMauro Carvalho Chehab 98d94cdae1SAlbert Vaca CintoraField 10 -- # of milliseconds spent doing I/Os (unsigned int) 994f4cfa6cSMauro Carvalho Chehab This field increases so long as field 9 is nonzero. 1004f4cfa6cSMauro Carvalho Chehab 1014f4cfa6cSMauro Carvalho Chehab Since 5.0 this field counts jiffies when at least one request was 1024f4cfa6cSMauro Carvalho Chehab started or completed. If request runs more than 2 jiffies then some 1032b8bd423SKonstantin Khlebnikov I/O time might be not accounted in case of concurrent requests. 1044f4cfa6cSMauro Carvalho Chehab 105d94cdae1SAlbert Vaca CintoraField 11 -- weighted # of milliseconds spent doing I/Os (unsigned int) 1064f4cfa6cSMauro Carvalho Chehab This field is incremented at each I/O start, I/O completion, I/O 1074f4cfa6cSMauro Carvalho Chehab merge, or read of these stats by the number of I/Os in progress 1084f4cfa6cSMauro Carvalho Chehab (field 9) times the number of milliseconds spent doing I/O since the 1094f4cfa6cSMauro Carvalho Chehab last update of this field. This can provide an easy measure of both 1104f4cfa6cSMauro Carvalho Chehab I/O completion time and the backlog that may be accumulating. 1114f4cfa6cSMauro Carvalho Chehab 112d94cdae1SAlbert Vaca CintoraField 12 -- # of discards completed (unsigned long) 1134f4cfa6cSMauro Carvalho Chehab This is the total number of discards completed successfully. 1144f4cfa6cSMauro Carvalho Chehab 115d94cdae1SAlbert Vaca CintoraField 13 -- # of discards merged (unsigned long) 1164f4cfa6cSMauro Carvalho Chehab See the description of field 2 1174f4cfa6cSMauro Carvalho Chehab 118d94cdae1SAlbert Vaca CintoraField 14 -- # of sectors discarded (unsigned long) 1194f4cfa6cSMauro Carvalho Chehab This is the total number of sectors discarded successfully. 1204f4cfa6cSMauro Carvalho Chehab 121d94cdae1SAlbert Vaca CintoraField 15 -- # of milliseconds spent discarding (unsigned int) 1224f4cfa6cSMauro Carvalho Chehab This is the total number of milliseconds spent by all discards (as 123*b089f167SNaohiro Aota measured from blk_mq_alloc_request() to __blk_mq_end_request()). 1244f4cfa6cSMauro Carvalho Chehab 125b6866318SKonstantin KhlebnikovField 16 -- # of flush requests completed 126b6866318SKonstantin Khlebnikov This is the total number of flush requests completed successfully. 127b6866318SKonstantin Khlebnikov 128b6866318SKonstantin Khlebnikov Block layer combines flush requests and executes at most one at a time. 129b6866318SKonstantin Khlebnikov This counts flush requests executed by disk. Not tracked for partitions. 130b6866318SKonstantin Khlebnikov 131b6866318SKonstantin KhlebnikovField 17 -- # of milliseconds spent flushing 132b6866318SKonstantin Khlebnikov This is the total number of milliseconds spent by all flush requests. 133b6866318SKonstantin Khlebnikov 1344f4cfa6cSMauro Carvalho ChehabTo avoid introducing performance bottlenecks, no locks are held while 1354f4cfa6cSMauro Carvalho Chehabmodifying these counters. This implies that minor inaccuracies may be 1364f4cfa6cSMauro Carvalho Chehabintroduced when changes collide, so (for instance) adding up all the 1374f4cfa6cSMauro Carvalho Chehabread I/Os issued per partition should equal those made to the disks ... 1384f4cfa6cSMauro Carvalho Chehabbut due to the lack of locking it may only be very close. 1394f4cfa6cSMauro Carvalho Chehab 1404f4cfa6cSMauro Carvalho ChehabIn 2.6+, there are counters for each CPU, which make the lack of locking 1414f4cfa6cSMauro Carvalho Chehabalmost a non-issue. When the statistics are read, the per-CPU counters 1424f4cfa6cSMauro Carvalho Chehabare summed (possibly overflowing the unsigned long variable they are 1434f4cfa6cSMauro Carvalho Chehabsummed to) and the result given to the user. There is no convenient 1444f4cfa6cSMauro Carvalho Chehabuser interface for accessing the per-CPU counters themselves. 1454f4cfa6cSMauro Carvalho Chehab 1462b8bd423SKonstantin KhlebnikovSince 4.19 request times are measured with nanoseconds precision and 1472b8bd423SKonstantin Khlebnikovtruncated to milliseconds before showing in this interface. 1482b8bd423SKonstantin Khlebnikov 1494f4cfa6cSMauro Carvalho ChehabDisks vs Partitions 1504f4cfa6cSMauro Carvalho Chehab------------------- 1514f4cfa6cSMauro Carvalho Chehab 1524f4cfa6cSMauro Carvalho ChehabThere were significant changes between 2.4 and 2.6+ in the I/O subsystem. 1534f4cfa6cSMauro Carvalho ChehabAs a result, some statistic information disappeared. The translation from 1544f4cfa6cSMauro Carvalho Chehaba disk address relative to a partition to the disk address relative to 1554f4cfa6cSMauro Carvalho Chehabthe host disk happens much earlier. All merges and timings now happen 1564f4cfa6cSMauro Carvalho Chehabat the disk level rather than at both the disk and partition level as 1574f4cfa6cSMauro Carvalho Chehabin 2.4. Consequently, you'll see a different statistics output on 2.6+ for 1584f4cfa6cSMauro Carvalho Chehabpartitions from that for disks. There are only *four* fields available 1594f4cfa6cSMauro Carvalho Chehabfor partitions on 2.6+ machines. This is reflected in the examples above. 1604f4cfa6cSMauro Carvalho Chehab 1614f4cfa6cSMauro Carvalho ChehabField 1 -- # of reads issued 1624f4cfa6cSMauro Carvalho Chehab This is the total number of reads issued to this partition. 1634f4cfa6cSMauro Carvalho Chehab 1644f4cfa6cSMauro Carvalho ChehabField 2 -- # of sectors read 1654f4cfa6cSMauro Carvalho Chehab This is the total number of sectors requested to be read from this 1664f4cfa6cSMauro Carvalho Chehab partition. 1674f4cfa6cSMauro Carvalho Chehab 1684f4cfa6cSMauro Carvalho ChehabField 3 -- # of writes issued 1694f4cfa6cSMauro Carvalho Chehab This is the total number of writes issued to this partition. 1704f4cfa6cSMauro Carvalho Chehab 1714f4cfa6cSMauro Carvalho ChehabField 4 -- # of sectors written 1724f4cfa6cSMauro Carvalho Chehab This is the total number of sectors requested to be written to 1734f4cfa6cSMauro Carvalho Chehab this partition. 1744f4cfa6cSMauro Carvalho Chehab 1754f4cfa6cSMauro Carvalho ChehabNote that since the address is translated to a disk-relative one, and no 1764f4cfa6cSMauro Carvalho Chehabrecord of the partition-relative address is kept, the subsequent success 1774f4cfa6cSMauro Carvalho Chehabor failure of the read cannot be attributed to the partition. In other 1784f4cfa6cSMauro Carvalho Chehabwords, the number of reads for partitions is counted slightly before time 1794f4cfa6cSMauro Carvalho Chehabof queuing for partitions, and at completion for whole disks. This is 1804f4cfa6cSMauro Carvalho Chehaba subtle distinction that is probably uninteresting for most cases. 1814f4cfa6cSMauro Carvalho Chehab 1824f4cfa6cSMauro Carvalho ChehabMore significant is the error induced by counting the numbers of 1834f4cfa6cSMauro Carvalho Chehabreads/writes before merges for partitions and after for disks. Since a 1844f4cfa6cSMauro Carvalho Chehabtypical workload usually contains a lot of successive and adjacent requests, 1854f4cfa6cSMauro Carvalho Chehabthe number of reads/writes issued can be several times higher than the 1864f4cfa6cSMauro Carvalho Chehabnumber of reads/writes completed. 1874f4cfa6cSMauro Carvalho Chehab 1884f4cfa6cSMauro Carvalho ChehabIn 2.6.25, the full statistic set is again available for partitions and 1894f4cfa6cSMauro Carvalho Chehabdisk and partition statistics are consistent again. Since we still don't 1904f4cfa6cSMauro Carvalho Chehabkeep record of the partition-relative address, an operation is attributed to 1914f4cfa6cSMauro Carvalho Chehabthe partition which contains the first sector of the request after the 1924f4cfa6cSMauro Carvalho Chehabeventual merges. As requests can be merged across partition, this could lead 1934f4cfa6cSMauro Carvalho Chehabto some (probably insignificant) inaccuracy. 1944f4cfa6cSMauro Carvalho Chehab 1954f4cfa6cSMauro Carvalho ChehabAdditional notes 1964f4cfa6cSMauro Carvalho Chehab---------------- 1974f4cfa6cSMauro Carvalho Chehab 1984f4cfa6cSMauro Carvalho ChehabIn 2.6+, sysfs is not mounted by default. If your distribution of 1994f4cfa6cSMauro Carvalho ChehabLinux hasn't added it already, here's the line you'll want to add to 2004f4cfa6cSMauro Carvalho Chehabyour ``/etc/fstab``:: 2014f4cfa6cSMauro Carvalho Chehab 2024f4cfa6cSMauro Carvalho Chehab none /sys sysfs defaults 0 0 2034f4cfa6cSMauro Carvalho Chehab 2044f4cfa6cSMauro Carvalho Chehab 2054f4cfa6cSMauro Carvalho ChehabIn 2.6+, all disk statistics were removed from ``/proc/stat``. In 2.4, they 2064f4cfa6cSMauro Carvalho Chehabappear in both ``/proc/partitions`` and ``/proc/stat``, although the ones in 2074f4cfa6cSMauro Carvalho Chehab``/proc/stat`` take a very different format from those in ``/proc/partitions`` 2084f4cfa6cSMauro Carvalho Chehab(see proc(5), if your system has it.) 2094f4cfa6cSMauro Carvalho Chehab 2104f4cfa6cSMauro Carvalho Chehab-- ricklind@us.ibm.com 211