Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZMkbt-0007tK-Sf for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Aug 2015 22:23:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZMkbt-00042W-DU for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Aug 2015 22:23:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZMkbH-0003L2-1h for pgsql-bugs@postgresql.org; Tue, 04 Aug 2015 22:22:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZMkbD-00056H-Qt for pgsql-bugs@postgresql.org; Tue, 04 Aug 2015 22:22:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t74MMH4K003507; Tue, 4 Aug 2015 18:22:17 -0400 From: Tom Lane To: brent_despain@selinc.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13530: sort receives "unexpected out-of-memory situation during sort" In-reply-to: <15011.1438717384@sss.pgh.pa.us> References: <20150731220618.2987.1731@wrigleys.postgresql.org> <20722.1438402315@sss.pgh.pa.us> <6977.1438451753@sss.pgh.pa.us> <15011.1438717384@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 04 Aug 2015 15:43:04 -0400" Date: Tue, 04 Aug 2015 18:22:17 -0400 Message-ID: <3506.1438726937@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs