Set the shared memory to half of the installed

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
User avatar
voronwe
Posts: 193
Joined: Tue Jan 18, 2005 12:40 am
Location: Copenhagen Denmark

Set the shared memory to half of the installed

Post by voronwe »

Hello guys

I needed a quick way the change the Shared memory size on my ZM Machine, so i decided to build a script to do it for me, and ended up with the following, need someone to go it thru and tell me if iam all off or what, have tested it on my RedHat FC 3 and it seems to work.

Code: Select all

#!/bin/bash
#used for test purpose
#ZMDIR=`pwd`
#SYSCTL="$ZMDIR/etc/sysctl.conf"

# To change the Shared memory to half of the memory size of that u have installed in ur machine entehr the path for ur sysctl.conf
# below, on a RedHat Fedora Core 3 it is /etc/sysctl.conf
SYSCTL="/etc/sysctl.conf"

######################################################################################
# This line i found on the INet, not exactly sure what it does past the              #
# ($1 / 2) * 1024, but my end result is half the size of the installed memory        #
# into my variable SIZE, with that done i can now set my shared memory to that       #
# size in sysctl.conf.                                                               #
SIZE=`dmesg | egrep 'Memory.*available' | perl -ne '/\/(\d+)/; $_ = ($1 / 2) * 1024; print $_ > 268435456 ? $_ : 268435456'`
######################################################################################

######################################################################################
# The 2 following variables wil bet set to the new shared mem limits                 #
KSHMAX="kernel.shmmax=$SIZE"
KSHMALL="kernel.shmall=$SIZE"
######################################################################################

######################################################################################
# Find the original shared memory lines in sysctl.conf file,                         #
# this i used in the find command                                                    #
KSHMAX_ORG=$(grep "kernel.shmmax=" $SYSCTL)
KSHMALL_ORG=$(grep "kernel.shmall=" $SYSCTL)
######################################################################################

# Display what we found
echo "KSHMAX is = $KSHMAX"
echo "KSHMALL is = $KSHMALL"
echo "KSHMAX_ORG is = $KSHMAX_ORG"
echo "KSHMALL_ORG is = $KSHMALL_ORG"

# Make a backup of the or sysctl.conf
cp $SYSCTL $SYSCTL.org

# Do the changes in the file and remove the blank lines in it
if [ "$KSHMAX_ORG" == "" ] && [ "$KSHMALL_ORG" == "" ]; then
	echo "+++++++ ERROR : KSHMAX_ORG is empty and KSHMALL_ORG is empty"
	perl -i -ne "print if /\S/" $SYSCTL
	echo $KSHMAX >> $SYSCTL
	echo $KSHMALL >> $SYSCTL
else
	perl -i -ne "print if /\S/" $SYSCTL
	perl -i -pe 's/'$KSHMAX_ORG'/'$KSHMAX'/g' $SYSCTL
	perl -i -pe 's/'$KSHMALL_ORG'/'$KSHMALL'/g' $SYSCTL
fi
The script can be downloaded here. http://dvss.voronwe.dk/zm/shared.sh

Any changes are welcome, and if u find it usefull then good. :)
Best Regards
Tom Stage
User avatar
voronwe
Posts: 193
Joined: Tue Jan 18, 2005 12:40 am
Location: Copenhagen Denmark

Post by voronwe »

Hey All

A new version is now on my website, the script will do the same as before, but this time i have changed it so the minimum amount of ram installed in the server have to be 256MB of ram, this will result in a shared memory size of 128MB witch is half of the installed, the previous script needed 512MB of ram installed in the server.

Use the link in the above post to get the script.
Best Regards
Tom Stage
User avatar
voronwe
Posts: 193
Joined: Tue Jan 18, 2005 12:40 am
Location: Copenhagen Denmark

Post by voronwe »

Hey all

Within the next few days the link to this script wil change to the following. :

http://www.dvos.dk/zm/shared.sh
Best Regards
Tom Stage
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

whats all this about proxies apearing in several posts?
SyRenity
Posts: 301
Joined: Mon Jan 24, 2005 2:43 pm

Post by SyRenity »

Forum spam? Hope it's not a robot, otherwise we will have all the forum full of these.
Ruler
Posts: 235
Joined: Mon Nov 08, 2004 9:02 pm
Location: Bay City, MI

Post by Ruler »

This *exact* same thing appeared on a hunting/fishing site I'm also a member of.
Post Reply