Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2012-11-07
07:54 • Ticket [3584573fff] cannot set thread stack size on linux status still Open ... artifact: dad0175e59 user: dvrsn
2012-11-06
23:01 • Ticket [3584573fff]: 4 changes artifact: 8b7f47612e user: ferrieux
00:50 • New ticket [3584573fff]. artifact: 1433b5c35e user: dvrsn

cannot set thread stack size on linux

Open3584573fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2012-11-06 00:50:29
ecent versions of Linux support pthread_attr_setstacksize, but HAVE_PTHREAD_ATTR_SETSTACKSIZE is not defined for linux.  As a result, no stack size requests are handed in Tcl_CreateThread, meaning the default is always used.  On linux the default stack size is the maximum possible stack size (i.e., the RLIMIT_STACK soft limit at program start time), which is typically 8Mb.

Even if stack size setting was enabled for linux, the notifier thread is created with the default size, and this is not changeable, meaning every threaded tclsh has minimum 8Mb overhead, even if no application threads are used.
ferrieuxplain2012-11-06 23:01:46
While the suggestion to allow this setting is obviously valid, please notice that on Linux systems this "8Mb overhead" only costs in virtual address space, not real RAM, thanks to overcommit. To verify this, let's look at a 8.6HEAD threaded build on Linux 32b:

Notifier thread stack segment as seen in pmap: 10MB

   b6e93000  10248K rw---    [ anon ]

Real usage as seen in /proc/PID/smaps: only 16kB

b6e93000-b7895000 rw-p 00000000 00:00 0 
Size:              10248 kB
Rss:                  16 kB
Pss:                  16 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:        16 kB
Referenced:           16 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
dvrsnplain2012-11-07 07:54:19
This does limit the number of threads that can be created on a 32-bit system to a much smaller number (around 365 on my machine) than would otherwise be the case.

It's possible to adjust the overcommit behavior, although I doubt doing so is very common.

It also may be the case (I wasn't able to find a definitive answer one way or the other) that in some virtualized environments (e.g., OpenVZ) the OOM killer looks at allocated rather than used pages.  This could lead to threaded apps being unfairly targeted.
Log in (anonymous is fine) to add a comment.