0

I am trying to modify something in /sys. My command is failing.

e.g. echo 63 > /sys/bus/pci/devices/0000:62:00.0/sriov_numvfs -> bash: echo: write error: Cannot allocate memory

e.g. echo three > /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/nr_hugepages -> bash: echo: write error: Invalid argument

How can I debug these failures? Is there a general method to find the logs for whatever is on the other side of these virtual files? Ideally I want to find the process or source code for whatever is generating the error message.

  • 1
    The "other side" of these nodes is handled by the kernel - many of the nodes in sysfs are only intended to provide information (i.e: are read only), and many others can only be written to while the system is in a certain state (e.g: not configured). – Attie May 8 at 10:06
2

The process is the Linux kernel. Its source code can be found on various Git repositories.

Log messages generated by the kernel would show up in dmesg (with the exception of "debug"-level messages which need to be enabled first).

Sysfs attributes are defined and handled by the device drivers, but it's usually easier to just git grep (or use Elixir online search) for the specific filename that causes problems and keep digging from there. Look for a pair of "store"/"show" functions, which accept your writes and provide data for your reads.

  • Writes to sriov_numvfs are handled by sriov_numvfs_store() in drivers/pci/pci-sysfs.c. The error messages it prints (using pci_info or pci_err) go to dmesg.

  • The part that handles writes to nr_hugepages (both the global sysctl and per-node attributes) appears to be in mm/hugetlb.c – look for function __nr_hugepages_store_common(). Unfortunately the code doesn't actually generate log messages in the first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.