Skip to content

Commit

Permalink
Future-proof disk_io_counters on Linux. (#1665)
Browse files Browse the repository at this point in the history
Kernel 5.5 added 2 more fields to /proc/diskstats, requiring another
change after the one for 4.18, which recently added 4 fields.

At this point in time, the meaning of the existing fields is unlikely to
change, and psutil is not using any of the newer ones. By considering
18 fields and more to have the current layout, psutil will continue to
work as newer kernels add more fields.
  • Loading branch information
glandium authored and giampaolo committed Jan 17, 2020
1 parent 678292f commit 2e0952e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion psutil/_pslinux.py
Expand Up @@ -1066,6 +1066,7 @@ def read_procfs():
# "3 1 hda1 8 8 8 8"
# 4.18+ has 4 fields added:
# "3 0 hda 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0"
# 5.5 has 2 more fields.
# See:
# https://www.kernel.org/doc/Documentation/iostats.txt
# https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
Expand All @@ -1080,7 +1081,7 @@ def read_procfs():
reads = int(fields[2])
(reads_merged, rbytes, rtime, writes, writes_merged,
wbytes, wtime, _, busy_time, _) = map(int, fields[4:14])
elif flen == 14 or flen == 18:
elif flen == 14 or flen >= 18:
# Linux 2.6+, line referring to a disk
name = fields[2]
(reads, reads_merged, rbytes, rtime, writes, writes_merged,
Expand Down

0 comments on commit 2e0952e

Please sign in to comment.