Skip to content

Improve Memory Detection #13

Open
Open
@wdelgenio

Description

@wdelgenio

Instead of guessing how much memory a system has from /proc/meminfo, it's possible to get an exact value using sysfs.

For example, the lshw util queries the /sys/devices/system/memory dir for available memory blocks and uses /sys/devices/system/memory/block_size_bytes as the block size. Check that each memory block is online by checking the value of /sys/devices/system/memory/memory*/online

Here's the documentation on the sysfs memory blocks https://www.ibm.com/support/knowledgecenter/en/linuxonibm/com.ibm.linux.z.lgdd/lgdd_c_mem_know_sysfs.html

Here's a one-liner:
printf '%c' /sys/devices/system/memory/memory*/online | wc -c | dc -e '?16i' -f /sys/devices/system/memory/block_size_bytes -e '*p' | numfmt --to=iec-i --suffix B

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions