ghw-snapshot no longer operates as expected on newer releases of the Linux kernel because it attempts to copy the demote interface (by glob expansion) from inside hugepages sysfs. The demote interface is, as per the spec, write-only and therefore cannot be copied.
This is easily reproducible on any system running the latest Linux kernel (discovered when attempting to run on up-to-date Arch Linux).
Failure produced:
$ ./ghw-snapshot
Error: open /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/demote: permission denied
Usage:
ghw-snapshot [flags]
Flags:
-d, --debug Enable or disable debug mode
-h, --help help for ghw-snapshot
-o, --out string Path to place snapshot. Defaults to file in current directory with name $OS-$ARCH-$HASHSYSTEMNAME.tar.gz
More information (evidence of write-only interface):
$ cd/sys/devices/system/node/node0/hugepages/hugepages-1048576kB
$ ls -ashil
total 0
3404 0 drwxr-xr-x 2 root root 0 Mar 18 13:49 .
3403 0 drwxr-xr-x 4 root root 0 Mar 18 13:49 ..
3409 0 --w------- 1 root root 4.0K Mar 19 10:37 demote
3408 0 -rw-r--r-- 1 root root 4.0K Mar 19 10:40 demote_size
3406 0 -r--r--r-- 1 root root 4.0K Mar 19 10:40 free_hugepages
3405 0 -rw-r--r-- 1 root root 4.0K Mar 19 10:40 nr_hugepages
3407 0 -r--r--r-- 1 root root 4.0K Mar 19 10:40 surplus_hugepages
ghw-snapshot no longer operates as expected on newer releases of the Linux kernel because it attempts to copy the demote interface (by glob expansion) from inside hugepages sysfs. The demote interface is, as per the spec, write-only and therefore cannot be copied.
This is easily reproducible on any system running the latest Linux kernel (discovered when attempting to run on up-to-date Arch Linux). Failure produced:
More information (evidence of write-only interface):
External references:
https://www.kernel.org/doc/html/v5.16-rc3/admin-guide/mm/hugetlbpage.html
I would recommend only attempting to copy files with the read permission set to avoid more issues such as this in the future. I can send a PR.