Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

/dev/ SHM is a device file, which can be viewed as an entry to the system memory. It can be viewed as a physical storage device, a TMP filesystem, through which files can be read and written to memory to speed up some I/O operations. For example, open, write, read!

/dev/ SHM (shitou has never used Oracle). You can mount /dev/shm to the current file system. You can read and write to /dev/shm directly, for example:

#touch /dev/shm/file1
Copy the code

Since it is a memory-based file system, the files under /dev/shm will not exist after the system restarts. The size of the /dev/shm partition is 50% of the physical memory of the system, although using /dev/shm is much more efficient. However, it is rarely used in any distribution software (except for Oracle). You can check for files in ls /dev/shm. If not, the device is not used in the current system.

Therefore, you need to add the configuration to the /etc/fstab file:

DAYTIME=$(date +%Y%m%d)
memTotal=$(grep MemTotal /proc/meminfo | awk '{print $2}')
shmTotal=$(df -k /dev/shm | awk '{print $2}' | head -n 2 | tail -n 1)
if [ "$(grep -E -c "/dev/shm" /etc/fstab)" -eq 0 ]; then
    [ ! -f /etc/fstab."${DAYTIME}" ] && cp /etc/fstab /etc/fstab."${DAYTIME}"
    cat <<EOF >>/etc/fstab
tmpfs /dev/shm tmpfs size=${memTotal}k 0 0
EOF
    mount -o remount /dev/shm
  else
    if [ "$shmTotal" -lt "$memTotal" ]; then
      shmTotal=$memTotal
      [ ! -f /etc/fstab."${DAYTIME}" ] && cp /etc/fstab /etc/fstab."${DAYTIME}"
      line=$(grep -n "/dev/shm" /etc/fstab | awk -F ":" '{print $1}')
      sed -i "${line} d" /etc/fstab
      cat <<EOF >>/etc/fstab
tmpfs /dev/shm tmpfs size=${memTotal}k 0 0
EOF
      mount -o remount /dev/shm
    fi

  fi
Copy the code

This is the end of sharing ~

If you think the article is helpful to you, please like it, favorites it, pay attention to it, comment on it, and support it four times with one button. Your support is the biggest motivation for my creation.

❤️ technical exchange can follow the public number: Lucifer think twice before you do ❤️