Friday, February 2, 2018

Creating a RAM Disk on CentOS 6

tmpfs vs. ramfs

The two main RAM based file system types in Linux are tmpfs and ramfs. ramfs is the older file system type and is largely replaced in most scenarios by tmpfs.

ramfs
file systems cannot be limited in size like a disk base file system which is limited by it’s capacity. ramfs will continue using memory storage until the system runs out of RAM and likely crashes


tmpfs
Is a more recent RAM file system which overcomes many of the drawbacks with ramfs. You can specify a size limit in tmpfs which will give a ‘disk full’ error when the limit is reached.

There are many reasons to create a RAM Disk. One reason is to have a isolated latency test or throughput test between interconnect, but discounting the effects of the spinning disk I/O that might be the bottleneck to the test.

Step 1: Check how much RAM you have. Display it in GB

# free -g
[root@~]# free -g
             total       used       free     shared    buffers     cached
Mem:            94         92          1          0          0         67
-/+ buffers/cache:         24         69 
Swap:            1          0          1 
You can also display with -m (MB) or -k (KB)

Step 2: Create and Mount a RAM Disk
# mkdir /mnt/ramdisk
# mount -t tmpfs -o size=40g tmpfs /mnt/ramdisk

Step 3: If you wish to create automatic mount, do place it at /etc/fstab


tmpfs       /mnt/ramdisk tmpfs   nodev,nosuid,noexec,nodiratime,size=40g   0 0  
[root@ ~]# dd if=/dev/zero of=/mdsdata/ramdisk/test bs=1G count=50
dd: writing `/mdsdata/ramdisk/test': No space left on device
41+0 records in
40+0 records out
42949672960 bytes (43 GB) copied, 44.5053 s, 965 MB/s
Above if you try to create bigger file the ramdisk the it will fail. So we can limit size.

No comments: