Re: Do work_mem and shared buffers have 1g or 2g limit on 64 bit linux? - Mailing list pgsql-performance

From Tomas Vondra
Subject Re: Do work_mem and shared buffers have 1g or 2g limit on 64 bit linux?
Date
Msg-id 557EE7F1.9000901@2ndquadrant.com
Whole thread Raw
In response to Re: Do work_mem and shared buffers have 1g or 2g limit on 64 bit linux?  (Kaijiang Chen <chenkaijiang@gmail.com>)
List pgsql-performance

On 06/15/15 05:44, Kaijiang Chen wrote:
> I've checked the source codes in postgresql 9.2.4. In function
> static bool
> grow_memtuples(Tuplesortstate *state)
>
> the codes:
>     /*
>      * On a 64-bit machine, allowedMem could be high enough to get us into
>      * trouble with MaxAllocSize, too.
>      */
>     if ((Size) (state->memtupsize * 2) >= MaxAllocSize / sizeof(SortTuple))
>         return false;
>
> Note that MaxAllocSize == 1GB - 1
> that means, at least for sorting, it uses at most 1GB work_mem! And
> setting larger work_mem has no use at all...

That's not true. This only limits the size of 'memtuples' array, which
only stores pointer to the actual tuple, and some additional data. The
tuple itself is not counted against MaxAllocSize directly. The SortTuple
structure has ~24B which means you can track 33M tuples in that array,
and the tuples may take a lot more space.

regards

--
Tomas Vondra                   http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


pgsql-performance by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Slow query: Postgres chooses nested loop over hash join, whery by hash join is much faster, wrong number of rows estimated
Next
From: "Sheena, Prabhjot"
Date:
Subject: PGBOUNCER ISSUE PLEASE HELP(Slowing down the site)