<div dir="ltr">I forgot to add the following. You also need to update your /etc/default/grub entry with the proper hugepagesz=2M entry. Like below. The service won't "activate" unless you configure this.<div><br></div><div>GRUB_CMDLINE_LINUX_DEFAULT="nomodeset quiet splash intel_iommu=on hugepagesz=2M pci_stub.ids=10de:13c2,10de:0fbb,104c:8241"</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 17, 2017 at 2:44 PM Ryan Flagler <<a href="mailto:ryan.flagler@gmail.com">ryan.flagler@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">So, I just wanted to share the process I found for allocating hugepages from memory tied to a specific numa node on your system. Traditionally, I had a /etc/default/grub that looked like this.<div><br></div><div>GRUB_CMDLINE_LINUX_DEFAULT="nomodeset quiet splash intel_iommu=on hugepages=6144 pci_stub.ids=10de:13c2,10de:0fbb,104c:8241"<br></div><div><br></div><div>This would allocate 12GB of hugepages (utilizing the default size of 2MB/hugepage). However, my allocation would look like this.</div><div><br></div><div>cat /sys/devices/system/node/node*/meminfo | fgrep Huge<br></div><div><div>Node 0 AnonHugePages:     20480 kB</div><div>Node 0 HugePages_Total:  3072</div><div>Node 0 HugePages_Free:   3072</div><div>Node 0 HugePages_Surp:      0</div><div>Node 1 AnonHugePages:         0 kB</div><div>Node 1 HugePages_Total:  3072</div><div>Node 1 HugePages_Free:   3072</div><div>Node 1 HugePages_Surp:      0</div></div><div><br></div><div>As you can see, half of the hugepages were allocated to each of my numa nodes. In my VM configuration, I had all my CPUs pinned to Numa Node 1, and I allocated 8GB of memory to that VM. So some of my hugepage memory was coming from numa node 1 and some from numa node 0.</div><div><br></div><div>If you're dynamically allocating hugepages on the fly, you can easily specify which numa node you allocate the memory from with something like this.</div><div>echo 6144 > $nodes_path/node1/hugepages/hugepages-2048kB/nr_hugepages<br></div><div><br></div><div>The problem is you may not have 6144 available pages on numa node1 when you need them.</div><div><br></div><div>I came across the following page that documented how to dyanmically allocate hugepages betweene numa nodes on boot on RHEL7 using systemd.</div><div><a href="http://fibrevillage.com/sysadmin/536-how-to-enable-and-config-hugepage-and-transparent-hugepages-on-rhel-centos" target="_blank">http://fibrevillage.com/sysadmin/536-how-to-enable-and-config-hugepage-and-transparent-hugepages-on-rhel-centos</a><br></div><div><br></div><div>Thankfully, I'm running Ubuntu 16.04 which also utilizes systemd. There were a couple differences, so here's what I did.</div><div><br></div><div><div>Create /lib/systemd/system/hugetlb-gigantic-pages.service with the following contents</div><div>[Unit]</div><div>Description=HugeTLB Gigantic Pages Reservation</div><div>DefaultDependencies=no</div><div>Before=dev-hugepages.mount</div><div>ConditionPathExists=/sys/devices/system/node</div><div>ConditionKernelCommandLine=hugepagesz=2M</div><div>[Service]</div><div>Type=oneshot</div><div>RemainAfterExit=yes</div><div>ExecStart=/lib/systemd/hugetlb-reserve-pages</div><div>[Install]</div><div>WantedBy=sysinit.target</div></div><div><br></div><div><div>Create /lib/systemd/hugetlb-reserve-pages with the following contents</div><div>#!/bin/sh</div><div>nodes_path=/sys/devices/system/node/</div><div>if [ ! -d $nodes_path ]; then</div><div>echo "ERROR: $nodes_path does not exist"</div><div>exit 1</div><div>fi</div><div>reserve_pages()</div><div>{</div><div>echo $1 > $nodes_path/$2/hugepages/hugepages-2048kB/nr_hugepages</div><div>}</div><div># This example reserves 2 2M pages on node0 and 1 1M page on node1.</div><div># You can modify it to your needs or add more lines to reserve memory in</div><div># other nodes. Don't forget to uncomment the lines, otherwise they won't</div><div># be executed.</div><div># reserve_pages 2 node0</div><div># reserve_pages 1 node1</div><div>reserve_pages 6144 node1</div></div><div><br></div><div>Note my uncommented line to allocate 6144 pages to numa node1.</div><div><br></div><div>Update permissions and enable the job</div><div><div>chmod +x /lib/systemd/hugetlb-reserve-pages</div><div>systemctl enable hugetlb-gigantic-pages</div></div><div><br></div><div>Reboot</div><div><br></div><div>After reboot, I saw the following.</div><div><div>cat /sys/devices/system/node/node*/meminfo | fgrep Huge</div><div>Node 0 AnonHugePages:    169984 kB</div><div>Node 0 HugePages_Total:     0</div><div>Node 0 HugePages_Free:      0</div><div>Node 0 HugePages_Surp:      0</div><div>Node 1 AnonHugePages:    184320 kB</div><div>Node 1 HugePages_Total:  6144</div><div>Node 1 HugePages_Free:   6144</div><div>Node 1 HugePages_Surp:      0</div></div><div><br></div><div>And after starting my VM with all CPUs pinned on Node 1 and with 8GB of memory, I see this.</div><div><div>cat /sys/devices/system/node/node*/meminfo | fgrep Huge</div><div>Node 0 AnonHugePages:    724992 kB</div><div>Node 0 HugePages_Total:     0</div><div>Node 0 HugePages_Free:      0</div><div>Node 0 HugePages_Surp:      0</div><div>Node 1 AnonHugePages:    270336 kB</div><div>Node 1 HugePages_Total:  6144</div><div>Node 1 HugePages_Free:   2048</div><div>Node 1 HugePages_Surp:      0</div></div><div><br></div><div>Lastly, here is the status output of the systemd job.</div><div><div>service hugetlb-gigantic-pages status</div><div>â— hugetlb-gigantic-pages.service - HugeTLB Gigantic Pages Reservation</div><div>   Loaded: loaded (/lib/systemd/system/hugetlb-gigantic-pages.service; enabled; vendor preset: enabled)</div><div>   Active: active (exited) since Wed 2017-05-17 12:01:49 CDT; 3min 17s ago</div><div>  Process: 872 ExecStart=/lib/systemd/hugetlb-reserve-pages (code=exited, status=0/SUCCESS)</div><div> Main PID: 872 (code=exited, status=0/SUCCESS)</div><div>    Tasks: 0</div><div>   Memory: 0B</div><div>      CPU: 0</div><div>   CGroup: /system.slice/hugetlb-gigantic-pages.service</div></div><div><br></div><div>Hopefully this helps someone else!</div></div></blockquote></div>