[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT and coroutines
- From: Mike Pall <mikelu-0604@...>
- Date: Sat, 29 Apr 2006 14:57:14 +0200
Hi,
Adrian Sietsma wrote:
> >>You need to use a STACKSIZE statement in the .def file.
>
> I see coco setting the stack size in CreateFiber; I assume I could change
> COCO_DEFAULT_CSTACKSIZE, if I just wanted to change CoCo ?
> And also as a runtime param to coroutine.create() I see.
Yes, but this only changes the committed amount on Windows. These
parameters do not allow you to reduce the reserved address space
below STACKSIZE.
> Adrian (having RTFM).
But not the MS docs about 'committed' and 'reserved' memory.
You are usually out of the latter. So you really need to change
the STACKSIZE definition.
Short explanation: Windows reserves a contiguous block of address
space for each Fiber (or Thread) stack. A part of it is committed
and will be allocated from physical RAM or the page file. The
committed amount will auto increase up to the reserved amount
when the non-committed stack pages are accessed.
If the reserved size is large enough (default is 1 MB) and you
create enough Fibers, then you will run out of address space long
before you run out of physical RAM or page file space. Simply
because there is a 4 GB address space limit on a 32 bit CPU.
Note that this is a peculiarity of Windows memory management. On
Linux and most other systems the stack size parameters to
coroutine.create, coroutine.wrap and coroutine.cstacksize
actually determine the number of allocated PTEs ('reserved'
memory). The used PTEs ('committed' memory) are automatically
determined by the kernel and default to one page (4K on x86).
The default stack sizes are much lower for non-Windows systems.
The latest version of Coco/LuaJIT uses 60K (minimum: 36K).
Bye,
Mike