[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C stack size
- From: Andrew Gierth <andrew@...>
- Date: Mon, 03 Jun 2019 16:32:05 +0100
>>>>> "Roberto" == Roberto Ierusalimschy <roberto@inf.puc-rio.br> writes:
Roberto> As already discussed, Lua 5.4 is using a "non stackless"
Roberto> implementation. [...]
Roberto> If you could run this test in your machine, that would be
Roberto> helpful. It would be even more helpful if you could play with
Roberto> the constant LUAI_MAXCSTACK and find its maximum value that
Roberto> the test does not crash. (You can change LUAI_MAXCSTACK in
Roberto> luaconf.h or define it with a compiler option.)
I think the question "does it crash" is not the important one. The
question that someone needs to know when embedding the interpreter is
"what is the maximum stack space it can use without letting me check the
stack usage". Also, as an embeddable language, if there's going to be a
stack limit, it should be one which is _much smaller_ than the
platform's default or commonly-used limit.
Furthermore, "just compile it with a smaller limit" is NOT a good
response, since it blocks any attempt to have a system-wide shared
library used by many programs.
(My opinion, biased as it is, is that the default limit should be such
that the stack usage does not exceed 500kbytes. The current limit is
very close to that, except on clang on i386 where it's just over 2x too
large.)
What I've been testing with is actually instrumenting the stack depth
error to report the approximate bytes of stack used.
My major results:
1. Without compiler optimization the stack usage grows by a large
multiple (more than 10 times in some cases) presumably because of the
use of un-eliminated and un-reused stack-based temporaries in place of
register allocation.
2. Clang (8.0) uses somewhat more stack space than gcc does, on amd64.
3. Clang (8.0) uses significantly more stack space than gcc does on
i386.
4. i386 uses more stack space than amd64 on either compiler.
5. Disabling jumptables reduces stack usage a bit.
The following values are approximate bytes of stack usage at the point
of error, with the default limit of 2200, from executing the string
'local function f() f() end f()'.
with optimization:
#compiler,jumptables, i386-O2 amd64-O2
gcc8 jumptables 523913 488985
gcc8 nojumptables 349593 349529
clang80 jumptables 1290705 523913
clang80 nojumptables 1238409 454185
without optimization:
#compiler,jumptables, i386-O0 amd64-O0
gcc8 jumptables 4254497 6033001
gcc8 nojumptables 4149905 5893545
clang80 jumptables 5684277 6869813
clang80 nojumptables 5684277 6869813
--
Andrew.