Calculating vm.nr_hugepages

From: Troels Arvin <troels(at)arvin(dot)dk>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Calculating vm.nr_hugepages
Date: 2023-08-30 13:12:13
Message-ID: 43ddf925-9c8b-b023-282c-b20e9366077d@arvin.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I'm writing an Ansible play which is to set the correct value for
vm.nr_hugepages on Linux servers where I hope to make Postgres make use
of huge pages.

However, I'm struggling to find the right formula.

I assume I need to find the same value as I get from running "postgres
-C shared_memory_size_in_huge_pages". I call that my target value.
Note: I cannot simply run "postgres -C ...", because I need my Ansible
play to work against a server where Postgres is running.

I've tried using the formula described at
https://www.cybertec-postgresql.com/en/huge-pages-postgresql/, but it
produces a different value than my target:

Using a shared_buffers value of 21965570048, like in Cybertec
Postgresql's example:
"postgres ... -C 21965570048B" yields: 10719
The formula from Cybertec Postgresql says: 10475

I've also tried doing what ChatGPG suggested:
Number of Huge Pages when shared_buffers is set to 1 GiB =
shared_buffers / huge_page_size
                    = 1073741824 bytes / 2097152 bytes
                    = 512
But that's also wrong compared to "postgres -C ..." (which said 542).

Which formula can I use? It's OK for me for it to be slightly wrong
compared to "postgres -C", but if it's wrong, it needs to be slightly
higher than what "postgres -C" outputs, so that I'm sure there's enough
huge pages for Postgres to be able to use them properly.

--
Kind regards,
Troels Arvin

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Don Seiler 2023-08-30 14:06:19 Re: Calculating vm.nr_hugepages
Previous Message Peter J. Holzer 2023-08-30 10:00:30 Re: Restoring default privileges on objects