-
-
Notifications
You must be signed in to change notification settings - Fork 422
Set stack size explicitly if pthread_create fails #1340
Conversation
|
LGTM. |
|
Looks like a hack for a resource problem. |
|
You can already explicitly set the stack size when creating a Thread object. Silently changing that to 16KB is a bad idea and might easily cause a stack overflow later on. |
|
@MartinNowak I looked more into it and it's the stack size that's too big. Trying smaller sizes (yet greater than One possibility is to try a divide by 2 decay, i.e. if 8 MB (the default) doesn't work, try 4MB, then 2MB, etc. I'll do that in the next iteration of this diff. |
|
@MartinNowak My VM has 4GB of RAM. Things fail even if I set it to 6 GB. |
|
alright here we go |
|
As much as I admire this binary decay (clever), it doesn't make sense that this would work. I would expect at most you could make one more thread (when resources are tight, and they really shouldn't be with 4GB of RAM). And you will get possibly random out of stack errors depending on which thread got the short end of the RAM stick. I still feel like something strange is going on with your setup. |
|
@schveiguy I hear you, but there's no action item. The simple thing is, I have a problem and this fixes it. My VM setup is as vanilla as they come. FWIW 8MB is a large stack, most threads only use a few kb. It's a bit of a bummer that that's the default on 32 bits etc. etc. |
I suspect you're running into artificial limits, not actually exhausting resources.
Those will segfault. |
|
I'm not confortable with this change either. For starters, I doubt any user of a system programming language will expect the runtime to give it a stack smaller than what was asked for. If the stack size is the default one, that behavior might be okay, but it can also create hard to reproduce bug and I'm not sure that's where your actual issue lies.
You'll run out of virtual memory at around 3+ GBs, so that's < 0.3% of the virtual memory. Whenever that's disproportionate or not, having a default that's different from pthread's default is also confusing.
It won't make any difference, since the memory isn't adressable by the process anyway. |
@Geod24 I don't get the action item. This is a solution to a problem in a context. What alternative do you propose?
This only kicks in if no specific stack size was asked for. |
That's not how it's written. If In any case, my worry here is that on run 1, thread A gets a small stack size as compared to other threads, runs fine. On run 2, thread B gets a small stack size, but needs more. Of course, one could say the alternative is that one thread doesn't run at all, which is a hard error. But at least you (should) see that happening, and it won't reach production. Can we make this opt-in? So for instance, if you set the stack size to size_t.max, it uses the default, and then does the binary decay? |
|
How many threads are you creating? Is it RLIMIT_NPROC you're actually hitting? |
Ah, it's the phobos tests. Why would you run out of resources for thread creation during phobos tests? |
|
@MartinNowak The unittest is creating 100 threads, see https://github.com/andralex/phobos/blob/allocator/std/experimental/allocator/building_blocks/free_list.d#L1018. With a default stack size of 8MB per thread, we're looking at 800MB, which is quite a strain in a 32-bit app. I'll reduce that number to 20 and close this. |
Took me a while! I am testing 32-bit Phobos on Ubuntu64 running on VMWare hosted under OSX. Only in the 32-bit build,
pthread_createwould fail with the EAGAIN error code. It turns out, if thread stack size is explicitly set then it works.