LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   TOP command: calculation of memory usage (http://www.linuxquestions.org/questions/linux-server-73/top-command-calculation-of-memory-usage-658835/)

samiralmousawi 07-28-2008 03:02 PM

TOP command: calculation of memory usage
 
1. How can I calculate Memory usage that appears in the 'top' command in the top part, using the details shown in the processes table. When I try to sum up, using Excel, the processes memory percentage or VIRT, they do NOT add up to the amount shown in the top part for 'Mem'. I need to know which process is filling up Memory usage. Below is the whole dump:

top - 08:57:03 up 2 days, 12:12, 1 user, load average: 0.08, 0.08, 0.05
Tasks: 125 total, 2 running, 123 sleeping, 0 stopped, 0 zombie
Cpu(s): 1.3% us, 0.1% sy, 0.0% ni, 98.2% id, 0.3% wa, 0.0% hi, 0.0% si
Mem: 8164332k total, 3232068k used, 4932264k free, 507500k buffers
Swap: 16777208k total,0k used, 16777208k free, 1036236k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1370 www 15 0 6144 936 696 R 2 0.0 0:00.01 top
1 root 16 0 4752 556 460 S 0 0.0 0:00.99 init
2 root RT 0 0 0 0 S 0 0.0 0:00.16 migration/0
3 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/0
4 root RT 0 0 0 0 S 0 0.0 0:00.12 migration/1
5 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/1
6 root RT 0 0 0 0 S 0 0.0 0:00.14 migration/2
7 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/2
8 root RT 0 0 0 0 S 0 0.0 0:00.08 migration/3
9 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/3
10 root 5 -10 0 0 0 S 0 0.0 0:00.14 events/0
11 root 5 -10 0 0 0 S 0 0.0 0:00.00 events/1
12 root 5 -10 0 0 0 S 0 0.0 0:00.01 events/2
13 root 5 -10 0 0 0 S 0 0.0 0:00.03 events/3
14 root 5 -10 0 0 0 S 0 0.0 0:00.01 khelper
15 root 15 -10 0 0 0 S 0 0.0 0:00.00 kacpid
70 root 5 -10 0 0 0 S 0 0.0 0:00.00 kblockd/0
71 root 5 -10 0 0 0 S 0 0.0 0:00.00 kblockd/1
72 root 5 -10 0 0 0 S 0 0.0 0:00.00 kblockd/2
73 root 5 -10 0 0 0 S 0 0.0 0:00.00 kblockd/3
74 root 15 0 0 0 0 S 0 0.0 0:00.12 khubd
101 root 20 0 0 0 0 S 0 0.0 0:00.00 pdflush
102 root 15 0 0 0 0 S 0 0.0 0:01.27 pdflush
105 root 12 -10 0 0 0 S 0 0.0 0:00.00 aio/0
103 root 25 0 0 0 0 S 0 0.0 0:00.00 kswapd1
104 root 25 0 0 0 0 S 0 0.0 0:00.00 kswapd0
106 root 5 -10 0 0 0 S 0 0.0 0:00.00 aio/1
107 root 5 -10 0 0 0 S 0 0.0 0:00.00 aio/2
108 root 5 -10 0 0 0 S 0 0.0 0:00.00 aio/3
252 root 23 0 0 0 0 S 0 0.0 0:00.00 kseriod
400 root 7 -10 0 0 0 S 0 0.0 0:00.00 kmirrord
423 root 15 0 0 0 0 S 0 0.0 0:01.08 kjournald
1705 root 6 -10 3604 444 364 S 0 0.0 0:00.01 udevd
2336 root 6 -10 0 0 0 S 0 0.0 0:00.00 kauditd
2472 root 15 0 0 0 0 S 0 0.0 0:00.00 emcpd
2473 root 15 0 0 0 0 S 0 0.0 0:00.00 emcpdefd
2474 root 19 0 0 0 0 S 0 0.0 0:00.00 emcprequestd
2646 root 20 0 0 0 0 S 0 0.0 0:00.00 MpxAsyncIoDaemo
2647 root 20 0 0 0 0 S 0 0.0 0:00.00 MpxResumeIoDaem
2648 root 15 0 0 0 0 S 0 0.0 0:00.00 MpxPeriodicCall
2649 root 20 0 0 0 0 S 0 0.0 0:00.00 MpxGrDaemon
2650 root 20 0 0 0 0 S 0 0.0 0:00.00 MpxProactiveDae
2651 root 20 0 0 0 0 S 0 0.0 0:00.00 MpxDispatchDaem
2652 root 20 0 0 0 0 S 0 0.0 0:00.00 MpxTestDaemon
2725 root 5 -10 0 0 0 S 0 0.0 0:00.00 kmpathd/0
2726 root 5 -10 0 0 0 S 0 0.0 0:00.00 kmpathd/1
2727 root 5 -10 0 0 0 S 0 0.0 0:00.00 kmpathd/2
2728 root 8 -10 0 0 0 S 0 0.0 0:00.00 kmpathd/3
2756 root 15 0 0 0 0 S 0 0.0 0:00.14 kjournald
2757 root 15 0 0 0 0 S 0 0.0 0:00.00 kjournald
2758 root 15 0 0 0 0 S 0 0.0 0:00.00 kjournald
2759 root 15 0 0 0 0 S 0 0.0 0:00.74 kjournald
2760 root 15 0 0 0 0 S 0 0.0 0:00.01 kjournald
2761 root 15 0 0 0 0 S 0 0.0 0:00.59 kjournald
2762 root 15 0 0 0 0 S 0 0.0 0:05.38 kjournald
2763 root 15 0 0 0 0 S 0 0.0 0:05.11 kjournald
3151 root 15 0 2528 276 208 S 0 0.0 0:03.74 cpuspeed
3152 root 15 0 2528 272 204 S 0 0.0 0:03.33 cpuspeed
3153 root 15 0 2528 272 204 S 0 0.0 0:02.75 cpuspeed
3154 root 15 0 2528 272 204 S 0 0.0 0:07.42 cpuspeed
3469 root 16 0 3628 608 496 S 0 0.0 0:00.64 syslogd
3473 root 16 0 2536 376 300 S 0 0.0 0:00.00 klogd
3484 root 16 0 2548 304 204 S 0 0.0 0:00.05 irqbalance
3496 rpc 16 0 4748 588 464 S 0 0.0 0:00.00 portmap
3516 root 17 0 5800 748 624 S 0 0.0 0:00.00 rpc.statd
3548 root 16 0 20916 392 188 S 0 0.0 0:00.00 rpc.idmapd
3733 root 19 0 2540 448 360 S 0 0.0 0:00.00 acpid
3747 root 16 0 6092 1876 532 S 0 0.0 0:00.00 perl
3794 root 16 0 21920 1268 856 S 0 0.0 0:04.97 sshd
3809 root 15 0 8712 828 656 S 0 0.0 0:00.00 xinetd
3827 ntp 15 0 18560 5296 4228 S 0 0.1 0:00.01 ntpd
3837 root 18 0 19544 1336 1020 S 0 0.0 0:00.00 vsftpd
3856 root 16 0 34996 2552 1092 S 0 0.0 0:00.01 sendmail
3864 smmsp 15 0 27788 1908 840 S 0 0.0 0:00.00 sendmail
3875 root 15 0 4176 348 268 S 0 0.0 0:00.00 gpm
4058 root 15 0 96100 5544 2604 S 0 0.1 0:00.16 hpsmhd
4059 root 16 0 18776 1204 884 S 0 0.0 0:00.00 rotatelogs
4061 root 20 0 18776 1200 880 S 0 0.0 0:00.00 rotatelogs
4070 root 16 0 57072 952 536 S 0 0.0 0:00.15 crond
4079 hpsmh 18 0 364m 4364 1280 S 0 0.1 0:00.00 hpsmhd
4131 xfs 16 0 10228 1736 808 S 0 0.0 0:00.01 xfs
4161 root 15 0 285m 9628 4888 S 0 0.1 0:10.40 ovcd
4169 root 16 0 93996 6184 4020 S 0 0.1 0:06.91 ovbbccb
4188 root 15 0 92452 8960 5800 S 0 0.1 0:14.04 opcmsga
4190 root 16 0 96372 6424 4700 S 0 0.1 0:00.10 ovconfd
4212 root 16 0 28768 7440 4960 S 0 0.1 0:00.08 opcacta
4214 root 15 0 112m 7884 5736 S 0 0.1 0:02.83 coda
4219 root 18 0 17304 6928 4524 S 0 0.1 0:00.03 opcmsgi
4222 root 15 0 17396 7136 4688 S 0 0.1 0:00.74 opcle
4226 root 15 0 19884 7680 5192 S 0 0.1 0:00.12 opcmona
4244 root 16 0 8912 420 292 S 0 0.0 0:00.00 atd
4264 dbus 16 0 9644 788 616 S 0 0.0 0:00.07 dbus-daemon-1
4412 root 16 0 2876 1856 980 S 0 0.0 0:00.00 p_ctmag
4581 root 16 0 2868 1824 956 S 0 0.0 0:00.01 p_ctmat
4610 root 16 0 8992 932 776 S 0 0.0 0:00.00 cups-config-dae
4621 root 15 0 20184 7384 1272 S 0 0.1 1:38.28 hald
4638 root 15 0 4820 1660 1396 R 0 0.0 0:00.03 mstragent
4732 root 16 0 15312 2528 1980 S 0 0.0 0:00.10 mstragent
4770 root 16 0 55752 8556 5300 S 0 0.1 0:44.37 tlmagent
4973 root 18 0 2524 404 336 S 0 0.0 0:00.00 mingetty
4974 root 18 0 2524 404 336 S 0 0.0 0:00.00 mingetty
4975 root 18 0 2524 404 336 S 0 0.0 0:00.00 mingetty
4976 root 18 0 2524 404 336 S 0 0.0 0:00.00 mingetty
4978 root 21 0 2524 404 336 S 0 0.0 0:00.00 mingetty
4981 root 18 0 2524 404 336 S 0 0.0 0:00.00 mingetty
4982 root 15 0 90144 2900 2316 S 0 0.0 0:00.03 gdm-binary
5662 root 16 0 102m 2508 1812 S 0 0.0 0:00.00 gdm-binary
5672 root 15 0 58056 11m 2676 S 0 0.1 0:05.28 X
5775 root 16 0 31312 2704 1772 S 0 0.0 0:00.00 dsmcad
5783 gdm 15 0 123m 11m 6740 S 0 0.1 0:00.62 gdmgreeter
6176 www 15 0 500m 143m 16m S 0 1.8 3:56.92 java
17994 www 18 0 52756 1100 904 S 0 0.0 0:00.00 startPortalServ
17996 www 16 0 1593m 289m 30m S 0 3.6 32:01.04 java
18095 www 18 0 52756 1088 904 S 0 0.0 0:00.00 startJMSServer.
18097 www 17 0 901m 151m 23m S 0 1.9 14:11.92 java
18386 www 18 0 52756 1100 904 S 0 0.0 0:00.00 startEjbServer.
18388 www 15 0 1586m 322m 34m S 0 4.0 60:01.31 java
29526 root 16 0 71116 2156 1592 S 0 0.0 0:00.00 cupsd
32292 root 17 0 73036 1280 768 S 0 0.0 0:00.00 crond
32295 root 18 0 5356 912 776 S 0 0.0 0:00.00 sh
32296 root 16 0 13384 1716 1344 S 0 0.0 0:00.00 perl
32305 root 16 0 3636 532 440 S 0 0.0 0:00.00 vmstat
1333 root 16 0 38124 2604 2036 S 0 0.0 0:00.02 sshd
1337 www 16 0 38256 1836 1240 S 0 0.0 0:00.00 sshd
1338 www 16 0 53976 1608 1204 S 0 0.0 0:00.02 bash

AlucardZero 07-28-2008 03:31 PM

see here and here

Press "M" in top to sort by memory usage.

also, you have 5GB memory free.

samiralmousawi 07-28-2008 04:12 PM

Thanks for the reply but please read question carefully, I need to know how to calculate Mem usage (using the process details in the 'top' command output. ie, the table of processes). I did sort by M or using < to sort by VIRT or by RES, but that does not give me what I need, again, I need to know how is the 'Mem' entry in the top part of the 'top' command is calculated.

syg00 07-28-2008 06:19 PM

The summary info isn't calculated, it's read from /proc, just like all the other data in top. As such you have to assume it is correct - at lest as far as the kernel is concerned.
You can't expect the sum of the parts (that you can see) will equal the total used, but if you insist, subtract the cached and buffers numbers from used and try again.
Do some searching - there are hundreds of threads that explain why this math is necessary.

awk would be an easy way to mangle the numbers without having to use a spreadsheet.

chrism01 07-28-2008 09:44 PM

You only seem to be using approx 3GB out of 8GB (and no swap), so why are you worried?

samiralmousawi 07-28-2008 10:56 PM

Thanks for the replies. Actually the dump of 'top' command i pasted in my original message is when the system is healthy. Yet I would like to know how the some of parts would add up to the total, because the server keeps chalking approximately two weeks after a reboot and we can't tell which process is causing this. Our Linux guys are blaming the Java application saying that even killing Java processes doesn't clear up all the threads !!! The application guys saying after killing Java processes, memory should be cleared up.

If you know of threads that would explain those details, a link to the thread(s) would be great. Thanks

chrism01 07-29-2008 03:51 AM

Quote:

chalking
????

maybe you mean choking?

Anyway, I'd start by writing a simple daemon or cron job to keep an eye on the System Load and or/Mem figures and alert you as to when it 'chokes'.
Then either eyeball it or check the logs for msgs around that time, pref both.
Remember with Linux that killing a job/jobs doesn't automatically clear the mem, it simply enables the kernel to re-use that mem when it needs it for something else.

AlucardZero 07-29-2008 04:16 PM

Please read my links and pay attention to the parts about memory reporting, esp. shared libraries etc, as that is why it does not add up.


All times are GMT -5. The time now is 03:47 AM.