Default of max_stack_depth and getrlimit

Lists: pgsql-hackers
From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Default of max_stack_depth and getrlimit
Date: 2008-07-21 08:53:08
Message-ID: 48844E74.1060704@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

In 8.2, we started to use getrlimit(RLIMIT_STACK, ...) to set
max_stack_depth automatically, to a max of 2MB:

http://archives.postgresql.org/pgsql-hackers/2006-10/msg00389.php

However, it's not behaving as I expected when the stack limit is set to
"unlimited". I would expect max_stack_depth to be set to the max of 2MB,
but instead it gets set to 100kB.

I don't normally run without a limit, but it looks like the regression
tests run like that with "make check", at least on my platform. I bumped
into this while running a custom regression test with very deep nesting.

I think we should differentiate between "infinite" and "unknown" in the
return value of get_stack_depth_limit(), and use max_stack_depth of 2MB
in case of infinite, and fall back to the 100kB only in the unknown case.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
Cc: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Default of max_stack_depth and getrlimit
Date: 2008-07-21 15:02:37
Message-ID: 13554.1216652557@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Heikki Linnakangas" <heikki(at)enterprisedb(dot)com> writes:
> In 8.2, we started to use getrlimit(RLIMIT_STACK, ...) to set
> max_stack_depth automatically, to a max of 2MB:

> http://archives.postgresql.org/pgsql-hackers/2006-10/msg00389.php

> However, it's not behaving as I expected when the stack limit is set to
> "unlimited".

Is there really any such thing as "unlimited" stack depth? I think that
treating that as "unknown" is a good conservative thing to do, because
it is surely a lie.

regards, tom lane


From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "PostgreSQL-development" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Default of max_stack_depth and getrlimit
Date: 2008-07-21 15:23:39
Message-ID: 4884A9FB.7000505@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com> writes:
>> In 8.2, we started to use getrlimit(RLIMIT_STACK, ...) to set
>> max_stack_depth automatically, to a max of 2MB:
>
>> http://archives.postgresql.org/pgsql-hackers/2006-10/msg00389.php
>
>> However, it's not behaving as I expected when the stack limit is set to
>> "unlimited".
>
> Is there really any such thing as "unlimited" stack depth?

No, but I would think it's safe to assume that "unlimited" is greater
than 2MB.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Cédric Villemain <cedric(dot)villemain(at)dalibo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
Subject: Re: Default of max_stack_depth and getrlimit
Date: 2008-07-21 16:07:24
Message-ID: 200807211807.28526.cedric.villemain@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Le Monday 21 July 2008, Heikki Linnakangas a écrit :
> In 8.2, we started to use getrlimit(RLIMIT_STACK, ...) to set
> max_stack_depth automatically, to a max of 2MB:
>
> http://archives.postgresql.org/pgsql-hackers/2006-10/msg00389.php
>
> However, it's not behaving as I expected when the stack limit is set to
> "unlimited". I would expect max_stack_depth to be set to the max of 2MB,
> but instead it gets set to 100kB.
>
> I don't normally run without a limit, but it looks like the regression
> tests run like that with "make check", at least on my platform. I bumped
> into this while running a custom regression test with very deep nesting.
>
> I think we should differentiate between "infinite" and "unknown" in the
> return value of get_stack_depth_limit(), and use max_stack_depth of 2MB
> in case of infinite, and fall back to the 100kB only in the unknown case.

Why 2MB ? I believed that 3.5MB is the effective good maximum , is that too
much ?

>
> --
> Heikki Linnakangas
> EnterpriseDB http://www.enterprisedb.com

--
Cédric Villemain
Administrateur de Base de Données
Cel: +33 (0)6 74 15 56 53
http://dalibo.com - http://dalibo.org


From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: Cédric Villemain <cedric(dot)villemain(at)dalibo(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Default of max_stack_depth and getrlimit
Date: 2008-07-21 16:14:37
Message-ID: 4884B5ED.3010702@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Cédric Villemain wrote:
> Le Monday 21 July 2008, Heikki Linnakangas a écrit :
>> I think we should differentiate between "infinite" and "unknown" in the
>> return value of get_stack_depth_limit(), and use max_stack_depth of 2MB
>> in case of infinite, and fall back to the 100kB only in the unknown case.
>
> Why 2MB ? I believed that 3.5MB is the effective good maximum , is that too
> much ?

2MB is the value we set max_stack_depth to, unless getrlimit() says that
the actual stack limit is lower than that.

I believe the 2MB figure is just an arbitrary value, thought to be quite
safe, but also high enough that most people won't need to raise it.
Before we started to use getrlimit(), we used to just default
max_stack_depth=2MB.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Cédric Villemain <cedric(dot)villemain(at)dalibo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
Subject: Re: Default of max_stack_depth and getrlimit
Date: 2008-07-21 16:50:38
Message-ID: 200807211850.43686.cedric.villemain@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Le Monday 21 July 2008, Heikki Linnakangas a écrit :
> Cédric Villemain wrote:
> > Le Monday 21 July 2008, Heikki Linnakangas a écrit :
> >> I think we should differentiate between "infinite" and "unknown" in the
> >> return value of get_stack_depth_limit(), and use max_stack_depth of 2MB
> >> in case of infinite, and fall back to the 100kB only in the unknown
> >> case.
> >
> > Why 2MB ? I believed that 3.5MB is the effective good maximum , is that
> > too much ?
>
> 2MB is the value we set max_stack_depth to, unless getrlimit() says that
> the actual stack limit is lower than that.
>
> I believe the 2MB figure is just an arbitrary value, thought to be quite
> safe, but also high enough that most people won't need to raise it.
> Before we started to use getrlimit(), we used to just default
> max_stack_depth=2MB.

Ok, thank you for the explanation.

>
> --
> Heikki Linnakangas
> EnterpriseDB http://www.enterprisedb.com

--
Cédric Villemain
Administrateur de Base de Données
Cel: +33 (0)6 74 15 56 53
http://dalibo.com - http://dalibo.org