juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Using RAM disk instead of a SD

Fri Feb 19, 2016 9:33 am

Hi guys,

I have some problem writing a .csv file because it is not as fast as I need. I read that it is possible to save this file into the ram disk that could make the raspberry write faster. How could I get this? Which folder is the RAM disk of the RPi or do I have do another steps to perform this?

Many thanks!

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using RAM disk instead of a SD

Fri Feb 19, 2016 9:44 am

You have to create your own.

There are two steps.

1) create a mount point, e.g. mkdir /ram

2) create a sized RAM disk, e.g. sudo mount -osize=100m tmpfs /ram -t tmpfs

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: Using RAM disk instead of a SD

Fri Feb 19, 2016 9:47 am

juranga wrote:do I have do another steps to perform this?
yes, it's built into the kernel so easy to do

Code: Select all

$ sudo mkdir /mnt/ramdisk
$ sudo mount -t tmpfs none /mnt/ramdisk
unmount when finished to free up the memory

Code: Select all

$ sudo umount /mnt/ramdisk
edit: beaten

juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Re: Using RAM disk instead of a SD

Fri Feb 19, 2016 11:08 am

Many thanks for your answers!

I guess that ram memory is not volatile, isn´t it? Moreover, I have the RPI 2 so it has 1GB Ram memory, how could I know how many memory would be free to use in my things?

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Using RAM disk instead of a SD

Fri Feb 19, 2016 11:15 am

juranga wrote:...how could I know how many memory would be free to use in my things?
Open a terminal and type...

Code: Select all

free
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Using RAM disk instead of a SD

Fri Feb 19, 2016 11:40 am

juranga wrote:Many thanks for your answers!

I guess that ram memory is not volatile, isn´t it? Moreover, I have the RPI 2 so it has 1GB Ram memory, how could I know how many memory would be free to use in my things?
It is volatile, when you shutdown anything in there is lost to the outer darkness. If you want to keep what's there you'll need to copy it somewhere else before shutting down.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26659
Joined: Sat Jul 30, 2011 7:41 pm

Re: Using RAM disk instead of a SD

Fri Feb 19, 2016 11:46 am

juranga wrote:Many thanks for your answers!

I guess that ram memory is not volatile, isn´t it? Moreover, I have the RPI 2 so it has 1GB Ram memory, how could I know how many memory would be free to use in my things?
It IS volatile - when the power is off, the data disappears. So you need to back the completed files off to SD card every now and again.

However, I don't think this is your problem, Baremetal I would write code that cached data then output to file in bigger chunks. But TBH, Linux should be doing that in the background for you in its file caching, so there is something off in your code somewhere that is slowing down writing to file.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Using RAM disk instead of a SD

Fri Feb 19, 2016 11:48 am

juranga wrote:I guess that ram memory is not volatile, isn´t it? Moreover, I have the RPI 2 so it has 1GB Ram memory, how could I know how many memory would be free to use in my things?
Ram is volatile. Its contents are lost when the machine is shut down.
This implementation (tmpfs) uses "virtual" memory. It shares the available memory with other things such as applications and disk cache. The amount of memory used simply depends on the size of the files. The size given to mount is only a maximum (and it defaults to half the machines memory ). So "free -h" will show no extra memory used after you have created the disk (there is a slight overhead, about 100k, even if the filesystem is empty).

It is common to mount /tmp as tmpfs - just add this line to /etc/fstab

Code: Select all

tmpfs /tmp  tmpfs defaults,noatime 0 0
Which apart from being fast, is cleared out on reboot.
Pi4 8GB running PIOS64

juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Re: Using RAM disk instead of a SD

Fri Feb 19, 2016 2:25 pm

Many thanks for all your answers!

I cannot use the ram disk in my application but it is great to learn new things!

Return to “General discussion”