I noticed the machine acting a bit sluggish (purely qualitative
assessment), so I ran 'free' to see how much memory is allocated, and
to what - I got the following response:
total used free shared buffers cached
Mem: 255644 213792 41852 0 104976
63904
-/+ buffers/cache: 44912 210732
Swap: 264592 21436 243156
Now, am I correct in interpreting the above as:
1. Of the ~ 256 Mb in the machine, 214 Mb are used, ~42 MB are free.
2. of the 256 MB swap allocated, about 21 Mb is being used (at least,
when I polled the current stauts using free).
When I run meminfo (same box), I get
total: used: free: shared: buffers: cached:
Mem: 261779456 223150080 38629376 0 107950080 72011776
Swap: 270942208 21950464 248991744
MemTotal: 255644 kB
MemFree: 37724 kB
MemShared: 0 kB
Buffers: 105420 kB
Cached: 66860 kB
SwapCached: 3464 kB
Active: 183092 kB
ActiveAnon: 29528 kB
ActiveCache: 153564 kB
Inact_dirty: 4588 kB
Inact_laundry: 7064 kB
Inact_clean: 6312 kB
Inact_target: 40208 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 255644 kB
LowFree: 37724 kB
SwapTotal: 264592 kB
SwapFree: 243156 kB
Roughly the same results - in both cases, a samll amount of swap being
used.
Now, my colleagues tell me that if some swap is being used, I don't
have enough RAM, and that swap should really be a last resort. While I
understand the basic reasoning, I'm wondering if in fact, based on
what 'free' and 'meminfo' tell me whether or not its worth dumping in
another 128 MB or so of RAM?
Yeah, I know, no such thing as too much RAM, but $40 is still $40.
Thanks!
> Now, my colleagues tell me that if some swap is being used, I don't
> have enough RAM, and that swap should really be a last resort. While
> I understand the basic reasoning, I'm wondering if in fact, based on
> what 'free' and 'meminfo' tell me whether or not its worth dumping in
> another 128 MB or so of RAM?
>
I think your colleagues either exaggerate or oversimplify. It really
does not matter how much swap space you use (as long as you have
enough). What really matters is your paging rate. You can get this by
running xosview in a window: very informative -- I let it run
continuously, though I set it to nice 18.
Another way that does not require the windowing system to be up is just
to run vmstat.
When I do that on this machine running at 5 second intervals, I get:
valinux:jdbeyer[~]$ vmstat 5
procs memory swap io system
cpu
r b w swpd free buff cache si so bi bo in cs us
sy id
2 0 0 68252 11200 54192 285136 0 1 10 1 4 17 23
2 6
3 0 0 68252 11756 54196 284548 0 0 0 11 213 672 98
2 0
2 0 0 68252 11756 54200 284548 0 0 0 4 117 326 94
6 0
2 0 0 68252 11756 54200 284548 0 0 0 1 114 363 92
8 0
2 0 0 68252 11756 54200 284548 0 0 0 5 112 280 95
5 0
2 0 0 68252 11184 54200 284548 0 0 0 3 119 446 96
4 0
3 0 0 68252 11000 54200 284548 0 0 0 1 118 392 98
2 0
4 0 0 68252 11076 54200 284548 0 0 0 3 218 738 96
4 0
2 0 0 68252 11380 54208 284584 2 0 9 8 169 737 96
4 0
There is about 68 Megabytes of stuff swapped out, but the pageing rate
is negligeable.
--
.~. Jean-David Beyer Registered Linux User 85642.
/V\ Registered Machine 73926.
/( )\ Shrewsbury, New Jersey http://counter.li.org
^^-^^ 12:15pm up 10 days, 17:48, 3 users, load average: 2.06, 2.10, 2.09
Well, using 24 Mb of swap out of 256 isn't really "using the swap".
Some amount of swap is fine. Besides, you should check the memory
usage and processes not once, but a specific interval, just to
monitor the usage of the machine. If you start seeing the swap
used heavily and always, maybe you should think about adding ram.
From what you posted, it looks to me that your machine isn't overloaded
and is not in real need of more ram.
Of course, this also depends by what are you using the machine for.
If it's a web server, then RAM is important but disk speed is more important,
if it's a database, then RAM is used for caching, so more ram, better
performances (ok, I know, this is reductive and require a deep
analysis).
Davide
[Note line wrapping adjusted from original post]
> total used free shared buffers cached
> Mem: 255644 213792 41852 0 104976 63904
> -/+ buffers/cache: 44912 210732
> Swap: 264592 21436 243156
>
> Now, am I correct in interpreting the above as:
>
> 1. Of the ~ 256 Mb in the machine, 214 Mb are used, ~42 MB are free.
> 2. of the 256 MB swap allocated, about 21 Mb is being used (at least,
> when I polled the current stauts using free).
Also, you have 104MB in buffers and 64MB in the cache. (Last two
columns of the first line.) Those can be dumped to free up space for
other things if needed. So (as the second line says) you effectively
have 210MB free and 45MB used after adjusting for cache and buffers.
It's really those second line figures that count, IMHO.
> Now, my colleagues tell me that if some swap is being used, I don't
> have enough RAM, and that swap should really be a last resort. While I
> understand the basic reasoning, I'm wondering if in fact, based on
> what 'free' and 'meminfo' tell me whether or not its worth dumping in
> another 128 MB or so of RAM?
No, you certainly don't need more RAM based on these figures. As I
said, you're really only using 44912K (about 45MB, first item in the
second line of numbers). Then you've got 168MB in buffers/cache. And
you've still got nearly 42MB free after all that! The 21MB in swap is
stuff that isn't actively being used and got pushed out to swap to make
way for other stuff. It hasn't been needed yet, so it hasn't been
swapped back in. That's a good thing!
Now, all of this assumes that these figures represent the typical
memory load on your system. If they were taken at an unusually lightly
loaded time, things may be different.
My output from vmstat looks like:
procs memory swap io system cpu
r b w swpd free buff cache si so bi bo in cs us sy id
1 0 0 21424 9652 112236 88432 0 0 13 18 5 19 32 1 0
1 0 0 21424 9652 112244 88440 0 0 2 10 116 23 100 0 0
1 0 0 21424 9652 112256 88440 0 0 0 7 104 12 99 1 0
1 0 0 21424 9652 112260 88440 0 0 0 2 102 10 100 0 0
1 0 0 21424 9652 112260 88440 0 0 0 0 102 12 100 0 0
1 0 0 21424 9652 112268 88440 0 0 0 8 113 23 100 0 0
1 0 0 21424 9652 112268 88440 0 0 0 0 102 10 100 0 0
So I seem to be doing OK.
Thanks!
As per my original post, the machine is virtually dedicated to serving: web, and
mySQL (accessed though web apps). Running apache 2.0.45 and mySQL 3.2.xx
>Evan Cooch wrote:
>>
>> I currently am running RH 7.3 on an old PIII box, with 256 MB RAM. The
>> machine basically works as a web and mySQL server.
>>
>> I noticed the machine acting a bit sluggish (purely qualitative
>> assessment), so I ran 'free' to see how much memory is allocated, and
>> to what - I got the following response:
>
>[Note line wrapping adjusted from original post]
Not re-configuration of posting defaults to 80 characters. :-)
>> 1. Of the ~ 256 Mb in the machine, 214 Mb are used, ~42 MB are free.
>> 2. of the 256 MB swap allocated, about 21 Mb is being used (at least,
>> when I polled the current stauts using free).
>
>Also, you have 104MB in buffers and 64MB in the cache. (Last two
>columns of the first line.) Those can be dumped to free up space for
>other things if needed. So (as the second line says) you effectively
>have 210MB free and 45MB used after adjusting for cache and buffers.
>It's really those second line figures that count, IMHO.
OK.
>
>> Now, my colleagues tell me that if some swap is being used, I don't
>> have enough RAM, and that swap should really be a last resort. While I
>> understand the basic reasoning, I'm wondering if in fact, based on
>> what 'free' and 'meminfo' tell me whether or not its worth dumping in
>> another 128 MB or so of RAM?
>
>No, you certainly don't need more RAM based on these figures. As I
>said, you're really only using 44912K (about 45MB, first item in the
>second line of numbers). Then you've got 168MB in buffers/cache. And
>you've still got nearly 42MB free after all that! The 21MB in swap is
>stuff that isn't actively being used and got pushed out to swap to make
>way for other stuff. It hasn't been needed yet, so it hasn't been
>swapped back in. That's a good thing!
>
>Now, all of this assumes that these figures represent the typical
>memory load on your system. If they were taken at an unusually lightly
>loaded time, things may be different.
I'd say fairly typical. Thanks for the insights!
Sorry, I missed that bit (your post was reaaaaaally long).
Whell, MySQL isn't so heavy in ram consumption, and he doesn't do caching
very much, so your machine should be fine. Keep the number of processes and
the general load of the machine under control of course to avoid surprises.
Davide
Just to elaborate a bit, the Linux kernel is designed to use most of the
available RAM for buffers and cache. Thus, few systems will have very
large numbers in the "free" column on the "Mem:" line of "free" output.
Mostly those numbers will be high immediately after booting, then drop as
you use the disk. As John-Paul Stewart says, it's the "-/+ buffers/cache"
numbers that are better indicators of how much RAM is in use.
Swap has a tendency to get used for storage when there's a "burst" in
demand for memory, and then stuff stays in swap if it's not needed again.
It looks like that's what's happened to the OP, with a small amount of
swap space being used (8.1%) and little RAM in use by programs (17.6%).
Of course, a dynamic look at memory use over time is more informative
than a single slice, but if this is typical, there's no need to add more
RAM to this system. If these numbers fluctuate a lot, with frequent
spikes in RAM use, then more RAM might help the system get through those
spike periods.
--
Rod Smith, rods...@rodsbooks.com
http://www.rodsbooks.com
Author of books on Linux, FreeBSD, and networking
> Now, my colleagues tell me that if some swap is being used, I don't
> have enough RAM, and that swap should really be a last resort.
To add to what other replies mentioned, this belief is not valid, at least
for linux swap space as it is currently used. There were systems, such as
the early Windows swap (and maybe early uinces) that did not treat swap
space intelligently, and basically used it as if it were additional RAM
back in the days when real RAM was expensive. Now it is used for
low-priority allocated memory, and does not effect performance
appreciably.
Sometimes a process will spin out of control, such as a large
finite-element calculation, and swap will fill up rapidly. Under those
conditions, yeah, performance will slow to a crawl, but this is not the
fault of the system, but of the computation being performed.
--
David L. Johnson
__o | The trouble with the rat race is that even if you win you're
_`\(,_ | still a rat. --Lilly Tomlin
(_)/ (_) |
Your colleagues *might* be right, but it is not certain.
You might want to run vmstat to see how much *work* swapping is
causing you.
dev6% vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 477244 6836 10692 128032 2 1 5 4 10 1 7 7 85 0
0 0 477244 6688 10700 128176 0 0 26 9 169 715 1 1 97 0
0 0 477244 6552 10708 128304 0 0 26 2 169 747 1 1 97 0
0 0 477244 6404 10724 128436 0 0 28 6 153 683 1 1 97 0
0 0 477244 6396 10732 128436 0 0 0 3 151 661 1 1 97 0
That actually is implying that my machine is using almost all possible
memory; 477 out of 490 MB.
[Rummaging around to restart an Apache process that did something
evil, and a CMU/CL session that I'm not using...]
dev6% vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2 0 88180 475048 7904 110788 2 1 5 4 10 1 7 7 85 0
0 0 88180 475020 7928 110788 0 0 0 38 209 678 2 3 96 0
0 0 88180 475020 7928 110788 0 0 0 0 275 1246 5 2 93 0
0 0 88180 475016 7928 110788 1 0 1 26 161 492 1 2 97 0
0 0 88180 476112 7928 110788 0 0 0 0 130 302 0 0 100 0
System performance hasn't changed. Only once, in the active range, is
there a page swapped in (see the "1" in the "si" column). The system
isn't behaving badly. Indeed, it wasn't before.
What is quite interesting about the stats is that even when I was
invested to the tune of 477MB of swap, there was 128MB of *physical*
memory being used as cache. There lies a *win* in using swap: You
have the code in virtual memory, in case it ever needs to be run, but
get to use the *physical* memory as cache, thereby improving system
performance.
I wouldn't mind tossing in another stick of 512MB of RAM on my box, if
I could, but it would hardly be necessary.
Swapping _is_ bad if you start using it actively. If that happened,
you'd see the "swap" columns have active use, regularly pushing pages
in and out.
But it isn't obvious that that is what you are encountering.
--
let name="cbbrowne" and tld="acm.org" in name ^ "@" ^ tld;;
http://cbbrowne.com/info/languages.html
"The chat program is in public domain. This is not the GNU public
license. If it breaks then you get to keep both pieces."
(Copyright notice for the chat program)
A certain amount of "swap" occurs each time you load a program. So I think
the better bright-line metric is "what is continuously slowing my programs
down?" What, if anything, are they being forced to wait upon that
otherwise they would not be waiting on?
Many systems have ATA disk-drives running off the built-in controller
circuits found on many motherboards. These are _not_ fast. They are
inexpensive. A very fast SCSI controller and corresponding drives can make
a world of difference.