RHEL: Resize/disable /dev/shm filesystem

# Tested on RHEL 5, 6 & 7


# Notes from www.walkernews.net, www.generation-linux.fr and Red Hat web site

# Thanks to big memory size, nowadays most of RAM is not used at all. It is thus possible
# to allocate a part of this physical memory to be used as storage.

# The name given to a temporary unix file is 'tmpfs'. From Linux 2.6 on this tmpfs is based
# on ramfs. It is possible to fix a limit to its size in a way that system will allocate
# memory dynamically.

# By default, RHEL and most Linux distributions mount tmpfs (a RAM-based temporarily
# filesystem for shared memory) on /dev/shm directory and this temporarily filesystem size
# is always set to be half of the installed memory.

# If that default size is not something expected, we can increase or reduce the /dev/shm
# filesystem size.

# We may drop or disable this temporarily RAM-based filesystem entirely, to prevent it
# from auto-mount during system boot-up, if none of the application in our server is relying
# on shared memory function or explicitly using tmpfs.



# Implementation
# ------------------------------------------------------------------------------------------

# By default, tmpfs is mounted during system start-up and its definition in /etc/fstab looks
# like this (on RHEL 7 there's no specification in /etc/fstab file by default):

   tmpfs                   /dev/shm                tmpfs   defaults        0 0

# What produces, for a system with 16 GB of RAM, a F.S. like this:

df -k
   [...]
   tmpfs                 7.8G     0  7.8G   0% /dev/shm



# Creating own tmpfs
# ------------------------------------------------------------------------------------------

# Create a mount point on /mnt/mytmpfs.

mkdir /mnt/mytmpfs

# Change directory permissions so anyone will be able to read/write/execute on it

chmod 777 /mnt/mytmpfs

# Finally, mount 'tmpfs' the usual way

mount -t tmpfs -o size=256M tmpfs /mnt/mytmpfs

# Remember that if we don't specify the size, it will be half the RAM.

# For this F.S. to be mounted during system boot-up, add it to /etc/fstab file:

   tmpfs                   /
mnt/mytmpfs            tmpfs    defaults,size=256M     0 0



# To increase or decrease /dev/shm filesystem size
# ------------------------------------------------------------------------------------------

# Open /etc/fstab and locate the line of /dev/shm and use the tmpfs size option to specify
# desired size (on RHEL 7, add the line if not present):

# e.g. 512MB:

   tmpfs
                   /dev/shm                tmpfs    defaults,size=512m    0 0

# e.g. 2GB:

   tmpfs
                   /dev/shm                tmpfs    defaults,size=2g      0 0

# To make change effective immediately, run following mount command to remount the
# /dev/shm filesystem:

mount -o remount /dev/shm



# Disabling /dev/shm filesystem
# ------------------------------------------------------------------------------------------

# Actually, Linux allocates the memory for this tmpfs on demand basis, up to the maximum
# size shown in 'df -h' command output. If none of the application is using the /dev/shm,
# this tmpfs in fact does not consume any memory space. So, why disable it?

# Anyway, if you prefer to disable /dev/shm temporarily just execute the umount command:

   umount /dev/shm

# To prevent tmpfs from auto-mount each time RHEL boots up, just comment out or
delete
# corresponding line from /etc/fstab.


# On RHEL 7 API file systems are mounted by systemd. As they constitute an important mean of
# communication kernel<->userspace and userspace<->userspace they are mounted automatically
# without user confirmation. It is possible to disable the automatic mounting of some of them,
# but /dev/shm should always become available, so better leave it mounted ;)
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
RHEL: Scan and configure new SAN (fibre channel) LUNs
Viewed 7292 times since Sun, May 27, 2018
RHCS: Install a two-node basic cluster
Viewed 9631 times since Sun, Jun 3, 2018
How to Install and use Lsyncd on CentOS 7 / RHEL 7 rsync
Viewed 3734 times since Wed, Oct 31, 2018
RHCS6: Clustered LVM
Viewed 1790 times since Sun, Jun 3, 2018
Stunnel Setup
Viewed 16779 times since Fri, Sep 28, 2018
ubuntu How to Reset Forgotten Passwords in Ubuntu 16.04
Viewed 2093 times since Tue, Dec 8, 2020
RHEL: Building a custom kernel on RHEL 6
Viewed 3630 times since Sat, Jun 2, 2018
Use inotify-tools on CentOS 7 or RHEL 7 to watch files and directories for events
Viewed 13318 times since Fri, Jul 27, 2018
Super Grub2 Disk
Viewed 2928 times since Wed, May 22, 2019
LVM: Extend SWAP size by growing existing Logical Volume
Viewed 2115 times since Sat, Jun 2, 2018