1

I testing writing data to a RAM drive on my linux machine, and I'm seeing much lower numbers than the RAM speed would suggest. So I would like to ask: why am I seeing slower speeds? Could be that I'm misunderstanding the speed rating, or how RAM drives work, or maybe there is a bottleneck somewhere else. This particular test isn't super important, but understanding the unexpected results here will help me get a better idea of which system resources will bottleneck which operations in the future.

For the test, I mounted a RAM drive, then gave the system two seconds to write as many zeroes to that disk as possible:

mkdir ramdisk
mount -t tmpfs -o size=16G tmpfs ramdisk
timeout 2s bash -c "cat /dev/zero > ramdisk/testfile"

I end up with a file that's about 11 GB (averaged over several runs). However, my computer is running DDR4-3200 RAM, which I've read has a peak transfer rate of 25.6 GB/s, so should theoretically be able to write 51 GB in two seconds. By contrast, when I run the same test on an SSD, I see speeds pretty close to the rated maximum sequential write speed.

Rain
  • 11
  • 1
  • It's not like cat is writing directly to RAM in this case, it's going through the Virtual File System (VFS) layer of the kernel, and ending up in RAM. That may be the bottleneck, especially if the numbers you see on the SSD are larger than those you see here. – Andy Dalton Jun 23 '21 at 01:22
  • The RAM drive speeds I see are about 2x the speed w/ SSD. – Rain Jun 23 '21 at 01:27
  • Hum, that shoots down that theory. – Andy Dalton Jun 23 '21 at 01:27
  • You might find something by comparing /usr/bin/time -v and / or strace -c on the RAM vs SSD writes. I.e. by head -c 4G /dev/zero > ... – ibuprofen Jun 23 '21 at 01:52
  • 1
    And there is of course also the case of actually sunching the data. When you write to SSD the data could stay in RAM. Keep notice on free -h between tests. (I.e. shared for tmpfs - ans alos keep an aye on swap) https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html – ibuprofen Jun 23 '21 at 02:02
  • There are many factors, starting with the kernel treating the RAM drive the same way it would if you were saving to paper punch cards: It assumes noting about how fast or slow the device is, and does a lot of bookkeeping "behind the scenes" which will slow things down. Then, there is read and write caching. Then there is the hardware, such as the system bus which is shared by all the hardware, slow RAM vs high speed cache RAM, CPU pipelining, and so on. You cannot assume the RAM speed is a measure of speed in this context. – C. M. Jun 23 '21 at 02:04
  • 3
    Do you have swap space, and if so, on what is your swap located? The contentns tmpfs could be backed by swap, so you might be seeing the effects your large file being written to the SSD swap space when using tmpfs. – muru Jun 23 '21 at 06:21
  • I have 2 GB swap, which lives on an SSD (rated at around 3 GB/sec sequential write) – Rain Jun 26 '21 at 17:18

0 Answers0