#!/bin/bash
#============================================================================
# Title       : memory
# Description : Configure memory on Linux EL7/EL8
# Author      : Bart Sjerps <bart@dirty-cache.com>
# License     : GPLv3+
# ---------------------------------------------------------------------------

memtotal=$(awk '/MemTotal/ {print $(NF-1)}' /proc/meminfo)

# Set the shmmax memory parameter in bytes.
# Recommended half the size of physical memory (see oracle support note 567506.1)
shmmax=$(echo "$memtotal*50*1024/100"|bc)

# Set the shmall memory parameter in 4k pages.
# Recommended "Greater than or equal to the value of shmmax, in pages"

shmall=$(echo "$shmmax/4096+1"|bc)

cat <<- EOF > /etc/sysctl.d/20-oramem.conf
	# Calculated value for shmmax - ${SHMMAX}% of ram - in bytes
	kernel.shmmax = $shmmax
	# Calculated value for shmall - equal to shmmax+1 - in 4k pages
	kernel.shmall = $shmall
	EOF
