URL: http://www.eit.name/blog/read.php? 426
Overview:
Using in-memory FS you can allocate part of physical memory to be used as a harddisk partition. you can mount this partition and start writing and reading files like a harddisk partition, it will be much faster for sure. when a vital process becomes drastically
Slow because of disk writes, you can choose either ramfs orTmpfsFile Systems for writing files to the ram.
BothTmpfsAndRamfs
Mount will give you the power of Fast Reading and Writing files from and to the primary memory. when you test this on a small file, you may not see a huge difference. you'll notice the difference only when you write large amount of data to a file with some
Other processing overhead such as network.
How to mount tmpfs and ramfs
# Mkdir-P/mnt/{TMP, Ram}
# Mount-T tmpfs-O size = 50 m tmpfs/mnt/tmp
# Mount-T ramfs-O size = 50 m ramfs/mnt/Ram
You can mount ramfs and tmpfs during boot time by adding an entry to the/etc/fstab or execute the above mount command when starting your system.
Difference between ramfs and tmpfs
Generally ramfs and tmpfs does the same thing with few minor differences.
* Ramfs will grow dynamically. so, you need control the process that writes data to make sure ramfs doesn't exhaust all avaliable RAM in your system, otherwise an OOM will occure which might cause some potential damage. assume that you have 2 GB of Ram and
Created a 1 GB ramfs and mounted as/mnt/Ram. when the total size of the/mnt/Ram crosses 1 GB, you can still write data to it. system will not stop you, when it goes abve total Ram size of 2 GB, the system may hang, as there is no RAM for other operation.
* Tmpfs will not grow automatically. it's more like a harddisk partition. it does not allow you to write more data to the mounted tmpfs. when you try to write more data the specified limit, it'll output errors like this:
# Cp 20 mb. tgz/mnt/tmp
CP: Writing '/mnt/tmp/20 mb. tgz': no space left on device.
Ramfs and tmpfs disadvantages
Since both ramfs and tmpfs is writing to the system Ram, it wocould get deleted once the system gets rebooted, or crashed. if the data is critical, you should write a script to pick up the data from ramfs/tmpfs to disk in periodic intervals, and another script
To write down the data from ramfs/tmpfs to disk while the system is shutting down. But, this doesnt help you when system crash.
Table: Comparison of ramfs and tmpfs
Experimentation |
Tmpfs |
Ramfs |
Fill maximum space and continue writing |
Will Display Error |
Will continue writing |
Fixed size |
Yes |
No |
Uses swap |
Yes |
No |
Volatile storage |
Yes |
Yes |
If you want your process to write faster, opting for tmpfs is better, frankly it's mostly used to store PHP sessions.