16

How to be sure that a tmpfs filesystem can only deal with physical and it's not using a swap partition on disk?

Since I have a slow HDD and a fast RAM, I would like, at least, giving higher priority to the RAM usage for swap and tmpfs or disabling the disk usage for tmpfs related mount points.

peterh
  • 9,488
  • 16
  • 59
  • 88
user1717079
  • 485
  • 2
  • 5
  • 11
  • 3
    Actualy, under the terms you've given the only one answer is not using swap at all. And JFYI Linux kernel programmers are really aware RAM is faster. So, you're doing something rather pointless. – poige Oct 10 '12 at 22:10
  • 3
    Everybody has a slow hard disk and fast RAM. Use tmpfs. The kernel is smarter than you when it comes to deciding what should be kept in RAM and what has to be relegated back to disk when the RAM is full. – Gilles 'SO- stop being evil' Oct 10 '12 at 23:22

1 Answers1

12

use ramfs instead of tmpfs. ramfs is a ramdisk (no swap) tmpfs can be both in your /etc/fstab:

none     /path/to/location     ramfs  defaults,size=512M   0     0

edit the size parameter to whatever you like but be careful not to exceed your actual amount of ram.

NOTE: the use of a ramfs instead of tmpfs is not something i would recommend. you will find yourself experiencing stability issues if something happens and you write a ton of data to your ramdisk. you can NOT unallocate ram from a ramfs. once your ramdisk (all of your ram) is full your system will seize up. ram is volatile memory, meaning once it looses power all data is gone. so if your ramdisk fills up your ram and you crash you will never see what was on your ram disk again. unlike ramfs, tmpfs limits its size.

h3rrmiller
  • 13,095
  • 5
  • 31
  • 41
  • thanks, i have never heard of this ramfs, it's something that was introduced recently ? What are the requirements for this ? Kernel version ? EDIT how to swap on a ramfs ? – user1717079 Oct 10 '12 at 15:54
  • tmpfs is supported on all kernels 2.4+. according to wikipedia ramfs precedes tmpfs (http://en.wikipedia.org/wiki/Tmpfs#Linux). – h3rrmiller Oct 10 '12 at 15:55
  • /dev/shm is an example of a ramdisk. however it has been defaulted to tmpfs now that disks are faster. You commonly find /tmp as a ramfs on Solaris. The issue with that is you can continually allocate more ram for /tmp but cannot unallocate that ram once allocated without a reboot – h3rrmiller Oct 10 '12 at 15:56
  • so i only have `/dev/shm` if i want to swap on a ramfs ? – user1717079 Oct 10 '12 at 15:58
  • why would you want to build a swap partition in ram? and no, you can create new mount points that exist in ram with ramfs – h3rrmiller Oct 10 '12 at 16:00
  • because my RAM performs better than my HDD, also i do not need a real ramdisk for user data but i would like to speed up system performance – user1717079 Oct 10 '12 at 16:02
  • using ramfs is something that should NOT be done by a beginner. the implementation of tmpfs and the use of swap was a feature designed to improve stability/reliability and to avoid running out of memory. – h3rrmiller Oct 10 '12 at 16:03
  • ram will always perform better than a mechanical disk. how slow is your disk? – h3rrmiller Oct 10 '12 at 16:04
  • 5400rpm with a not so fast seek time, it's slow – user1717079 Oct 10 '12 at 16:05
  • 1
    the use of a ramfs instead of tmpfs is not something i would recommend. you will find yourself experiencing stability issues if something happens and you write a ton of data to your ramdisk. as i said you can NOT unallocate ram from a ramfs. once your ramdisk (all of your ram) is full your system will seize up. ram is volatile memory, meaning once it looses power all data is gone. so if your ramdisk fills up your ram and you crash you will never see what was on your ram disk again – h3rrmiller Oct 10 '12 at 16:08
  • wait a minute, i was talking about swap space, not ramdisk, the ramdisk is exactly the thing that i do not need, i just need something like a swap for the kernel but i would like to be sure that it will not access the disk but only the RAM – user1717079 Oct 10 '12 at 16:11
  • 2
    +1 to h3rrmiller - I've seen a ramfs setup consume all available memory until a machine dies. tmpfs is more appropriate. Also there is little point swapping to ram - why swap at all? – Danny Staple Oct 10 '12 at 16:43
  • Linux is pretty good at allocating resources by itself. It will make efficient use of swap by paging old ram contents into swap until they are needed again. the point of swap is to be additional "pseudo-ram" stored on alternate media to free up the faster ram for more important/strenuous tasks – h3rrmiller Oct 10 '12 at 19:27