-   Linux - Server (
-   -   bash: fork: retry: Resource temporarily unavailable - Limit issue? (

miketwenty1 11-23-2017 08:19 PM

bash: fork: retry: Resource temporarily unavailable - Limit issue?
I've looked through the other posts and feel like this question has been answered and doesn't apply to my situation or was asked and the thread has gone stale.

Ubuntu OS 16.04. Running Java Process.

java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

(not that it matters because I'm running into other limit issues I believe. Doesn't look like anything to do with java HEAP Xms Xmx Xss type stuff. )

I'm running a process that uses many threads i want 10,000's of threads potentially.
My process stops making threads around 12,000, I'm very confused about this. (the same exact number every time)

When it ramps up to ~12,000 threads I will also have issues running commands in the shell

my normal user: (while process is running)

-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: Resource temporarily unavailable

as root: (while process is running)

-bash: fork: retry: No child processes
(so makes me think this is a system wide thing? not a specific user issue? since both root and my normal user have shell issues)

Here's some information which might be able to help. I'm confused on what limit I'm hitting exactly.


`free -m`
              total        used        free      shared  buff/cache  available
Mem:          60395        306      59195          8        892      59349
Swap:            0          0          0


`ulimit -a`
core file size          (blocks, -c) 0
data seg size          (kbytes, -d) unlimited
scheduling priority            (-e) 0
file size              (blocks, -f) unlimited
pending signals                (-i) 241522
max locked memory      (kbytes, -l) unlimited
max memory size        (kbytes, -m) unlimited
open files                      (-n) 500000
pipe size            (512 bytes, -p) 8
POSIX message queues    (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 256
cpu time              (seconds, -t) unlimited
max user processes              (-u) 1000000
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

(I've messed with stack size making it 600,000 to 256 doesn't seem to affect anything)


`sysctl kernel.pid_max`
kernel.pid_max = 4194303


`cat /proc/sys/kernel/threads-max`


`cat /proc/sys/fs/file-nr`
832        0        6168013


ps -T -p <pid>
(will give me how many threads are being used which stops around 12000)

I don't see anything interesting in /var/log/syslog

So, what the heck is going on exactly. What limit am I hitting? I don't feel like I'm hitting a process count limit as the ulimit -a results show the limit is very high.. the thread max count is very high. Feeling a little confused here.

Tried this java application out on multiple cloud hardware configurations.. all yielding the same result. from 1cpu - 6gb of ram to 16cpu - 60gb of ram and several hardware configs in between.

Figured out the issue

/etc/systemd/logind.conf UserTasksMax needs to be set higher than ~12000
Not sure how this is read in, but a reboot of the server activated this number

I think it's also worth noting that
Could probably be limitations if I was trying to go much higher with thread count, and these might be my next limiters if I decided to go bigger with thread count.

Instead of rebooting you can do these commands

sudo systemctl daemon-reload
sudo systemctl daemon-reexec
sudo service systemd-logind restart

Then restart your shell or.. exit.. and ssh back in

ondoho 11-25-2017 03:32 AM

thanks for posting your solution.
if you edit your post, it will not show up as a new post in other member's feeds, and it can also seriously disrupt the flow of communication.
it would've been better to post the solution as a separate post/reply.
that way your thread also loses zero reply status.

All times are GMT -5. The time now is 11:22 AM.