Linux: Creating a ramdisk with tmpfs and ramfs

From Define Wiki
Revision as of 12:43, 2 October 2014 by David (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

So tmpfs vs ramfs, in short tmpfs is newer and behaves like a filesystem and can be created on the fly (it will also swap under high usage), ramfs wont swap but you may hang your machine if you exhaust ram. Lots more details online: http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/

Setting up tmpfs

Easier than i expected!

 mkdir -p /ramdisk
 mount -t tmpfs -o size=8192m tmpfs /ramdisk

Setting up ramfs

Damn this is easy

mkdir /ramdisk
mount -r ramfs -o size=8192m ramfs /ramdisk

Performance tmpfs

  • Tests below on a haswell E5-2640v3 DDR4-1866Mhz with 8GB ramdisk tmpfs
  • Tests performed with FIO and DD
  • Achieved over 1m IOPS and 4GB bandwidth with 16 cores all running.

Bandwidth with dd

[david@haswell5 dp]$ dd if=/dev/zero of=./file.dd bs=4M count=1024
1024+0 records in
1024+0 records out
4294967296 bytes (4.3 GB) copied, 2.00559 s, 2.1 GB/s

IOPS / Bandwidth on tmpfs with FIO (using 1 job/thread)

david@haswell5 dp]$ cat iops.fio 
[random]
rw=randread
size=8000m
directory=/ramdisk/dp/
iodepth=32
blocksize=4k
numjobs=1
nrfiles=1
group_reporting
ioengine=sync
loops=1
[david@haswell5 dp]$ fio ./iops.fio 
random: (g=0): rw=randread, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=32
fio-2.0.13
Starting 1 process
random: Laying out IO file(s) (1 file(s) / 8000MB)
Jobs: 1 (f=1): [r] [83.3% done] [1897M/0K/0K /s] [486K/0 /0  iops] [eta 00m:01s]
random: (groupid=0, jobs=1): err= 0: pid=9674: Thu Oct  2 11:13:35 2014
  read : io=8000.0MB, bw=1628.2MB/s, iops=417023 , runt=  4911msec
    clat (usec): min=1 , max=26 , avg= 1.62, stdev= 0.55
     lat (usec): min=1 , max=26 , avg= 1.64, stdev= 0.54
    clat percentiles (usec):
     |  1.00th=[    1],  5.00th=[    1], 10.00th=[    1], 20.00th=[    1],
     | 30.00th=[    1], 40.00th=[    2], 50.00th=[    2], 60.00th=[    2],
     | 70.00th=[    2], 80.00th=[    2], 90.00th=[    2], 95.00th=[    2],
     | 99.00th=[    2], 99.50th=[    2], 99.90th=[    4], 99.95th=[    6],
     | 99.99th=[   12]
    bw (MB/s)  : min=    0, max= 2010, per=100.00%, avg=1724.23, stdev=647.28
    lat (usec) : 2=39.38%, 4=60.46%, 10=0.12%, 20=0.04%, 50=0.01%
  cpu          : usr=19.47%, sys=80.49%, ctx=498, majf=0, minf=24
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=2048000/w=0/d=0, short=r=0/w=0/d=0

Run status group 0 (all jobs):
   READ: io=8000.0MB, aggrb=1628.2MB/s, minb=1628.2MB/s, maxb=1628.2MB/s, mint=4911msec, maxt=4911msec

IOPS / BW with FIO (using 16 jobs/threads)

[david@haswell5 dp]$ cat iops.fio 
[random]
rw=randread
size=500m
directory=/ramdisk/dp/
iodepth=32
blocksize=4k
numjobs=16
nrfiles=1
group_reporting
ioengine=sync
loops=1
[david@haswell5 dp]$ fio ./iops.fio 
random: (g=0): rw=randread, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=32
...
random: (g=0): rw=randread, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=32
fio-2.0.13
Starting 16 processes
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
random: Laying out IO file(s) (1 file(s) / 500MB)
Jobs: 16 (f=16)
random: (groupid=0, jobs=16): err= 0: pid=9616: Thu Oct  2 11:11:20 2014
  read : io=7940.3MB, bw=4550.3MB/s, iops=1164.9K, runt=  1745msec
    clat (usec): min=0 , max=1463 , avg= 2.06, stdev= 2.17
     lat (usec): min=0 , max=1463 , avg= 2.09, stdev= 2.17
    clat percentiles (usec):
     |  1.00th=[    0],  5.00th=[    1], 10.00th=[    1], 20.00th=[    1],
     | 30.00th=[    1], 40.00th=[    1], 50.00th=[    1], 60.00th=[    1],
     | 70.00th=[    2], 80.00th=[    3], 90.00th=[    5], 95.00th=[    6],
     | 99.00th=[    9], 99.50th=[   10], 99.90th=[   13], 99.95th=[   15],
     | 99.99th=[   21]
    bw (KB/s)  : min=    3, max=    3, per=0.00%, avg= 3.00, stdev= 0.00
    lat (usec) : 2=63.58%, 4=16.42%, 10=19.43%, 20=0.56%, 50=0.01%
    lat (usec) : 100=0.01%, 250=0.01%
    lat (msec) : 2=0.01%
  cpu          : usr=3.68%, sys=95.18%, ctx=2966, majf=0, minf=398
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=2032697/w=0/d=0, short=r=0/w=0/d=0

Run status group 0 (all jobs):
   READ: io=7940.3MB, aggrb=4550.3MB/s, minb=4550.3MB/s, maxb=4550.3MB/s, mint=1745msec, maxt=1745msec

Extend the tmpfs

  mount -o remount,size=16g /ramdisk/