Solutions to no=12 Cannot allocate memory Problems

The problem is due to the UNIX.fork() process which is spawned by Runtime.exec(). When doing so, the LINUX/UNIX OS need to allocate soe head room in memory. If your system is heavily taxed by another large application, this might fail. In our case, we had a small monitoring app running on a AWS Instance for development purposes with a large JBoss AS and virtually no initial swap space.

The first thing to do is to activate overcommiting of system memory. This usually works for small programs which exit quickly such as ls, w or df -k.

If that doesn’t help and you’re not running in a production environment, you’ll want to increaase swap. As of Linux 2.6, you can add swap files instead of swap partitions by going through the following steps:

a) Login as the root user

b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
# dd if=/dev/zero of=/swapfile1 bs=1024 count=524288

c) Set up a Linux swap area:
# mkswap /swapfile1

d) Activate /swapfile1 swap space immediately:
# swapon /swapfile1

e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:
# vi /etc/fstab

Append following line:
/swapfile1 swap swap defaults 0 0

This entry was posted in Distributed Computing, Enterprise Java, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s