[doc fix] Correct calculation of vm.nr_hugepages
[doc fix] Correct calculation of vm.nr_hugepages
Hello, The current PostgreSQL documentation overestimates the number of huge pages (vm.nr_hugepages) because the calculation uses the maximum virtual address space. In practice, huge pages are only used for the anonymous shared memory segment. The attached patch fixes the documentation. FYI, Oracle presents a shell script to calculate the number of huge pages for its shared memory segments: https://docs.oracle.com/cd/E11882_01/server.112/e10839/appi_vlm.htm#UNXAR385 Regards Takayuki Tsunakawa
Re: [doc fix] Correct calculation of vm.nr_hugepages
От:
Justin Pryzby <pryzby@telsasoft.com>
Дата:
On Mon, Feb 19, 2018 at 07:05:47AM +0000, Tsunakawa, Takayuki wrote:
> The current PostgreSQL documentation overestimates the number of huge pages
> (vm.nr_hugepages) because the calculation uses the maximum virtual address
> space. In practice, huge pages are only used for the anonymous shared memory
> segment. The attached patch fixes the documentation.
+ pmap 4170 | grep rw-s | grep zero | awk '{print $2}'
One can do with fewer greps:
pryzbyj@pryzbyj:~$ sudo pmap `pgrep -P 1 -u postgres` |awk '/rw-s/&&/zero/{print $2}' # check PPID=1
144848K
or:
pryzbyj@pryzbyj:~$ sudo pmap `pgrep -u postgres |sed q` |awk '/rw-s/&&/zero/{print $2}' # check any backend, not just postmaster parent
144848K
Or (this is even less clean but gives an alternative which continues to use
/proc directly):
pryzbyj@pryzbyj:~$ sudo cat /proc/`pgrep -P 1 -u postgres`/maps |awk --non-decimal-data 'BEGIN{FS="[ -]"} /zero/{a="0x"$1;b="0x"$2;print (b-a)/1024"kB"}'
144848kB
BTW when huge_pages=try, I've been verifying hugepages are in use by running:
pryzbyj@pryzbyj:~$ sudo sh -c 'cat /proc/`pgrep -u postgres -P1`/smaps |grep -c "KernelPageSize: *2048 kB"' || echo NOT FOUND
0
NOT FOUND
Justin
RE: [doc fix] Correct calculation of vm.nr_hugepages
From: Justin Pryzby [mailto:pryzby@telsasoft.com]
> One can do with fewer greps:
> pryzbyj@pryzbyj:~$ sudo pmap `pgrep -P 1 -u postgres` |awk
> '/rw-s/&&/zero/{print $2}' # check PPID=1 144848K
Thanks, I'd like to take this.
Regards
Takayuki Tsunakawa
Re: [doc fix] Correct calculation of vm.nr_hugepages
От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Mon, Feb 19, 2018 at 9:43 PM, Tsunakawa, Takayuki wrote: > Thanks, I'd like to take this. Why are these values so large? The example in the documentation shows 6490428 kB, and in my test I got 8733888 kB. But 8733888 kB = 8.3 TB! 8.3 GB would make sense, but 8.3 TB does not. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Re: [doc fix] Correct calculation of vm.nr_hugepages
От:
Justin Pryzby <pryzby@telsasoft.com>
Дата:
On Wed, Feb 21, 2018 at 03:14:57PM -0500, Robert Haas wrote:
> On Mon, Feb 19, 2018 at 9:43 PM, Tsunakawa, Takayuki
> wrote:
> > Thanks, I'd like to take this.
>
> Why are these values so large? The example in the documentation shows
> 6490428 kB, and in my test I got 8733888 kB. But 8733888 kB = 8.3 TB!
> 8.3 GB would make sense, but 8.3 TB does not.
pryzbyj@pryzbyj:~$ units -t -v 8733888kB GiB
8733888kB = 8.1340671 GiB
Re: [doc fix] Correct calculation of vm.nr_hugepages
От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Wed, Feb 21, 2018 at 3:28 PM, Justin Pryzby wrote: > On Wed, Feb 21, 2018 at 03:14:57PM -0500, Robert Haas wrote: >> On Mon, Feb 19, 2018 at 9:43 PM, Tsunakawa, Takayuki >> wrote: >> > Thanks, I'd like to take this. >> >> Why are these values so large? The example in the documentation shows >> 6490428 kB, and in my test I got 8733888 kB. But 8733888 kB = 8.3 TB! >> 8.3 GB would make sense, but 8.3 TB does not. > > pryzbyj@pryzbyj:~$ units -t -v 8733888kB GiB > 8733888kB = 8.1340671 GiB Sigh. It would be nice if I were less stupid. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Re: [doc fix] Correct calculation of vm.nr_hugepages
От:
Vasundhar Boddapati <bvasundhar@gmail.com>
Дата:
The following review has been posted through the commitfest application: make installcheck-world: not tested Implements feature: not tested Spec compliant: not tested Documentation: tested, passed It works. Can be Merged.
Re: [doc fix] Correct calculation of vm.nr_hugepages
От:
Andres Freund <andres@anarazel.de>
Дата:
On 2018-02-20 02:43:32 +0000, Tsunakawa, Takayuki wrote:
> diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml
> index d162acb..1aed070 100644
> --- a/doc/src/sgml/runtime.sgml
> +++ b/doc/src/sgml/runtime.sgml
> @@ -1472,14 +1472,14 @@ export PG_OOM_ADJUST_VALUE=0
> the kernel setting vm.nr_hugepages. To estimate the
> number of huge pages needed, start PostgreSQL
> without huge pages enabled and check the
> - postmaster's VmPeak value, as well as the system's
> + postmaster's anonymous shared memory segment size, as well as the system's
> huge page size, using the /proc file system. This might
> look like:
>
> $ head -1 $PGDATA/postmaster.pid
> 4170
> -$ grep ^VmPeak /proc/4170/status
> -VmPeak: 6490428 kB
> +$ pmap 4170 | awk '/rw-s/ && /zero/ {print $2}'
> +6490428K
> $ grep ^Hugepagesize /proc/meminfo
> Hugepagesize: 2048 kB
>
One disadvantage of this is that it relies on the presence of pmap,
which IIRC is not installed by default in a number of distributions. Are
we concerned about that?
Greetings,
Andres Freund
Re: [doc fix] Correct calculation of vm.nr_hugepages
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 2/26/18 08:25, Vasundhar Boddapati wrote: > The following review has been posted through the commitfest application: > make installcheck-world: not tested > Implements feature: not tested > Spec compliant: not tested > Documentation: tested, passed > > It works. Can be Merged. committed -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [doc fix] Correct calculation of vm.nr_hugepages
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 3/1/18 04:54, Andres Freund wrote: > One disadvantage of this is that it relies on the presence of pmap, > which IIRC is not installed by default in a number of distributions. Are > we concerned about that? It's in the same package as "top", so I think that's fine. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services