Default tmpfs configuration

Latest response

All;

I am a systems engineer that has a distracting curiosity. I was recently working on configuring a RHEL7 system for an Oracle database and following Oracle instructions on doing so. Long story short, I am looking for some information on how the default tmpfs filesystems (/dev/shm, /run, ,etc.) get created. Is the default mechanism for this hard-coded into the kernel or possibly implemented in some operating system service(s)? I'm very interested in how this mechanism works and might be modified.

Thanks!

Responses

Hi Leslie,

Early in the boot sequence, the kernel mounts /boot/initramfs-$(uname -r).img, then executes the init.sh file from that filesystem. That init.sh file mounts these two filesystems:

if ! ismounted /dev/shm; then
    mkdir -m 0755 /dev/shm
    mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime tmpfs /dev/shm >/dev/null
fi

if ! ismounted /run; then
    mkdir -m 0755 /newrun
    mount -t tmpfs -o mode=0755,nosuid,nodev,strictatime tmpfs /newrun >/dev/null
    cp -a /run/* /newrun >/dev/null 2>&1
    mount --move /newrun /run
    rm -fr -- /newrun
fi

The initramfs file is generated by dracut. The init script may be found here: /usr/lib/dracut/modules.d/99base/init.sh

Cool, thanks for that answer. I also see that the various tmpfs mounts appear to use the same memory space/quantity by default (which appears to be 50% of available RAM). Is this something inherent in the coding of the kernel or is it also configured in a script somewhere?

Hi Lesley,

The size of a tmpfs filesystem is actually the maximum amount of space that it could use. When the filesystem is empty, it is no using any memory. It won't allow the filesystem to contain more than that size of data, which defaults to 50 of RAM.

To set the size of tmpfs to 20% of RAM, one could use:

    mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime,size=20% tmpfs /dev/shm >/dev/null

You could also specify number of bytes:

    mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime,size=10m tmpfs /dev/shm >/dev/null

Or number of blocks:

    mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime,nr_blocks=1000 tmpfs /dev/shm >/dev/null

For more on options, see the mount page for mount, and search for tmpfs.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.