LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-08-2014, 11:29 AM   #1
gilperon
LQ Newbie
 
Registered: May 2014
Posts: 7

Rep: Reputation: Disabled
CentOS reporting wrong actual ram memory used


Hi,

I am sunning CENTOS 6.5 and I was surprised why my memory usage is so high. I executed top command and everything looks fine. After sum all the %MEM column I got the value of 32% but my memory used is about 90%! I have no idea why CENTOS is reporting the memory usage so wrong!

Bellow is my top command. You see it says I am using 1836776k of 2040900k (total) = 90%. So it says I am using 90% of total memory. BUT if I sum all %MEM lines it results 30% not 90%. Where is the 60% being used if it does not appear in the top report?

Thank you all. I am really new in Linux but I am studying as hard as possible but some questions like these still remain with no answer to me.

Code:
top - 16:11:50 up 21:52, 2 users, load average: 0.31, 0.34, 0.33
Tasks: 112 total, 1 running, 111 sleeping, 0 stopped, 0 zombie
Cpu(s): 32.4%us, 3.3%sy, 0.0%ni, 63.6%id, 0.3%wa, 0.0%hi, 0.3%si, 0.1%st
Mem: 2040900k total, 1836776k used, 204124k free, 205184k buffers
Swap: 262140k total, 18644k used, 243496k free, 802988k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 
30888 apache 20 0 317m 29m 4224 S 6.0 1.5 0:18.95 httpd 
30891 apache 20 0 317m 29m 4168 S 6.0 1.5 0:19.93 httpd 
30892 apache 20 0 318m 30m 3992 S 6.0 1.5 0:19.34 httpd 
31025 apache 20 0 316m 27m 3908 S 6.0 1.4 0:16.06 httpd 
30894 apache 20 0 316m 29m 3980 S 4.0 1.5 0:18.62 httpd 
30899 apache 20 0 317m 29m 4084 S 4.0 1.5 0:19.07 httpd 
30916 apache 20 0 316m 28m 4048 S 4.0 1.4 0:19.24 httpd 
31027 apache 20 0 316m 28m 4112 S 4.0 1.4 0:16.98 httpd 
31011 apache 20 0 316m 28m 4024 S 2.0 1.4 0:16.80 httpd 
1 root 20 0 19284 284 160 S 0.0 0.0 0:00.92 init 
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 
3 root 20 0 0 0 0 S 0.0 0.0 0:04.97 ksoftirqd/0 
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 
7 root 20 0 0 0 0 S 0.0 0.0 1:20.39 rcu_sched 
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 
9 root RT 0 0 0 0 S 0.0 0.0 0:00.02 migration/0 
10 root RT 0 0 0 0 S 0.0 0.0 0:00.09 migration/1 
11 root 20 0 0 0 0 S 0.0 0.0 0:00.85 ksoftirqd/1 
13 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H 
14 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 khelper 
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs 
16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns 
20 root 20 0 0 0 0 S 0.0 0.0 0:00.00 xenwatch 
21 root 20 0 0 0 0 S 0.0 0.0 0:00.00 xenbus 
207 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback 
209 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset 
211 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd 
228 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md 
313 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 rpciod 
388 root 20 0 0 0 0 S 0.0 0.0 0:25.53 kswapd0 
455 root 20 0 0 0 0 S 0.0 0.0 0:00.00 fsnotify_mark 
483 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ecryptfs-kthrea 
485 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 nfsiod 
493 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 cifsiod 
506 root 20 0 0 0 0 S 0.0 0.0 0:00.00 jfsIO 
507 root 20 0 0 0 0 S 0.0 0.0 0:00.00 jfsCommit 
508 root 20 0 0 0 0 S 0.0 0.0 0:00.00 jfsCommit 
509 root 20 0 0 0 0 S 0.0 0.0 0:00.00 jfsSync 
518 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 xfsalloc 
519 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 xfs_mru_cache 
520 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 xfslogd 
521 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 glock_workqueue 
522 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 delete_workqueu 
528 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 gfs_recovery 
533 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto 
1105 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khvcd 
1197 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset 
1198 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 drbd-reissue 
1216 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kpsmoused 
1218 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 raid5wq 
1221 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 dm_bufio_cache 
1245 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ipv6_addrconf 
1272 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset 
1291 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 deferwq 
1294 root 0 -20 0 0 0 S 0.0 0.0 0:18.38 kworker/0:1H 
1295 root 20 0 0 0 0 S 0.0 0.0 0:02.47 kjournald 
1353 root 16 -4 10824 0 0 S 0.0 0.0 0:00.06 udevd 
1549 root 18 -2 10820 0 0 S 0.0 0.0 0:00.00 udevd 
1578 root 20 0 0 0 0 S 0.0 0.0 0:03.14 kjournald 
1610 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kauditd 
1797 root 20 0 9172 612 472 S 0.0 0.0 0:00.00 dhclient 
1849 root 20 0 243m 1680 320 S 0.0 0.1 1:23.58 rsyslogd 
1882 root 20 0 66660 236 152 S 0.0 0.0 0:01.30 sshd 
1890 ntp 20 0 30772 596 460 S 0.0 0.0 0:00.96 ntpd 
1901 root 20 0 52584 0 0 S 0.0 0.0 0:00.00 vsftpd 
2154 root 20 0 114m 468 388 S 0.0 0.0 0:00.42 crond 
2169 root 20 0 4116 0 0 S 0.0 0.0 0:00.00 mingetty 
2170 root 20 0 4116 0 0 S 0.0 0.0 0:00.00 mingetty 
2172 root 20 0 4116 0 0 S 0.0 0.0 0:00.00 mingetty 
2175 root 20 0 4116 0 0 S 0.0 0.0 0:00.00 mingetty 
2177 root 20 0 4116 0 0 S 0.0 0.0 0:00.00 mingetty 
2179 root 20 0 4116 0 0 S 0.0 0.0 0:00.00 mingetty 
2181 root 20 0 4116 0 0 S 0.0 0.0 0:00.00 mingetty 
9980 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:1H 
12734 root 20 0 0 0 0 S 0.0 0.0 0:01.08 kworker/1:0 
13479 root 20 0 105m 1284 1284 S 0.0 0.1 0:00.01 mysqld_safe 
13584 mysql 20 0 1125m 38m 5020 S 0.0 1.9 10:25.54 mysqld 
20161 root 20 0 0 0 0 S 0.0 0.0 0:01.71 kworker/0:2 
25797 root 20 0 0 0 0 S 0.0 0.0 0:05.27 kworker/u4:1 
26796 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:1 
27254 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u4:0 
29399 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/1:1 
30288 root 20 0 98.1m 4468 3480 S 0.0 0.2 0:00.14 sshd 
30290 root 20 0 105m 1960 1516 S 0.0 0.1 0:00.03 bash 
30329 root 20 0 98.1m 4180 3188 S 0.0 0.2 0:00.02 sshd 
30334 root 20 0 57732 2276 1620 S 0.0 0.1 0:00.01 sftp-server 
30385 root 20 0 98.1m 4196 3188 S 0.0 0.2 0:00.02 sshd 
30387 root 20 0 57732 2272 1620 S 0.0 0.1 0:00.00 sftp-server 
30793 root 20 0 98.1m 4196 3188 S 0.0 0.2 0:00.02 sshd 
30797 root 20 0 57864 2308 1620 S 0.0 0.1 0:00.01 sftp-server 
30885 root 20 0 310m 23m 5736 S 0.0 1.2 0:00.22 httpd 
30887 apache 20 0 316m 28m 4036 S 0.0 1.4 0:18.84 httpd 
30889 apache 20 0 316m 28m 4200 S 0.0 1.4 0:19.14 httpd 
30890 apache 20 0 317m 29m 4072 S 0.0 1.5 0:18.65 httpd 
30893 apache 20 0 316m 29m 4172 S 0.0 1.5 0:19.65 httpd 
30905 apache 20 0 316m 28m 4188 S 0.0 1.4 0:19.73 httpd 
30926 root 20 0 98.1m 4196 3188 S 0.0 0.2 0:00.02 sshd 
30928 root 20 0 57848 2296 1620 S 0.0 0.1 0:00.15 sftp-server 
31001 apache 20 0 316m 28m 4016 S 0.0 1.4 0:19.62 httpd 
31021 root 20 0 15080 1328 1008 S 0.0 0.1 0:00.98 top 
31028 apache 20 0 316m 28m 3876 S 0.0 1.4 0:15.59 httpd 
31372 root 20 0 98.1m 4468 3480 S 0.0 0.2 0:00.03 sshd 
31381 root 20 0 105m 1976 1516 S 0.0 0.1 0:00.01 bash 
31689 root 20 0 81336 3388 2484 S 0.0 0.2 0:00.02 master 
31691 postfix 20 0 81416 3268 2412 S 0.0 0.2 0:00.00 pickup 
31692 postfix 20 0 81484 3296 2444 S 0.0 0.2 0:00.00 qmgr 
31768 postfix 20 0 84304 4620 3192 S 0.0 0.2 0:00.00 smtpd 
31770 postfix 20 0 81408 3272 2404 S 0.0 0.2 0:00.00 anvil 
31801 apache 20 0 315m 27m 3512 S 0.0 1.4 0:02.85 httpd 
31827 postfix 20 0 81756 3912 2816 S 0.0 0.2 0:00.00 cleanup 
31873 postfix 20 0 81620 3660 2724 S 0.0 0.2 0:00.00 smtp 
31892 root 20 0 15076 1172 880 R 0.0 0.1 0:00.00 top

