Re: can we optimize STACK_DEPTH_SLOP

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Stark <stark(at)mit(dot)edu>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: can we optimize STACK_DEPTH_SLOP
Date: 2016-07-08 03:46:27
Message-ID: 17417.1467949587@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> Based on these numbers, I'd have no fear of reducing STACK_DEPTH_SLOP
> to 256KB on x86_64. It would sure be good to check things on some
> other architectures, though ...

I went to the work of doing the same test on a PPC Mac:

182 Stack [ 8192K/ 40K]
25 Stack [ 8192K/ 48K]
2 Stack [ 8192K/ 56K]
11 Stack [ 8192K/ 60K]
5 Stack [ 8192K/ 64K]
2 Stack [ 8192K/ 108K]
1 Stack [ 8192K/ 576K]
1 Stack [ 8192K/ 2056K]

The last number here is "resident pages", not "dirty pages", because
this older version of OS X doesn't provide the latter. Still, the
numbers seem to track pretty well with the ones I got on x86_64.
Which is a bit odd when you think about it: a 32-bit machine ought
to consume less stack space because pointers are narrower.

Also on my old HPPA dinosaur:

40 addr 0x7b03a000, length 8, physical pages 8, type STACK
166 addr 0x7b03a000, length 10, physical pages 9, type STACK
26 addr 0x7b03a000, length 12, physical pages 11, type STACK
16 addr 0x7b03a000, length 14, physical pages 13, type STACK
1 addr 0x7b03a000, length 15, physical pages 13, type STACK
1 addr 0x7b03a000, length 16, physical pages 15, type STACK
2 addr 0x7b03a000, length 28, physical pages 27, type STACK
1 addr 0x7b03a000, length 190, physical pages 190, type STACK
1 addr 0x7b03a000, length 514, physical pages 514, type STACK

As best I can tell, "length" is the nominal virtual space for the stack,
and "physical pages" is the actually allocated/resident space, both
measured in 4K pages. So that again matches pretty well, although the
stack-efficiency of the recursive regex functions seems to get worse with
each new case I look at.

However ... the thread here
https://www.postgresql.org/message-id/flat/21563.1289064886%40sss.pgh.pa.us
says that depending on your choice of compiler and optimization level,
IA64 can be 4x to 5x worse for stack space than x86_64, even after
spotting it double the memory allocation to handle its two separate
stacks. I don't currently have access to an IA64 machine to check.

Based on what I'm seeing so far, really 100K ought to be more than plenty
of slop for most architectures, but I'm afraid to go there for IA64.

Also, there might be some more places like tzload() that are putting
unreasonably large variables on the stack, but that the regression tests
don't exercise (I've not tested anything replication-related, for
example).

Bottom line: I propose that we keep STACK_DEPTH_SLOP at 512K for IA64
but reduce it to 256K for everything else.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2016-07-08 04:01:10 Re: \timing interval
Previous Message Alvaro Herrera 2016-07-08 03:18:24 Re: A Modest Upgrade Proposal