5

I've spent the past several hours (not few, several!) reading different pages and questions on how to setup a tmpfs/RAMDisk. They all say different things and say what filesystems I should and shouldn't be including, so I would really appreciate a conclusive, updated answer on this.

I have 16GB of RAM and I want to dedicate maybe 6-8GB to a RAM disk.

1) I plan on adding /tmp, /var/cache, and ~/.cache to the RAM Disk (and Firefox through profile-sync-daemon). Any other suggestions on what to add? I read on moving /var/lock and /var/run too, but since it's from /var is that advisable?

2) I run LaTeX a lot (LuaLaTeX specifically) so I was thinking maybe I could install that in the RAM instead of on the actual SSD and see if that runs faster? Or I could move /var/lib/texmf and ~/.texmf-var to RAM? I don't know, so I'd appreciate the advice!

airatin
  • 51
  • @psusi ??? I specifically linked to that question and stated why I'm asking about it "again"... – airatin Jan 04 '15 at 22:57
  • They don't explicitly create a ramdisk; they create a directory in which to mount it, and then mount it ( which creates it ). – psusi Jan 04 '15 at 22:57
  • You should ask for clarification on an existing answer as a comment there rather than creating a whole new question. – psusi Jan 04 '15 at 22:57
  • The two answers don't explicitly create a ramdisk? I've seen in some answers to other questions where it's not even mounted, the appropriate line is simply entered into fstab and then rebooted. So the mkdir and mount lines do need to be entered then? – airatin Jan 04 '15 at 22:59
  • Also I don't have enough reputation to post a comment there; I feel that an answer should be an answer and not asking for clarification as it would appear messy, hence why I asked here. – airatin Jan 04 '15 at 23:01
  • fstab just specifies what should be mounted automatically during boot. To mount something you have to have somewhere to mount it, hence why they created a new directory since it they didn't already have an existing directory they wanted to mount it in. – psusi Jan 04 '15 at 23:01
  • @psusi Thanks for clarifying, appreciate it! :) I still am wondering about the last 2 questions I posted here; should I post those separately or leave them here (would that still make this entire question a duplicate then?)? – airatin Jan 04 '15 at 23:03
  • Go ahead and remove the first part instead of striking it out ( it's just distracting ) and then the two remaining questions would be unique. – psusi Jan 04 '15 at 23:22
  • @psusi just to clarify, when you create /media/ramdisk (for example) and want to add /tmp and other filesystems to ramdisk, don't you have to mount /tmp (and others) to /media/ramdisk? So in the second answer from this question you would do the first two lines (mkdir and mount the ramdisk) and then add /media/ramdisk /tmp tmpfs noatime,nodev,mode=1777 0 0 to fstab? That's why I got confused about mounting or simply editing fstab; once ramdisk is created where does /tmp go get mounted?? – airatin Jan 05 '15 at 03:58
  • No. You don't mount one directory to another. Normally you mount a block device into a directory, but since tmpfs is a ramdisk, the block device argument is ignored. Again, the only reason they created /media/ramdisk is because they didn't have some other place, such as /tmp that they wanted to make a ramdisk. Again, you don't "create" the ramdisk, and then mount it; you just mount it and it springs into existence to satisfy the mount request. – psusi Jan 05 '15 at 14:54

1 Answers1

2

/var/run is tied to the specific running instance of a machine at a time due to storing PIDs of the running processes, I would only avoid placing that on a RAM disk if you are using a virtual machine and suspend the VM often. /var/lock is intended to prevent more than a single instance of a given application from running and thus should also be fine. If you have a service which is not well behaved and uses the leftover pid/lock files to detect crashes you should either relocate the paths they store the information or find alternatives.

Source: http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/var.html

There are estimates running applications on a RAM disk may result in performance increases of in the 10x range. The bandwidth between your process and memory is definitely faster on modern AMD64 systems, thus this claim has substance if you are IO bound somewhere between the CPU and the disk.

Mark
  • 131
  • 6
  • Thanks for the help! Just a quick question, I did sudo mkdir -p /media/ramdisk and then sudo mount -t tmpfs -o size=4G tmpfs /media/ramdisk/. After doing grep /media/ramdisk /etc/mtab | sudo tee -a /etc/fstab, the file fstab does include the /media/ramdisk as part of it. So how do I add /tmp and the other folders?? /media/ramdisk has nothing in it right now so why did I even make this directory? How do I add multiple folders (/tmp, /var/run, etc) to ramdisk? – airatin Jan 05 '15 at 01:09
  • You would need to replace the target files {/tmp,/var/run,etc} with symbolic links using a combination of the rm and ln commands (IE: rm /tmp && ln -s /media/ramdisk-tmp /tmp). I would recommend creating a separate RAM disk for each area you wish to replace. This allows control of the size for each group, as /tmp should be larger than /var/run and /var/lock. Another approach would be to setup a startup script to create the directories within the RAM disk – Mark Jan 05 '15 at 18:28