Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Aug 2 '10 at 14:34

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers 3

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.

share|improve this answer
add comment
mount -t tmpfs tmpfs /home/user/directory

If you want this to take effect even after reboots, add an entry to your /etc/fstab.

share|improve this answer
    
What would the entry look like? –  Hengjie Dec 3 '12 at 23:02
    
@Hengjie tmpfs /home/user/directory tmpfs defaults 0 0 –  John Kugelman Dec 3 '12 at 23:07
    
Thanks, but how would you define how big that tmpfs is? Say if I want to limit it to 32MB? –  Hengjie Dec 4 '12 at 2:18
add comment

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.
share|improve this answer
    
+1 for actually mentioning both options –  sleske Aug 2 '10 at 15:00
    
The 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. –  MarkR Aug 2 '10 at 21:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.