]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lsmem: fix total online/offline memory calculation
authorGerald Schaefer <gerald.schaefer@de.ibm.com>
Tue, 20 Mar 2018 16:17:38 +0000 (17:17 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Mar 2018 17:57:07 +0000 (18:57 +0100)
commit49834246f502313afdc43b08dbd5b8ffa10c19ea
tree8fba80048abe397297c27880266f478cd39f1b7e
parent1b692a26f7eaad0a5bb7eecd6eca900955e25692
lsmem: fix total online/offline memory calculation

lsmem currently calculates the total online/offline memory by iterating
over all lsmem->blocks. Depending on the lsmem options, there may be
only one lsmem->block, because all sysfs memory blocks could be merged
into one. In this case, the calculation is wrong, because the individual
online/offline state of the sysfs memory blocks is not preserved, but
rather lsmem->blocks[0].state is set to the state of the first sysfs
memory block, typically MEMORY_STATE_ONLINE (at least on s390).

This means that "Total offline memory" will always be calculated as 0
in such cases, e.g. when using "lsmem --summary", or any options that
would merge the table output to one line, like "lsmem -o RANGE":

~# lsmem --summary
Memory block size:         1G
Total online memory:      20G
Total offline memory:      0B

Adding the "-a" option shows the real summary, since there is no block
merging going on, and the calculation is therefore correct:

~# lsmem -a --summary
Memory block size:         1G
Total online memory:      16G
Total offline memory:      4G

Fix this by moving the online/offline calculation into the loop that
is iterating over all sysfs memory blocks, instead of iterating over
potentially merged lsmem->blocks.

Reported-by: Alexander Klein <alkl@linux.vnet.ibm.com>
Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
sys-utils/lsmem.c