Is there a way map a portion of my memory to act like a directory on my hard drive with the exception that the data is not permanently stored. So for example, I save a file in /home/user/directory/filename.txt
in gedit and it can be opened in nano. I do not need the files to be stored permanently and I need them to be quickly written and read.
3 Answers
Yes there is, it's called a ram-disk on Linux. There are two types: a raw block device that you can create, backed by memory, which allows you format it with any file system (e.g. ext3). The other type are file systems which automatically use RAM as a backing store, but are still fully capable of being mounted.
Ram disks are usually available automatically on Linux as, and can be mounted and formatted just like a regular hard-disk:
* /dev/ram0
* /dev/ram1
* ...
And there are file systems that use RAM as a backing store:
* tmpfs (e.g.: mount -t tmpfs -o size=1G,nr_inodes=10k tmpfs /my/tmp)
* there are also some build on FUSE.
-
1The ramdisc block device is only useful for special purposes, for example creating disc images; it is not as good as tmpfs, in particular it is not resizable on the fly and uses memory even if empty.– MarkRAug 2, 2010 at 21:44
Yes, there is an in-memory filesystem called tmpfs.
It is a completely normal filesystem, but each time Linux asks it to flush on the disk, in answers "wait just a little bit more" and Linux keeps caching.
It is heavily used in Linux live CDs.
mount -t tmpfs tmpfs /home/user/directory
If you want this to take effect even after reboots, add an entry to your /etc/fstab
.
-
-
-
Thanks, but how would you define how big that tmpfs is? Say if I want to limit it to 32MB?– HengjieDec 4, 2012 at 2:18