Last edited by colucix; 05-08-2014 at 11:53 AM. Reason: Added CODE tags to improve readability.
 
Old 05-08-2014, 11:56 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
A lot of memory is shared, so it is not meaningful to sum the %MEM column. Your true memory use by those processes is less than that 30%.

The "used" value where you see 1836776k is even less meaningful. It includes buffers and cache, which for practical purposes are kinds of free memory.

Last edited by johnsfine; 05-08-2014 at 12:01 PM.
 
Old 05-08-2014, 11:58 AM   #3
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 7
Posts: 3,532

Rep: Reputation: 974Reputation: 974Reputation: 974Reputation: 974Reputation: 974Reputation: 974Reputation: 974Reputation: 974
Unused memory is wasted. Linux tries to keep all memory in use as disk cache. It can be freed when any process needs memory.
 
Old 05-08-2014, 12:02 PM   #4
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,585

Rep: Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351Reputation: 2351
I think this is obligatory?
http://www.linuxatemyram.com/
 
2 members found this post helpful.
Old 05-08-2014, 12:04 PM   #5
gilperon
LQ Newbie
 
Registered: May 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Yes I know

yes now I know that, thank you. I executed "free" and I see 80% of my memory is indeed free but why it shows a lot of swap memory being used if I am plenty of free phisical memory?
 
