Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xdn65-0007pK-HE for pgsql-docs@arkaria.postgresql.org; Mon, 13 Oct 2014 21:24:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xdn65-0006N5-1M for pgsql-docs@arkaria.postgresql.org; Mon, 13 Oct 2014 21:24:05 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xdn64-0006MG-BX for pgsql-docs@postgresql.org; Mon, 13 Oct 2014 21:24:04 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xdn61-0006kg-2A for pgsql-docs@postgresql.org; Mon, 13 Oct 2014 21:24:02 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1Xdn60-00017H-76; Mon, 13 Oct 2014 17:24:00 -0400 Date: Mon, 13 Oct 2014 17:24:00 -0400 From: Bruce Momjian To: Laurence Parry Cc: pgsql-docs@postgresql.org Subject: Re: Huge pages section needs to describe hugetlb_shm_group, memlock limit Message-ID: <20141013212400.GN21267@momjian.us> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="m972NQjnE83KvVa/" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org --m972NQjnE83KvVa/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --m972NQjnE83KvVa/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="huge.diff" 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 *************** $ sysctl -w vm.nr_hugepages=3 *** 1361,1366 **** --- 1361,1373 ---- + It is also necessary to give the database server operating system + user permission to use huge pages by setting + vm.hugetlb_shm_group via sysctl, and + permission to lock memory with ulimit -l. + + + The default behavior for huge pages in PostgreSQL is to use them when possible and to fallback to normal pages when failing. To enforce the use of huge --m972NQjnE83KvVa/ Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs --m972NQjnE83KvVa/--