16
June
2022
Creating a RAM disk in Linux to speed up Mozilla Firefox
17:01

Creating a RAM disk in Linux to speed up Mozilla Firefox

16 June 2022 17:01

At home I have a computer without an SSD drive, but with a lot of random access memory (RAM). I came up with a way to speed up the work - you need to use a RAM disk in Linux!

Creating a RAM Disk in Linux

Unlike Windows, no third party programs are required.

1) First of all, let’s create a subdirectory in the TMP folder, which we’ll call ramdisk:

sudo mkdir /tmp/ramdisk

2) Give full rights to all users to read, change, execute:

sudo chmod 777 /tmp/ramdisk

3) Let's check how much free memory is available

free -h

In my case, I will allocate 1GB of RAM.

4) Create a RAM disk, size 1024m, file system type tmpfs, device name ramdisk, to the path /tmp/ramdisk:

sudo mount -o size=1024m -t tmpfs ramdisk /tmp/ramdisk

Configuring Mozilla Firefox to use RAM disk

We configure Firefox so that it uses our ramdisk to store temporary files (cache) on disk:

  • launch Firefox

1) Enter in the address bar about:config and press the Enter key

We agree that we understand the risk and continue.

2) Add a string parameter

browser.cache.disk.parent_directory

and confirm with the Enter key.

Click [+] we add a value to it - our temporary directory in RAM:

/tmp/ramdisk

We complete the assignment of the value with the Enter key.

3) Restart the browser.

We evaluate how the speed of work has increased. If you go to the /tmp/ramdisk folder, you can see that the browser has created temporary files in it - it uses the cache, but not on the disk, but in RAM.

Creating a permanent RAM disk using the /etc/fstab file

In order for the RAM disk to be created when the OS boots, you need to edit the system file /etc/fstab

At the end of which I added the lines:

Entry for RAM disk

ramdisk           /tmp    tmpfs   defaults       0       0

where:
ramdisk- parameter No. 1 -device name
/tmp- parameter No. 2,file system mount point
tmfs- parameter No. 3,file system type - tmpfs
defaults- parameter No. 4, value defaults, which replaces the list of options: rw, suid, dev, exec, auto, nouser, async and relatime.
I did not specify the size size=4g in order to speed up the OS at the same time as Mozilla Firefox - the /tmp/ mount point for temporary files.
0- parameter No. 5, do not use for the backup utility
0- parameter No. 6, do not use for the fsck disk check option

If desired, the size of the RAM disk can be limited, instead defaults indicate defaults,size=4g

Result of the mount command:

  • with a disk size limit of 4GB:
    result 4G

  • RAM disk without restrictions:
    realtime

Speed comparison

Regular HDD

*Write speed

cd ~
sync; dd if=/dev/zero of=tempfile bs=1M count=1024; sync

1024+0 records received
1024+0 entries sent
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 10.4092 s, 103 MB/s

  • Reading speed

    sudo sh -c "sync && echo 3 > /proc/sys/vm/drop_caches"
    sync; dd if=~/tempfile of=/dev/null bs=100k; sync

10485+1 records received
10485+1 entries sent
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 7.24557 s, 148 MB/s

RAM disk

*Writing speed:
cd /tmp/ramdisk
sync; dd if=/dev/zero of=tempfile bs=1M count=1024; sync

1024+0 records received
1024+0 entries sent
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.32374 s, 811 MB/s

8 times faster writing to RAM.
dd if=./tempfile of=/dev/null bs=4k

  • Reading speed:
    sudo sh -c "sync && echo 3 > /proc/sys/vm/drop_caches"
    dd if=./tempfile of=/dev/null bs=100k

0485+1 records received
10485+1 entries sent
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.347437 s, 3.1 GB/s

On my PC, the writing speed to RAM is 811/103=8 times higher, the reading speed from RAM is 3100/103=30 times higher! On server motherboards with multi-channel memory and fast DDR4 RAM modules, the benefits from using a RAM disk should be even more significant.

The test used a WDC WD5000AZLX-2 hard drive, RAM 2 DIMM DDR3 1333 MHz (0.8 ns), product: R53 8G 1601S2S on the BIOSTAR Group J1800NH3 motherboard.

The advantage of storing the Mozilla Firefox cache on a RAM disk is that the browser cache is automatically cleared after the PC is turned off.


Links:

How to change the default cache folder for firefox?- Mozilla Support
How to Easily Create RAM Disk on Debian, Ubuntu, Linux Mint, CentOS-

LinuxBabe.
How to measure hard drive speed- serveradmin.ru
Using tmpfs to speed up the OS a little- the-bosha.ru
*Testing read/write speed for devices...- rus-linux.net



Related publications