Old 05-08-2014, 12:12 PM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by gilperon View Post
but why it shows a lot of swap memory being used if I am plenty of free phisical memory?
Use of swap memory is another topic misunderstood by almost everyone.

It is normal and appropriate for a Linux system to use some swap space even though it has plenty of usable ram.

Many service processes have significant amounts of stale anonymous memory: Things used only during initialization that they didn't clean up well. Or things initialized on startup that won't be used again until shutdown. Stale anonymous memory has less value in ram than file cache. The OS will detect that and will swap out the stale anonymous memory to make room for more file caching.
 
Old 05-08-2014, 12:16 PM   #7
gilperon
LQ Newbie
 
Registered: May 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thank you! You are awesome!
 
Old 05-08-2014, 07:52 PM   #8
jefro
Moderator
 
Registered: Mar 2008
Posts: 20,677

Rep: Reputation: 3333Reputation: 3333Reputation: 3333Reputation: 3333Reputation: 3333Reputation: 3333Reputation: 3333Reputation: 3333Reputation: 3333Reputation: 3333Reputation: 3333
You can adjust how the swap file, partition or swap raid uses space by a few means. One is swappiness.

As above, some apps just seem to take swap. It is even sometimes hard to clear it.

Some interesting tricks here too. https://wiki.archlinux.org/index.php...e#RAM_and_swap
 
Old 05-08-2014, 08:24 PM   #9
gilperon
LQ Newbie
 
Registered: May 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Great link!
 
Old 05-09-2014, 06:32 AM   #10
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by jefro View Post
You can adjust how the swap file, partition or swap raid uses space by a few means. One is swappiness.
Most people who adjust swappiness do so based on a fundamental misunderstanding of swapping and reduce swappiness when they shouldn't, and by doing so make their systems slightly slower.

Correct adjustment of swappiness should be based on the relative speed of a single read from the media where programs and commonly used files are stored compared to a write plus a read on the media where swap is located.

