What: The systemd service I wrote does not allocate huge pages as expected.
Why: Huge pages are needed by our hardware service, and the huge pages must be allocated on NUMA node 0.
How I’ve written a systemd service file that should set the values correctly. However, it doesn’t. When I run the commands interactive as root, it works fine. There is no error message displayed.
I’ve having trouble setting up a one-shot systemd service that allocates huge pages among the two NUMA nodes. If I execute the commands at the command line, it works. If it gets executed through systemd, nothing happens. I can see that the commands are getting executed in /var/log/messages, but they are having no effect.
Here is /var/log/messages:
May 15 00:01:07 dev05 systemd[1]: Starting Huge Pages Reservation...
May 15 00:01:07 dev05 echo[27493]: 0 > /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/nr_hugepages
May 15 00:01:07 dev05 echo[27494]: 71 > /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages
May 15 00:01:07 dev05 cat[27495]: 1
May 15 00:01:07 dev05 cat[27496]: 64
May 15 00:01:07 dev05 id[27497]: uid=0(root) gid=0(root) groups=0(root)
May 15 00:01:07 sparc-dev05 systemd[1]: pacbio-huge-pages.service: Deactivated successfully.
May 15 00:01:07 sparc-dev05 systemd[1]: Finished Huge Pages Reservation.
Here is the service:
[Unit]
Description=Huge Pages Reservation
DefaultDependencies=no
Before=dev-hugepages.mount
ConditionPathExists=/sys/devices/system/node
ConditionKernelCommandLine=hugepagesz=1GB
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/bin/echo 0 > /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/nr_hugepages
ExecStart=/bin/echo 71 > /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages
ExecStart=cat /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/nr_hugepages
ExecStart=cat /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages
ExecStart=/usr/bin/id
[Install]
WantedBy=sysinit.target
If I execute those echo commands under su, it works correctly. All of these commands were executed with a few seconds of each other, so this is not a boot race condition.
At the command line, I do it like this, and it works.
$ echo 71 > /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages
71
$ cat /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages
71
$ echo 0 > /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/nr_hugepages
0
$ cat /sys/devices/system/node/node1/hugepages/hugepages-1048576kB/nr_hugepages
0