AMSA

Week 7: TMPFS

Ferran Aran Domingo
Oriol Agost Batalla
Pablo Fraile Alonso

Goals for today

  • Any questions from the previous session?
  • Memory based filesystems (RAM disks).
  • Tmpfs
  • Tmpfs vs ramfs
  • How to create it?
  • Present and explain Prac-3.3

RAM disks

  • Memory-based filesystem made of Random Access Memory (RAM) that the computer treats as if it was a disk drive (a virtual one).
  • Provides very fast read/write speeds compared to traditional storage devices.
  • Data stored in RAM disks is volatile—lost when the system is powered off or restarted.
  • Useful for temporary files, caching, or applications needing high-speed storage.

Why is it faster?

  • No moving parts (unlike HDD)
  • No bus being used (IDE/SATA, …)
  • No extra writes from the filesystem

Note

It’s faster because RAM is volatile per definition, and all data will be lost in case of powering off the system, so there is no point in implementing back ups.

How much faster?

ramfs vs tmpfs

ramfs

  • Older system type, replaced in most scenarios by tmpfs
  • Creates an in-memory file system as Linux file system cache
  • Can be estimated by using the free command, cannot be seen with df
  • Cannot be limited in size
free -g
       total used free shared buffers cached
Mem:   31    29   2    0      0       8
-/+ buffers/cache: 20 11
Swap:  13    6    7

Note

This kind of memory is used by Linux to cache recent files and access them from RAM

tmpfs

  • More recent approach, solves many drawbacks
  • Can be limited in size, gives disk full error upon going over it
  • Can be seen with df
  • Might use swap space if running out of memory and available
df -h /mnt/ramdisk
Filesystem Size Used Avail Use% Mounted on
tmpfs      512M 0    512M  0%   /mnt/ramdisk

How to create it? Mounting

  • Mounting is making a file system available to use on another one
  • Uses a mount point to anchor the new file system
  • Attaches the new file system onto the existing directory structure.
sudo mkdir -p /mnt/mytmpfs  # Create dir
sudo mount -t tmpfs tmpfs /mnt/mytmpfs  # Simple tmpfs
sudo mount -t tmpfs -o size=1G,uid=1000,gid=1000,mode=0770 tmpfs /mnt/mytmpfs
# -t tmpfs -> filesystem type
# -o size=<size> -> filesystem size
# -o uid=<user_id> -> owner user id
# -o mode=<mode> -> set fs permissions, i.e. 0770 to make it like `/tmp`
# <name> -> device name
df -h /tmp/myramdisk  # See space and usage
sudo umount /mnt/mytmpfs  # Unmount fs

See more on the man page

Making it permanent

/etc/fstab is a file that tells the Linux system what systems to mount automatically, where and with what options.

tmpfs /mntmytmpfs tmpfs size=1G,uid=alice,,mode=0770 0 0
sudo mount -t tmpfs -o size=1G,uid=amsa,,mode=0770 tmpfs /mnt/mytmpfs

In the first command, last two zeros are dump and fsck, non-specifics

Quizz

RAM disks

  • What do we change to make a ram disk automatically mount on boot?

  • Which is the current used one?

  • Which of tmpfs or ramfs uses SWAP? Is that bad or good?

  • What’s the max size of either one of them?

References

Additional Exercices

Create a swapfile, mount a tmpfs and max out the RAM so that it uses the SWAP. Provide us proof of this happening.

Activity 3.2

Ready to have some fun? Check out the third AMSA activity here!