Re: BUG #13530: sort receives "unexpected out-of-memory situation during sort"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: brent_despain(at)selinc(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13530: sort receives "unexpected out-of-memory situation during sort"
Date: 2015-08-04 22:22:17
Message-ID: 3506.1438726937@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I wrote:
> But in tuplestore.c, the array elements are just "void *". On a 32-bit
> machine that's small enough that the very first allocation is a standard
> palloc chunk not a separate chunk. So then the allocation overhead *does*
> increase at the first enlargement, and if you're close to exhausting
> work_mem then LACKMEM can happen due to that. The new code that made
> sorting run closer to full memory utilization may have increased the odds
> of this, but it did not create the problem.

> So you need both a 32-bit machine and fairly small work_mem to trigger
> this failure; that explains why I could not reproduce it here (I was
> using a 64-bit machine).

Actually that's not true; the problem can happen on 64-bit as well.
I was thinking that the behavior change occurred at 8K allocation
requests, but actually it happens for requests larger than 8K.

> I think the best fix really is to increase the initial array size
> so that it's at least large enough to force palloc to do what we want.
> As a quick hack you could just s/1024/2048/ in tuplestore_begin_common,
> but what would be more maintainable in the long run is for the memory
> allocation code to export a #define for its "large chunk" threshold,
> and make the initial allocation here depend on that.

If you want to use the "official" patch for this, see
http://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=8bd45a394958c3fd7400654439ef2a113043f8f5

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2015-08-05 00:19:34 Re: BUG #13533: jsonb_populate_record does not work when the value is a simple string
Previous Message Tom Lane 2015-08-04 19:43:04 Re: BUG #13530: sort receives "unexpected out-of-memory situation during sort"