Being a newbie in working with amazon ec2, I am trying to make my application work. I've connecting a few times by ssh, I've been running and stopping the server, sometimes the connection was lost, and some other things...

At some point I got the error from JVM (my application uses Scala) that there was not enough free memory and it couldn't allocate it to run itself. What I did was rebooting the server. It worked. But I figure there should be more effective way(s). Are there any?


Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5550000, 715849728, 0) failed; error='Cannot allocate memory' (errno=12)
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 715849728 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/ubuntu/my-app/hs_err_pid8668.log
  • Can you post the exact error? It's not clear what kind of memory shortage was involved? Also, the output of system memory status commands (like free and top), performed while you're having the problem, would be very helpful. – David Schwartz Mar 16 '14 at 3:53
  • @DavidSchwartz, what important is not the exact error but the fact that there is no enough memory which means there are, for example, some unused file descriptors open and all these kind of things. Let me check "free" and "top", they may help me. – アレックス Mar 16 '14 at 4:12
  • Without the exact error, how do we know if it's talking about virtual memory or physical memory? Process memory (like is set by ulimit) or system memory (available to all processes)? And so on. – David Schwartz Mar 16 '14 at 4:13
  • @DavidSchwartz, we'll have to wait until it'll appear again then because I don't remember the exact text. But if I recall correctly, this the same of those ones stackoverflow.com/questions/20157775/… and stackoverflow.com/questions/18078859/… – アレックス Mar 16 '14 at 4:23
  • @DavidSchwartz, I updated the question. – アレックス Mar 17 '14 at 10:39

I'd look at two changes:

  • I'm pretty sure you need to tune the memory usage of your JVM (with, to start, -Xmx) to match the machine you're on. Make sure you're not asking for way more memory than your VM has.
  • Frob your overcommit settings. A talk from Re:invent 2013 suggests overcommit_memory=2 and overcommit_ratio=80. Getting into a bad place with overcommit will cause malloc to fail like you're seeing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.