Formatting of /proc/meminfo

From: Ulrich Windl
Date: Tue Jun 23 2015 - 04:55:32 EST


Hi!

My eyes just discovered this mis-alignment for x86_64 machines:
---
# cat /proc/meminfo
MemTotal: 81366016 kB
MemFree: 36484504 kB
Buffers: 1018764 kB
Cached: 38230264 kB
[...]
VmallocTotal: 34359738367 kB
VmallocUsed: 92792 kB
VmallocChunk: 34359544432 kB
HardwareCorrupted: 0 kB
DirectMap4k: 132623356 kB
DirectMap2M: 0 kB
---

It seems the very big numbers for "Vmalloc" are OK, so I suggest to update the formatting. The current code looks like this (/usr/src/linux/fs/proc/meminfo.c):
---
seq_printf(m,
"MemTotal: %8lu kB\n"
"MemFree: %8lu kB\n"
"Buffers: %8lu kB\n"
[...]
---

So the field should be widened by three digits at least (%11lu kB). Maybe one could make the field width variable, depending on 32/64 bit (it would look like a waste on 32 bit platforms).

Maybe the code would be friendlier to changes if there was one seq_printf() per value. Then one could use something like
seq_printf(m, "%-16s%8lu kB\n", "MemTotal:", K(i.totalram))
instead, I guess... You could put the format (%-16s%8lu kB\n) in a constant also, allowing a change at one point to affect every item...
Probably gcc will optimize the code anyway, so there won't be much difference regarding performance.

Regards,
Ulrich Windl


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/