The use of huge pages results in smaller page tables and less CPU time spent on memory management, increasing performance.
This is how I set up huge pages on one of my postgreSQL servers.
First, check the server's huge page size. My huge pages are 2M each:
grep Hugepagesize /proc/meminfo Hugepagesize: 2048 kBOn my 16G server, I would like to start with 25% of the total memory as available for shared_buffers:
su - postgres sudo systemctl stop postgresql-15.service postgres --shared-buffers=4096MB -D $PGDATA -C shared_memory_size_in_huge_pages 2102Update /etc/sysctl.conf. Add
vm.nr_hugepages=2102Restart sysctl
sysctl -pNow, tell the postgres server to use huge pages, if they are available.
Add the following directive to the config file postgresql.conf
huge_pages = tryAdd the following lines to /etc/security/limits.conf so that postgres can lock down the memory set aside for huge tables:
postgres soft memlock unlimited postgres hard memlock unlimitedReboot the server and verify that huge pages are being used:
cat /proc/meminfo | grep HugeInterestingly, the parameter huge_page_size should only be used if you wish to override the default huge page size on your system. The default is zero (0). When set to 0, the default huge page size on the system will be used. In my case this is what I want to so the parameter can be ignored.