Child pages
  • Ramdisk Java
Skip to end of metadata
Go to start of metadata


Putting a JVM in a read only ramdisk file system improve the overall performance of Java on Ubuntu Linux.

It doesn't replace a SSD but rooming 200M of RAM to get some substantial performance is always welcome.

However there are some limitations with this technic:

  • tmpfs is swappable. Under heavy loaded machine our ramdisk could be transferred in a mechanical hard drive.
  • SquashFS is building a highly compressed file, reducing the IO and the size of the ramdisk. Not sure if an unsquashed JVM image would outperform a squashed image.


In order to put a JVM in a RAM disk we are going to use the tool SquashFS.

Use the following command to install the Squash FS tools.

sudo apt-get update
sudo apt-get install squashfs-tools

Make a squashfs file out of your desired JVM, use LZMA2 compression rather than gzip.

cd /usr/lib/jvm
sudo mkdir ramdisk
mksquashfs /usr/lib/jvm/java-8-oracle /usr/lib/jvm/ramdisk/java- -comp xz

At this point you have an existing JVM squashed in .sqsh file with a roughly size of 160M:

user@machine:/media$ ls --block-size=M -al /usr/lib/jvm/ramdisk/java- 
-rw-r--r-- 1 user users 160M May 12 15:53 /usr/lib/jvm/ramdisk/java-

Mount Point

Create a mountpoint for the ramdisk:

sudo mkdir /media/ramdisk-java-8-oracle

Edit your /etc/fstab, define your mount point as a tmpfs file system and run your squashed JVM against this mount point by adding the following declarations:

# define a tmps mount point for Java ramdisk
tmpfs /media/ramdisk-java-8-oracle tmpfs defaults,size=170M,mode=1777 0 0
# run a squashed JVM against our tmps mount point
/usr/lib/jvm/ramdisk/java- /media/ramdisk-java-8-oracle squashfs ro,defaults,loop 0 0


At this point you need to reboot to initialize the ramdisk with your Squashed JVM. Now you have to proceed with a standard JVM installation.

in the /usr/lib/jvm directory we define the default-java to point to a local symlink who will point to our ramdisk:

user@machine:/usr/lib/jvm$ ls -al
total 92
drwxr-xr-x 7 root root 4096 Jul 13 13:40 .
drwxr-xr-x 205 root root 53248 Jul 13 09:22 ..
lrwxrwxrwx 1 root root 34 Jul 7 15:33 default-java -> /usr/lib/jvm/ramdisk-java-8-oracle
lrwxrwxrwx 1 root root 28 Jul 13 12:15 .default-java.jinfo -> .ramdisk-java-8-oracle.jinfo
lrwxrwxrwx 1 root root 20 Jul 7 11:46 ramdisk-java-8-oracle -> /media/ramdisk-java-8-oracle
-rw-r--r-- 1 root root 3569 Jul 13 10:24 .ramdisk-java-8-oracle.jinfo

We create a .ramdisk-java-oracle.jinfo with a unique priority id:

