I wondered, what would happen, if more tmpfs space is assigned than there is physical memory - and they are filled.
Suppose I have 4GB RAM, 4GB swap.
mount -o size=4G -t tmpfs tmpfs /mnt1 mount -o size=4G -t tmpfs tmpfs /mnt2 mount -o size=4G -t tmpfs tmpfs /mnt3
As far as I understand, there is no problem, since these devices do not actually allocate the memory they were assigned from the get-go.
Now I start to write on these:
cat /dev/zero >/mnt1/bla & cat /dev/zero >/mnt2/bla & cat /dev/zero >/mnt3/bla &
I wondered, how the system should handle this?
I did not find anything on it, but when I mount tmpfs multiple times, do I mount the same device over-and-over under the hood, or different, totally independent device instances are created?
Am I somehow prevented from crashing my system, or am I free to do it this way?
The underlying reason I started to ponder it, when assigning tmpfs to /tmp:
- one approach is mounting directly,
- the other is to create a file in /dev/shm, and bind mount that.
If there is no limit assigning tmpfs space, 2. - bind mounting - is probably an inherently safer option, if I want to make extensive use of tmpfs, but don't want to spend too much time thinking through the consequences of my actions.