The traditional default value of swappiness was chosen for the common hard drive situation in which a write plus a read takes twice as long as just a read. Lower values of swappiness are appropriate for media (such as SSD) in which a write plus a read is much more than twice as much as a read alone. I think some Linux installers detect that and lower swappiness for you in that case.

But selecting a much lower swappiness, so you get less swapping, only seems like a good idea because you misunderstand swapping. You should set it lower than the default only if the installer failed to recognize that write+read on your swap media is more than double the time of read on your program and file media.
 
Old 05-09-2014, 06:36 AM   #11
gilperon
LQ Newbie
 
Registered: May 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
I see some places that tells me to create a swap with twice as big as my RAM available but I think it's strange cause when I install my centos it recommends only 256MB of swap and the same happens in linode! Why is the great difference in the recomendation?
 
Old 05-09-2014, 06:54 AM   #12
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by gilperon View Post
I see some places that tells me to create a swap with twice as big as my RAM available but I think it's strange cause when I install my centos it recommends only 256MB of swap and the same happens in linode! Why is the great difference in the recomendation?
The amount of swap you ought to have depends on how you use the system. But disk space is cheap, so you don't need to put a lot of analysis into deciding on the amount of swap space. Just set up more than you need.

The old rule of swap equals double ram was stupid even when it was popular. It was based on old systems that had somewhere between seriously too little ram and desperately too little ram. But it still ignored how much swap depends on type of use. Now that ram is typically sufficient for the intended use of a system and disk is cheaper, I prefer a simpler rule:

Swap size should be 2GB for almost all systems. It does not depend on ram size. If you have 500MB of ram, you are just as likely to need 2GB of swap as if you have 32GB of ram. There are rare systems that need more swap (mine do). There are rare systems that can't be upgraded to decent disk drives, so every GB of disk counts and you can't afford 2GB of swap. In between, just make it 2GB and don't worry about it until you see a problem.

If you have a well managed typical usage server and nothing goes wrong in memory use, you won't ever use even 256MB of swap, so having 256MB is enough. Having 2GB instead is a low cost safety valve in case things do go wrong in memory use (gets you some graceful degradation and warning symptoms, rather fast undiagnosable failure). You expect that 2GB will never be used (like your home fire insurance). As long as 2GB of disk space is a very low cost waste, it has value as insurance.

Last edited by johnsfine; 05-09-2014 at 07:00 AM.
 
Old 05-09-2014, 07:33 AM   #13
gilperon
LQ Newbie
 
Registered: May 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thank you so much! You are so helpful!

You are very clear and you explained a question that I have for at least 6 months and no website could explain it clear with so sure!

But I have a final question (dont want to abuse of your kindness): can I estimate the amount of swap that I need to set using the top command? Let me explain: when I run "top" I see only 10MB of my 256MB are being used as swap. I check it at least 5 times a day among other things like free RAM. It never passed over 15MB. Even tough should I use more RAM if it never passes 10MB? Should not it be smarter to people first detect the amount of swap (using top, for example) during a few days of experiment and at the end conclude the final amount of swap that was really needed? Or should I assume that "top" does not provide real and conclusive information about the swap and I should not rely on it?
 
Old 05-09-2014, 11:26 AM   #14
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,535

Rep: Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077
That just means that you have never really needed swap at all. The kernel has always had plenty of non-dirty buffer and cache pages of sufficient age that it could use to satisfy memory requests. Those 10MB to 15MB of pages that you see in swap are pages that were allocated by some long-running processes at startup and then never referenced again. Eventually the kernel notices that and pushes them out to swap in favor of using that memory for buffer/cache space.
 
Old 05-09-2014, 07:42 PM   #15
gilperon
LQ Newbie
 
Registered: May 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Amazing! THANK YOU SO MUCH! You were very clear! You are very nice guys, thank you so much!
 
  


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
[SOLVED] Wrong RAM memory information at BIOS and Linux felipefv Linux - Hardware 5 11-04-2010 09:02 PM
How to get the each process actual RAM memory usage in linux 2.6.21 or higher version rangrej25 Linux - General 2 02-08-2010 07:46 AM
Odd reporting of total RAM dockpunk Slackware 7 02-11-2009 08:42 AM
"free -m" reporting wrong amount of RAM Ryand833 Linux - Hardware 3 08-23-2007 08:59 PM
Top not reporting full ram satinet Linux - Hardware 5 02-05-2006 03:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:01 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