Tuesday, September 30, 2008

Fixing java disk swapping problem on linux

Running JDK 1.6 on my ubuntu hardy laptop I noticed hard disk drive light flashing every second. Disk activity was happening when running any java program, e.g. Eclipse, or Tomcat. I pinned this down to the JVM's performance files in the /tmp/hsperfdata directory. To turn off disk swapping, and prolong your battery and disk live, run JVM with the following option -XX:-UsePerfData

E.g. for Eclipse you may edit eclipse.ini and add this line at the end:
-XX:-UsePerfData

These were the steps I took to diagnose the issue:

# Become root
sudo su -

# Stop loggers
/etc/init.d/sysklogd stop
/etc/init.d/klogd stop

# Enable block I/O debugging
echo 1 > /proc/sys/vm/block_dump

# Monitor kernel ring buffer
while true; do dmesg -c; sleep 1; done;

...
Examine the output
...
[ 562.539286] java(10323): dirtied inode 8224835 (10310) on sda1
[ 562.539293] java(10323): dirtied inode 8224835 (10310) on sda1
[ 562.545651] eclipse(13917): dirtied inode 8224819 (13898) on sda1
[ 562.545658] eclipse(13917): dirtied inode 8224819 (13898) on sda1

# Find out filename from inode
find / -inum 8224819 2> /dev/null
/tmp/hsperfdata_dmitri/13898

# We're done
# Turn off block I/O debugging
echo 0 > /proc/sys/vm/block_dump

# Start loggers
/etc/init.d/sysklogd start
/etc/init.d/klogd start

No comments: