Backing tempfs with disk instead of RAM/SWAP

253 views Asked by At

I want to limit the size of folder, so that a process cannot write more then x MB data to that folder. Looks like its not possible to do this in linux for folders but it can be done on tempfs filesystem.

So i can create a tempfs filesystem and set a size limit on it.

But the problem is tempfs is backed by RAM (and swap) which is not acceptable for my case as i will run out of disk space. Can i back the tempfs with a existing folder on disk?

I want to create around 50 such directories and set a cap of 500MB on each of those.

EDIT 1: What does following command do?

sudo mount -t tmpfs /tmp /tmp/mnt/aks2

I guess it mounts folder /tmp as mountpoint /tmp/mnt/aks2 . Does that mean /tmp/mnt/aks2 mount point is backed by /tmp folder instead of RAM? If yes why do i -t tmpfs in the command?

1

There are 1 answers

2
Ignacio Vazquez-Abrams On

No. Just create a filesystem in a file of the maximum size desired and loopmount that instead.

e.g.:

dd if=/dev/zero of=image.img bs=1MiB count=500
mke2fs image.img
sudo mount image.img /mnt