Thread: pgsql: Allow using huge TLB pages on Linux (MAP_HUGETLB)

pgsql: Allow using huge TLB pages on Linux (MAP_HUGETLB)

From
Heikki Linnakangas
Date:
Allow using huge TLB pages on Linux (MAP_HUGETLB)

This patch adds an option, huge_tlb_pages, which allows requesting the
shared memory segment to be allocated using huge pages, by using the
MAP_HUGETLB flag in mmap(). This can improve performance.

The default is 'try', which means that we will attempt using huge pages,
and fall back to non-huge pages if it doesn't work. Currently, only Linux
has MAP_HUGETLB. On other platforms, the default 'try' behaves the same as
'off'.

In the passing, don't try to round the mmap() size to a multiple of
pagesize. mmap() doesn't require that, and there's no particular reason for
PostgreSQL to do that either. When using MAP_HUGETLB, however, round the
request size up to nearest 2MB boundary. This is to work around a bug in
some Linux kernel versions, but also to avoid wasting memory, because the
kernel will round the size up anyway.

Many people were involved in writing this patch, including Christian Kruse,
Richard Poole, Abhijit Menon-Sen, reviewed by Peter Geoghegan, Andres Freund
and me.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/1a3458b6d8d202715a83c88474a1b63726d0929e

Modified Files
--------------
doc/src/sgml/config.sgml                      |   37 +++++++
src/backend/port/sysv_shmem.c                 |  135 ++++++++++++++++++-------
src/backend/port/win32_shmem.c                |    5 +
src/backend/utils/misc/guc.c                  |   33 ++++++
src/backend/utils/misc/postgresql.conf.sample |    2 +
src/include/storage/pg_shmem.h                |   10 ++
6 files changed, 183 insertions(+), 39 deletions(-)


Re: pgsql: Allow using huge TLB pages on Linux (MAP_HUGETLB)

From
Peter Geoghegan
Date:
On Wed, Jan 29, 2014 at 4:12 AM, Heikki Linnakangas
<heikki.linnakangas@iki.fi> wrote:
> Allow using huge TLB pages on Linux (MAP_HUGETLB)

The documentation says:

+        Remember that you will need at least shared_buffers / huge page size +
+        1 huge TLB pages. So for example for a system with 6GB shared buffers
+        and a hugepage size of 2kb of you will need at least 3156 huge pages.

I think that this should say 2MiB rather than 2kb. Or 2M, if you prefer.

--
Peter Geoghegan


Re: pgsql: Allow using huge TLB pages on Linux (MAP_HUGETLB)

From
Christian Kruse
Date:
Hi,

On 29/01/14 11:17, Peter Geoghegan wrote:
> On Wed, Jan 29, 2014 at 4:12 AM, Heikki Linnakangas
> <heikki.linnakangas@iki.fi> wrote:
> > Allow using huge TLB pages on Linux (MAP_HUGETLB)
>
> The documentation says:
> […]

I rewrote the whole part. Giving such a formula is a bad idea since
shared buffers is not the only factor affecting the no of required
huge pages.

Best regards,

--
 Christian Kruse               http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services


Attachment