tmpfs usage and resizing

Now, from what I read the tmpfs doesn't take physical storage, but uses the virtual memory of the machine. Is it correct?

Correct. tmpfs appears as a mounted file system, but it's stored in volatile memory instead of a persistent storage device. So this could answer your other questions.

In reality you cannot assign physical storage to tmpfs since it only relies on virtual memory. Everything stored in tmpfs is temporary in the sense that no files will be created on the hard drive. Swap space is used as backing store in case of low memory situations. On reboot, everything in tmpfs will be lost.

Many Unix distributions enable and use tmpfs by default for the /tmp branch of the file system or for shared memory.

Depending of your distribution you can use tmpfs for the /tmp. By default, a tmpfs partition has its maximum size set to half of the available RAM, however it is possible to overrule this value and explicitly set a maximum size. In this example, to override the default /tmp mount, use the size mount option:

/etc/fstab
tmpfs   /tmp         tmpfs   nodev,nosuid,size=2G          0  0

source: https://wiki.archlinux.org/index.php/tmpfs


Now, from what I read the tmpfs doesn't take physical storage, but uses the virtual memory of the machine. Is it correct? Does it affect the physical storage in any way? Is there a reality where the tmpfs will be written to the physical storage?

Well, it fills the swap area, to which it is limited. See tmpfs does not overflow to swap

Next, do all the mounted (/dev/sda1, /dev/sda1, etc...) dirs share the tmpfs? Or each of them gets a different one?

This depends on where the tmpfs is mounted. But all tmpfss should share the same memory, if that's what you meant.

I think I am missing something.

Maybe https://superuser.com/questions/45342/when-should-i-use-dev-shm-and-when-should-i-use-tmp:

Recent 2.6 Linux kernel builds have started to offer /dev/shm as shared memory in the form of a ramdisk, more specifically as a world-writable directory that is stored in memory with a defined limit in /etc/default/tmpfs. /dev/shm support is completely optional within the kernel config file. It is included by default in both Fedora and Ubuntu distributions, where it is most extensively used by the Pulseaudio application. [emphasis removed and added]