brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mount -t tmpfs -o size= gives you a folder that lives in RAM on Linux

Linux
~/tips/tip-linux-tmpfs-mount-size

mount -t tmpfs -o size=512M,mode=1777 tmpfs /mnt/scratch

Create a fast scratch folder in memory with a hard size cap.

For temporary files that are written and read a lot, like build output or a transcode cache, a folder in memory is much faster than a disk and saves wear on an SSD. tmpfs gives you that in one command.

mkdir -p /mnt/scratch
mount -t tmpfs -o size=512M,mode=1777 tmpfs /mnt/scratch
df -h /mnt/scratch

size=512M is a cap, not a reservation. The tmpfs man page explains that memory is only used for what you actually store, so an empty tmpfs costs almost nothing. mode=1777 gives the folder the same permissions as /tmp, so everybody can write but nobody can delete files of others.

If you need more room later, you can resize it while it is mounted, without losing files:

mount -o remount,size=1G /mnt/scratch

For a permanent mount, add a line to /etc/fstab:

tmpfs  /mnt/scratch  tmpfs  size=512M,mode=1777  0  0

Everything in a tmpfs is gone after a reboot or an unmount. That is the point, but never put anything there you want to keep. Without a size, the default cap is half of your RAM, and a full tmpfs competes with your programs for memory; under pressure its contents can be pushed to swap. I would always set a size that fits comfortably next to what the machine needs to run.

Further reading: tmpfs(5) manual page, mount(8) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link