#!/bin/bash

t_mem=$(grep MemTotal /proc/meminfo | awk '{print $2}'A)
m_max=`expr $t_mem - $t_mem / 8`
m_max_4=`expr $m_max / 4`
m_alert=`expr $t_mem / 3`
m_alert_4=`expr $m_alert / 4`
m_min=`expr $t_mem / 5`
m_min_4=`expr $m_min / 4`
echo "max mem is $m_max"
echo "alert mem is $m_alert"
echo "min mem is $m_min"
echo "=============================="
echo ""

echo "net.ipv4.tcp_mem = $m_min_4 $m_alert_4 $m_max_4" >> /etc/sysctl.conf
echo "net.ipv4.tcp_rmem = 4096 4096 $m_max" >> /etc/sysctl.conf
echo "net.ipv4.tcp_wmem = 4096 4096 $m_max" >> /etc/sysctl.conf
sysctl -p