jre ControlPanel /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/ControlPanel
jre java /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/java
jre javaws /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/javaws
jre jcontrol /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/jcontrol
jre jjs /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/jjs
jre keytool /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/keytool
jre orbd /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/orbd
jre pack200 /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/pack200
jre policytool /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/policytool
jre rmid /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/rmiregistry
jre servertool /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/servertool
jre tnameserv /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/tnameserv
jre unpack200 /usr/lib/jvm/ramdisk-java-8-oracle/jre/bin/unpack200
jre jexec /usr/lib/jvm/ramdisk-java-8-oracle/jre/lib/jexec
jdk appletviewer /usr/lib/jvm/ramdisk-java-8-oracle/bin/appletviewer
jdk extcheck /usr/lib/jvm/ramdisk-java-8-oracle/bin/extcheck
jdk idlj /usr/lib/jvm/ramdisk-java-8-oracle/bin/idlj
jdk jar /usr/lib/jvm/ramdisk-java-8-oracle/bin/jar
jdk jarsigner /usr/lib/jvm/ramdisk-java-8-oracle/bin/jarsigner
jdk javac /usr/lib/jvm/ramdisk-java-8-oracle/bin/javac
jdk javadoc /usr/lib/jvm/ramdisk-java-8-oracle/bin/javadoc
jdk javafxpackager /usr/lib/jvm/ramdisk-java-8-oracle/bin/javafxpackager
jdk javah /usr/lib/jvm/ramdisk-java-8-oracle/bin/javah
jdk javap /usr/lib/jvm/ramdisk-java-8-oracle/bin/javap
jdk javapackager /usr/lib/jvm/ramdisk-java-8-oracle/bin/javapackager
jdk jcmd /usr/lib/jvm/ramdisk-java-8-oracle/bin/jcmd
jdk jconsole /usr/lib/jvm/ramdisk-java-8-oracle/bin/jconsole
jdk jdb /usr/lib/jvm/ramdisk-java-8-oracle/bin/jdb
jdk jdeps /usr/lib/jvm/ramdisk-java-8-oracle/bin/jdeps
jdk jhat /usr/lib/jvm/ramdisk-java-8-oracle/bin/jhat
jdk jinfo /usr/lib/jvm/ramdisk-java-8-oracle/bin/jinfo
jdk jmap /usr/lib/jvm/ramdisk-java-8-oracle/bin/jmap
jdk jmc /usr/lib/jvm/ramdisk-java-8-oracle/bin/jmc
jdk jps /usr/lib/jvm/ramdisk-java-8-oracle/bin/jps
jdk jrunscript /usr/lib/jvm/ramdisk-java-8-oracle/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/ramdisk-java-8-oracle/bin/jsadebugd
jdk jstack /usr/lib/jvm/ramdisk-java-8-oracle/bin/jstack
jdk jstat /usr/lib/jvm/ramdisk-java-8-oracle/bin/jstat
jdk jstatd /usr/lib/jvm/ramdisk-java-8-oracle/bin/jstatd
jdk jvisualvm /usr/lib/jvm/ramdisk-java-8-oracle/bin/jvisualvm
jdk native2ascii /usr/lib/jvm/ramdisk-java-8-oracle/bin/native2ascii
jdk rmic /usr/lib/jvm/ramdisk-java-8-oracle/bin/rmic
jdk schemagen /usr/lib/jvm/ramdisk-java-8-oracle/bin/schemagen
jdk serialver /usr/lib/jvm/ramdisk-java-8-oracle/bin/serialver
jdk wsgen /usr/lib/jvm/ramdisk-java-8-oracle/bin/wsgen
jdk wsimport /usr/lib/jvm/ramdisk-java-8-oracle/bin/wsimport
jdk xjc /usr/lib/jvm/ramdisk-java-8-oracle/bin/xjc
#plugin /usr/lib/jvm/ramdisk-java-8-oracle/jre/lib/i386/
plugin /usr/lib/jvm/ramdisk-java-8-oracle/jre/lib/i386/
#plugin /usr/lib/jvm/ramdisk-java-8-oracle/jre/lib/i386/
#plugin /usr/lib/jvm/ramdisk-java-8-oracle/jre/lib/i386/
#plugin /usr/lib/jvm/ramdisk-java-8-oracle/jre/lib/i386/
#plugin /usr/lib/jvm/ramdisk-java-8-oracle/jre/lib/i386/
#plugin /usr/lib/jvm/ramdisk-java-8-oracle/jre/lib/i386/

Link the .default-java.jinfo with .ramdisk-java-oracle.jinfo.

Then we create a bunch of install and remove shell scripts to update-alternatives either the default-java and the ramdisk-java-8-oracle.

First we update-alternatives ramdisk-java-8-oracle then default-java and finally update-java-alternatives our default-java.

  • No labels