pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Huge pages section needs to describe hugetlb_shm_group, memlock limit
2+ messages / 2 participants
[nested] [flat]

* Huge pages section needs to describe hugetlb_shm_group, memlock limit
@ 2014-09-20 21:24  Laurence Parry <greenreaper@hotmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Laurence Parry @ 2014-09-20 21:24 UTC (permalink / raw)
  To: pgsql-docs

Regarding the coverage of huge pages (added in 9.4):
http://www.postgresql.org/docs/9.4/static/kernel-resources.html#LINUX-HUGE-PAGES

This section does not call out the need to add the PostgreSQL user to a 
group which has been given access to shared memory by setting its number as 
vm.hugetlb_shm_group, nor that the "memlock" limit needs to be raised or set 
to unlimited for this user.

If these are not done, postgres would need to be running as a user with 
CAP_IPC_LOCK (e.g. root) to take advantage of large pages. These 
restrictions exist because reserving a large page locks it in physical 
memory, which can lead to resource exhaustion.

Compare http://dev.mysql.com/doc/refman/5.7/en/large-page-support.html which 
mentions both of these issues (although it does not show adding the user to 
the group, just setting the group as vm.hugetlb_shm_group).

An example command sequence:
groupadd hugepages
gpasswd -a postgres hugepages
id postgres [user finds "hugepages" group has id 1234]

sysctl -w vm.hugetlb_shm_group=1234
sysctl -w vm.nr_hugepages=5678 [as estimated in documentation]

Edit /etc/sysctl.conf and add:
    vm.hugetlb_shm_group=1234
    vm.nr_hugepages=5678

Add to /etc/security/limits.conf:
    @hugepages      soft    memlock         unlimited
    @hugepages      hard    memlock         unlimited

In some cases (e.g. Debian's start-stop-daemon) the command "ulimit -l 
unlimited" may be needed in the PostgreSQL startup scripts instead of the 
limits.conf edit, because PAM limits are not called for those scripts.

Hope this helps,
-- 
Laurence "GreenReaper" Parry
http://greenreaper.co.uk - http://wikifur.com - http://flayrah.com
"Eternity lies ahead of us, and behind. Have you drunk your fill?" 



-- 
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Huge pages section needs to describe hugetlb_shm_group, memlock limit
@ 2014-10-13 21:24  Bruce Momjian <bruce@momjian.us>
  parent: Laurence Parry <greenreaper@hotmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruce Momjian @ 2014-10-13 21:24 UTC (permalink / raw)
  To: Laurence Parry <greenreaper@hotmail.com>; +Cc: pgsql-docs

On Sat, Sep 20, 2014 at 10:24:51PM +0100, Laurence Parry wrote:
> Regarding the coverage of huge pages (added in 9.4):
> http://www.postgresql.org/docs/9.4/static/kernel-resources.html#LINUX-HUGE-PAGES
> 
> This section does not call out the need to add the PostgreSQL user
> to a group which has been given access to shared memory by setting
> its number as vm.hugetlb_shm_group, nor that the "memlock" limit
> needs to be raised or set to unlimited for this user.
> 
> If these are not done, postgres would need to be running as a user
> with CAP_IPC_LOCK (e.g. root) to take advantage of large pages.
> These restrictions exist because reserving a large page locks it in
> physical memory, which can lead to resource exhaustion.
> 
> Compare
> http://dev.mysql.com/doc/refman/5.7/en/large-page-support.html which
> mentions both of these issues (although it does not show adding the
> user to the group, just setting the group as vm.hugetlb_shm_group).
> 
> An example command sequence:
> groupadd hugepages
> gpasswd -a postgres hugepages
> id postgres [user finds "hugepages" group has id 1234]
> 
> sysctl -w vm.hugetlb_shm_group=1234
> sysctl -w vm.nr_hugepages=5678 [as estimated in documentation]
> 
> Edit /etc/sysctl.conf and add:
>    vm.hugetlb_shm_group=1234
>    vm.nr_hugepages=5678
> 
> Add to /etc/security/limits.conf:
>    @hugepages      soft    memlock         unlimited
>    @hugepages      hard    memlock         unlimited
> 
> In some cases (e.g. Debian's start-stop-daemon) the command "ulimit
> -l unlimited" may be needed in the PostgreSQL startup scripts
> instead of the limits.conf edit, because PAM limits are not called
> for those scripts.

I have applied the attached doc patch.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

-- 
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs

Attachments:

huge.diff (text/x-diff, 776B) download diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml new file mode 100644 index 639b288..026850a *** a/doc/src/sgml/runtime.sgml --- b/doc/src/sgml/runtime.sgml *************** $ <userinput>sysctl -w vm.nr_hugepages=3 *** 1361,1366 **** --- 1361,1373 ---- </para> <para> + It is also necessary to give the database server operating system + user permission to use huge pages by setting + <varname>vm.hugetlb_shm_group</> via <application>sysctl</>, and + permission to lock memory with <command>ulimit -l</>. + </para> + + <para> The default behavior for huge pages in <productname>PostgreSQL</productname> is to use them when possible and to fallback to normal pages when failing. To enforce the use of huge
^ permalink raw reply [nested|flat] 2+ messages in thread


end of thread, other threads:[~2014-10-13 21:24 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-09-20 21:24 Huge pages section needs to describe hugetlb_shm_group, memlock limit Laurence Parry <greenreaper@hotmail.com>
2014-10-13 21:24 ` Bruce Momjian <bruce@momjian.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox