[nycbug-talk] Memory sizing

Francisco Reyes lists at stringsutils.com
Sun Apr 23 13:18:29 EDT 2006


Bjorn Nelson writes:

> bjorn at host=>for i in `ps -axo rss`; do SUM=$(($SUM+$i)); done; echo $SUM
> 893352
> bjorn at host=>for i in `ps -axo vsz`; do SUM=$(($SUM+$i)); done; echo $SUM
> 1166716

Thanks for the mini scripts. Very usefull.

> top shows currently:
> Mem: 92M Active, 111M Inact, 56M Wired, 13M Cache, 38M Buf, 804K Free
> Swap: 512M Total, 684K Used, 511M Free
> 
> bjorn at host=>vmstat 1
> procs      memory      page                   disk   faults      cpu
> r b w     avm    fre  flt  re  pi  po  fr  sr ad0   in   sy  cs us sy id
> 1 8 1  191568  16864   28   0   0   0 266 240   0 1341 1867 623 22  5 73
> 1 8 0  193012  15392   92   0   4   0 414   0  65 1400 1944 742 18  9 73
> 
> So far I see that my host has 56M wired mostly for the kernel, 92M  
> for active processes and 111M inactive for sleeping processes.  Maybe  
> someone can pipe in about the difference between Cache and Buf, man 1  
> top says that one is VM and the other is BIO based, McKusick's book  
> says that FreeBSD buffering using the VM system, so I am assuming BIO  
> is external to the VM system but not sure how.  Is this the hard  
> drive's cache?
> 
> 8 processes are blocking probably contending for vm resources to get  
> freed up.  I am paging in and freeing a bunch of resources during  
> this cycle.

The 'r' column in vmstat from what I have read is number of processes 
waiting for CPU and the 'b' column is number of pending transactions waiting 
to get done.

Also I believe the vmstat numbers depend on some variables that are updated 
every 5 secons so any number below 5 will not be all that meaninfull. Best 
explanation of vmstat I have found is Absolute BSD by Michael Lucas (page 
432 onward).

Ok I am with you so far.
Specially I think I mostly get/understand/agree with the meaning of active, 
inactive and wired.
If we tally up those numbers:
92  Active
111 Inact
56  Wired
13  Cache
38  Buf
 1  Free (rounded)
---
311  

 
> this is pretty much due to vm swapping:
> bjorn at host=>ps -axo inblock,oublock,comm | sort -n -k 2 | tail -3
>    325  1152 ntpd
>      0  8695 bufdaemon
> 69360 5017287 syncer

Can you explain that a little more please?
Inblock and outblook is what? The read and written by and app?
Man page has:
inblk      total blocks read (alias inblock)
oublk      total blocks written (alias oublock)
 
> regardless, major faults show that my webserver is paging in the most.

I will have to readup on those two keywords.
>From man page...
majflt     total page faults
minflt     total page reclaims

Is a page fault basically reading from swap?
Re-reading the vmstat section on absolute BSD as I type this. :)
I think I am for the most part clear on majflt.
minflt seems simmilar to 're' in vmstat..
"shows how many pages have been reclaimed or reused from cache (Absolute BSD 
page 434).

What is that "cache" referred to by the book?


> bjorn at host=>ps -axo majflt,minflt,comm | sort -n -k 1 | tail -5
>      18    394 sshd
>      19   1746 named
>      24  18078 python
>      41    220 httpd
>     128  22273 httpd

You say your server is mostly "pagin in". Again from Absolute BSD page 434
pi "Short for pages in, it shows how many pages are moving from physical 
memory to swap"..

So page in is going into swap.. and major fault is coming out from swap?
Hm..
Look at this output from one of my machines:
ps -axo majflt,minflt,comm | grep -v "   0      0 " | sort -n -k
.... lines of interest ....
MAJFLT MINFLT COMMAND
106    1717796  mysqld
 1    142441891 bacula-fd 

> minor faults show that my mail and imap servers are reclaiming from  
> the inactive memory pool.  These process are probably the most active  
> since they don't have a high number of minfaults but not major faults.

That was going to be my next question. :-)
Ok.. so those processes above are hitting "Inactive" memory. I wish they had 
used a different name.. doesn't sound like that memory is inactive at all. 
:-)

The memory for the machine running bacula is
Mem: 333M Active, 2269M Inact, 301M Wired, 104M Cache, 112M Buf, 4564K Free

swapinfo
Device          1K-blocks     Used    Avail Capacity
/dev/da0s1b       6291456      216  6291240     0%

So basically the Inact pool is what is getting used the most. Specially 
given all the minfaults and few major faults.. plus swap rarely used.
  
> The result of this is that I would probably be fine with a gig of  
> ram.

Only two pieces of info I didn't see.
What is the amount of physical memory? What is your "swapinfo"?

> Francisco, can  you apply this to what you are contending with?

Absolutely!
In particular you put in content info I had read from the Absolute BSD.
It is one thing to see explanations and another to see them in context.



More information about the talk mailing list