How to speed up compilation times in Linux / CentOS / RHEL / Fedora using Ramdisk, much faster than SSD / SAS

By Turjo, Gaea News Network
Friday, December 17, 2010

Compilation time is the time required by a compiler to successfully transform source code written in a programming language into an executable program. The time taken for compilation depends mainly on two important things- CPU speed i.e processor speed and the harddisk speed. Most of us are concerned about only the CPU speed performance and often neglect the hard disk speed. That’s why perhaps, although there is dramatical improvement in terms of CPU or processor speed, the hard disk speed performance is still neglected by the manufacturers.

But, if you use Ramdisk, it will surely reduce your compilation time for Linux/Fedora/CentOS/RHEL.

A Ramdisk is a portion of RAM which is being used just like a physical drive. Ram disks have fixed sizes, and act like regular disk partitions. However, any data stored on a RAM disk is lost when the system is shut down or powered off. Hence, Ram disks can be a great place to store temporary data which needs to be accessed frequently. For example, web images or downloadable files, etc. are some of the best candidates to store in the Ram Disk.

The benefit of using RAMDISk is that, reads and writes ot the RAMDISK would be extremely fast, since everything is in RAM and not on the DISK.

In Linux Kernel 2.4 or later, RedHat/Fedora creates 16MB RAMDISKS by default. You can check if ram disk is setup by doing:

# dmesg | grep RAMDISK
RAMDISK driver initialized: 16 RAM disks of 16384K size 1024 blocksize

The same output should be obtained for CentOS, RHEL and any other linux flavors.

To check out how they are named and what you would need to refer to, do the following:

# ls -l /dev/ram*
lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ram -> ram1
brw-rw—- 1 root disk 1, 0 Apr 24 12:05 /dev/ram0
brw-rw—- 1 root disk 1, 1 Apr 24 12:05 /dev/ram1
brw-rw—- 1 root disk 1, 10 Apr 24 12:05 /dev/ram10
brw-rw—- 1 root disk 1, 11 Apr 24 12:05 /dev/ram11
brw-rw—- 1 root disk 1, 12 Apr 24 12:05 /dev/ram12
brw-rw—- 1 root disk 1, 13 Apr 24 12:05 /dev/ram13
brw-rw—- 1 root disk 1, 14 Apr 24 12:05 /dev/ram14
brw-rw—- 1 root disk 1, 15 Apr 24 12:05 /dev/ram15
brw-rw—- 1 root disk 1, 2 Apr 24 12:05 /dev/ram2
brw-rw—- 1 root disk 1, 3 Apr 24 12:05 /dev/ram3
brw-rw—- 1 root disk 1, 4 Apr 24 12:05 /dev/ram4
brw-rw—- 1 root disk 1, 5 Apr 24 12:05 /dev/ram5
brw-rw—- 1 root disk 1, 6 Apr 24 12:05 /dev/ram6
brw-rw—- 1 root disk 1, 7 Apr 24 12:05 /dev/ram7
brw-rw—- 1 root disk 1, 8 Apr 24 12:05 /dev/ram8
brw-rw—- 1 root disk 1, 9 Apr 24 12:05 /dev/ram9
lrwxrwxrwx 1 root root 4 Apr 24 12:05 /dev/ramdisk -> ram0

To list available RAM disks use the command - ls -lh /dev/ram*.
To know default size of RAM disk use - dmesg | grep RAMDISK

To create a larger RAMDISK space, you have to configure hte kernel parameter by passing the size of the RAMDISK as a parameter during booting of the kernel.

The kernel option for RAMDISK size is: ramdisk_size=<size in kb>.

Now, all you have to do is to type the above line at the boot prompt during booting. Or if you are using some boot loader like lilo or grub, you need to change the boot command in either lilo.conf or grub.conf. For example in grub.conf you would be having something like :

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,4)
# kernel /boot/vmlinuz-version ro root=/dev/hda5
# initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=5
splashimage=(hd0,4)/boot/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.11-1.1369_FC4)
root (hd0,4)
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/1 ramdisk_size=512000 quiet
initrd /boot/initrd-2.6.11-1.1369_FC4.img
title Windoze XP
rootnoverify (hd0,1)
chainloader +1

The above configuration will create a RAMDISK of size 512MB. There is an upper limit to the max size of RAMDISK that can be created and it is also controlled by the amount of available RAM. So if you have 512MB of RAM, you would not be able to create RAMDISKS of more than 512MB. But depending on the kernel configuration, if you have a 4GB RAM system, you may not be able to create RAMDISK of more than 1GB maybe. You will have to check this limit either with the kernel documents or by trying out different sizes at boot prompt.

Once the RAMDISK size has been configured, all that needs to be done is to create a file system on the RAMDISK and then mount the RAMDISK as a file system directory in linux.

To create an ext2fs file system, the following command is used :

mke2fs -m 0 /dev/ram0
The -m 0 option keeps mke2fs from reserving any space on the file system for the root user. This makes the complete ramdisk space available to any regular user.

To mount the ramdisk :


mkdir /mnt/RAMDISK
mount /dev/ram0 /mnt/RAMDISK

Now RAMDISK can used as a regular directory. You can read, write, delete and modify files on the RAMDISK as if you are working on a regular hard disk. Linux would handle it as if it were handling a regular directory on the disk. The difference between RAMDISK and normal DISK would be invisible to a regular user.

One thing has to be kept in the mind that, everything you put on this drive will be gone if you reboot your server. If you unmounted the Ramdisk drive and remounted it, your files will still be there. It is because your system has that much ram set aside for your Ramdisk and will not use it for anything else. If you would like to setup Ramdisk the same next time you boot up, add these lines to your /etc/rc.local files.

mke2fs -m 0 /dev/ram0
mount /dev/ram0 /home/ramdisk
chown sunny.sunny /home/ramdisk

To prevent loss of data, it is advisable to keep a backup of data in RAMDISK on the local HDD.

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :