LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 03-21-2014, 02:53 PM   #1
awreneau
Member
 
Registered: Aug 2003
Location: GA
Distribution: Ubuntu
Posts: 42

Rep: Reputation: 15
calculate kernel.shmall during kickstart


I've been given a set of values for the sysctl.conf file and I'd like to incorporate those into the kickstart so there is less manual work after the image is laid down.

I can collect the memory on the box w/ this:

awk '/^MemTotal/{ print $2 }' /proc/meminfo

I'd then like to fulfill the request to adjust kernel.shmall on the fly. The request is as follows:

kernel.shmall = MemTotal size / getconf PAGE_SIZE.


I cant seem to get past the fatal division by zero problem.

Here is the actual syntax.
Code:
awk '/^MemTotal/{ print $2 / system(getconf PAGE_SIZE) }' /proc/meminfo
awk: (FILENAME=/proc/meminfo FNR=1) fatal: division by zero attempted
 
Old 03-27-2014, 09:06 AM   #2
awreneau
Member
 
Registered: Aug 2003
Location: GA
Distribution: Ubuntu
Posts: 42

Original Poster
Rep: Reputation: 15
I figured it out.
I took an easy way out and setup a variable to pass to awk. I also had to format the output so as to eliminate any decimal places w/ the OFMT option.


Code:
#kernel.shmall physical RAM / pagesize
pgsize=$(getconf PAGE_SIZE)
sed -i "s/^kernel.shmall = .*/kernel.shmall = `awk -v pgsz=$pgsize '/^MemTotal/{print $2/pgsz}' OFMT="%3.0f" /proc/meminfo`/" /etc/sysctl.conf
 
Old 04-09-2014, 10:49 AM   #3
awreneau
Member
 
Registered: Aug 2003
Location: GA
Distribution: Ubuntu
Posts: 42

Original Poster
Rep: Reputation: 15
So I found I'd made an error here. The MemTotal value has to be converted to bytes first bc it's in KB from /proc/meminfo. The new formula is



#kernel.shmall physical RAM / pagesize
pgsize=$(getconf PAGE_SIZE)
sed -i "s/^kernel.shmall = .*/kernel.shmall = `awk -v pgsz=$pgsize '/^MemTotal/{print $2*1024/pgsz}' OFMT="%3.0f" /proc/meminfo`/" /etc/sysctl.conf


And for giggles I'm adding the shmmax and huge page calculation.

#kernel.shmmax = 1/2 of physical ram
sed -i "s/^kernel.shmmax = .*/kernel.shmmax = `awk '/^MemTotal/{print $2*1024/2}' /proc/meminfo`/" /etc/sysctl.conf


#vm.nr_hugepages = 50% of the total memory in bytes
cat >> /etc/sysctl.conf << EOF
vm.nr_hugepages = `awk '/^MemTotal/{print $2}' /proc/meminfo | awk '{huge = $1 / 2 / 2048} {printf "%.0f\n", huge}'`
EOF
 
Old 04-10-2014, 11:30 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Not contributing to the exact question but here's some custom puppet facts I put together that may be useful:
Code:
# pagesize.rb
require 'facter'
Facter.add(:pagesize) do
  setcode do
     Facter::Util::Resolution.exec('getconf PAGE_SIZE')
  end
end
Code:
# physpages.rb
require 'facter'
Facter.add(:physpages) do
  setcode do
     Facter::Util::Resolution.exec('getconf _PHYS_PAGES')
  end
end
Code:
# recshmall.rb
# generates recommended value for SHMALL based on %80 of pysical memory
require 'facter'
Facter.add(:recshmall) do
  setcode do
    physpgs = Facter.value(:physpages)
    if physpgs
      recshmall = Integer(physpgs) / 10 * 8
    end
    recshmall
  end
end
Then we just use:
Code:
kernel.shmall = <%= @recshmall %>
.. in our /etc/sysctl.conf template
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Meaning of SHMALL kernel variable JMCraig Linux - Newbie 5 04-28-2010 06:07 PM
SHMALL and SHMMAX hq5535 Linux - Kernel 0 06-01-2008 09:08 PM
Query regarding kernel.shmall value in RHEL 5 (x86_64) mether Red Hat 0 04-07-2008 09:35 AM
Issues with Large SHMALL value s_damarla Linux - General 2 10-29-2004 02:43 PM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 05:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration