Skip to content

[Linux] virtual_memory() fails when /proc/meminfo contains ShadowCallStack >= 10MB #2809

Description

@hanson-openai

Summary

  • OS: Linux
  • Architecture: ARM
  • Psutil version: 7.1.2
  • Python version: 3.12.9
  • Type: core

Description

On an arm64 Linux machine, psutil.virtual_memory() fails when /proc/meminfo contains a line like:

ShadowCallStack:10373888 kB

Because the parsing in _pslinux.py breaks when no space is present after the metric name:

https://github.com/giampaolo/psutil/blob/a59dae7/psutil/_pslinux.py#L258-L259

            fields = line.split()
            mems[fields[0]] = int(fields[1]) * 1024

The upstream cause is actually due to a quirk in the Linux kernel, where for some reason ShadowCallStack is printed with padding up to 8 digits (none of the other meminfo fields are like this) but without a guaranteed space:

https://github.com/torvalds/linux/blob/8356a5a3b078ca89c526dd6d71e9a76fec571c37/fs/proc/meminfo.c#L113-L116

	seq_printf(m, "ShadowCallStack:%8lu kB\n",

So whenever ShadowCallStack >= 10MB this issue occurs! Suggested fix below.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions