How to get the number of swapped out LWPs in linux - linux

I use vmstat | head -3 in Solaris to check the process situation and get this
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr s4 s5 -- -- in sy cs us sy id
0 0 0 100548720 6357568 219 3300 0 0 0 0 0 8 0 0 0 2193 6771 2256 0 1 98
the w means the number of swapped out lightweight processes (LWPs) that are waiting for processing resources to finish. We use this data to monitor system conditions.
But running the command in Redhat get this result
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu -----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 784968 348724 28 44781148 0 1 16 49 7 9 1 0 98 1 0
The w in column 3 is missing, I try to find a replacement in another command
use the top command
top - 20:28:12 up 5 days, 22:24, 7 users, load average: 0.02, 0.03, 0.06
Tasks: 725 total, 1 running, 724 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.0 id, 0.3 wa, 0.1 hi, 0.1 si, 0.0 st
MiB Mem : 48087.3 total, 301.6 free, 4029.0 used, 43756.7 buff/cache
MiB Swap: 16384.0 total, 15617.9 free, 766.1 used. 3496.9 avail Mem
1 running is not the data I need
Use the ps -efL | head -3 command
UID PID PPID LWP C NLWP STIME TTY TIME CMD
root 1 0 1 0 1 Jun 22 ? 00:00:22 /usr/lib/systemd/systemd --switched-root --system --deserialize 18
root 2 0 2 0 1 Jun 22 ? 00:00:00 [kthreadd]
The NLWP here is also not the data I need
Is there any way to get the same data as the w column of vmstat in solaris?

Related

Top Command: How come CPU% in process is higher than in overall CPU Usage Percentage

How come CPU% in process is higher than in overall CPU Usage Percentage
top - 19:42:24 up 68 days, 19:49, 6 users, load average: 439.72, 540.53, 631.13
Tasks: 354 total, 3 running, 350 sleeping, 0 stopped, 1 zombie
Cpu(s): 21.5%us, 46.8%sy, 0.0%ni, 17.4%id, 0.0%wa, 0.1%hi, 14.2%si, 0.0%st
Mem: 65973304k total, 50278472k used, 15694832k free, 28749456k buffers
Swap: 19455996k total, 93436k used, 19362560k free, 14769728k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4425 ladm 20 0 63.6g 211m 1020 S **425.7** 0.3 433898:26 zzz
28749 isdm 20 0 167g 679m 7928 S 223.7 1.1 2526:40 xxx
28682 iadm 20 0 167g 1.1g 7928 S 212.8 1.8 2509:08 ccc
28834 iladm 20 0 11.8g 377m 7968 S 136.3 0.6 850:25.78 vvv
7776 root 20 0 237m 139m 11m S 3.3 0.2 658:24.58 bbbb
45 root 20 0 0 0 0 R 1.1 0.0 1313:36 nnnn/10
1313 isom 20 0 103m 712 504 S 1.1 0.0 0:00.20 mmmm.sh
4240 ladm 20 0 338m 18m 576 S 1.1 0.0 558:21.33 memcached
32341 root 20 0 15172 1440 916 R 1.1 0.0 0:00.04 top
The machine in question is using 100% of the cores available.
In the situation presented, the pc or server has more than 1 core, therefore a process can use more than 1. That's why one process can use 425.7%, meaning that it's using more than 4 cores to do its job.

Linux memory usage: Can we consider memory full when swap is unused?

I am checking available free memory after deploying our applications. I am using below command and finding free memory is less than 20%:
free | grep Mem | awk '{print "Free Memory :"100*($4+$6+$7)/$2"%"}'
But when i check top command, i see that swap memory is not used at all. also above command doesn't include swap memory space. Now i have several questions in my mind
Snapshot1:
top - 10:01:07 up 305 days, 11:23, 1 user, load average: 0.35, 0.22, 0.12
Tasks: 244 total, 1 running, 242 sleeping, 0 stopped, 1 zombie
Cpu(s): 13.4%us, 14.5%sy, 0.0%ni, 69.3%id, 0.8%wa, 0.4%hi, 1.6%si, 0.0%st
Mem: 15952M total, 15817M used, 135M free, 531M buffers
Swap: 16378M total, 0M used, 16378M free, 2567M cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19983 user1 20 0 3410m 2.9g 4420 S 23 18.9 56733:33 x1
28390 user2 20 0 621m 216m 1300 S 12 1.4 40201:39 p2
24781 user1 20 0 1393m 868m 1760 S 9 5.4 27795:12 p3
13936 user1 20 0 740m 432m 2692 S 6 2.7 15726:39 p4
30545 user1 20 0 391m 77m 2232 S 6 0.5 2805:05 p5
5696 user1 20 0 914m 680m 2180 S 4 4.3 2209:03 p6
28801 user2 20 0 282m 148m 1432 S 4 0.9 12408:20 p7
29559 user2 20 0 504m 357m 2028 S 3 2.2 9152:52 p8
29129 user2 20 0 245m 172m 2004 S 2 1.1 6935:50 p9
29130 user2 20 0 245m 172m 1996 S 2 1.1 6879:25 p9
29131 user2 20 0 245m 172m 1996 S 2 1.1 6913:15 p9
29135 user2 20 0 245m 172m 1996 S 2 1.1 6897:49 p9
29140 user2 20 0 245m 172m 1996 S 2 1.1 6886:52 p9
Snapshot 2:
top - 10:06:18 up 312 days, 11:29, 1 user, load average: 0.26, 0.42, 0.31
Tasks: 240 total, 1 running, 238 sleeping, 0 stopped, 1 zombie
Cpu(s): 13.1%us, 11.8%sy, 0.0%ni, 71.8%id, 1.7%wa, 0.5%hi, 1.1%si, 0.0%st
Mem: 15952M total, 15832M used, 119M free, 480M buffers
Swap: 16378M total, 0M used, 16378M free, 2622M cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19983 user1 20 0 3410m 2.9g 5292 S 18 18.9 58711:30 x1
28390 user2 20 0 621m 216m 1300 S 12 1.4 41451:12 p2
24781 user1 20 0 1393m 868m 1760 S 8 5.4 28615:15 p3
13936 user1 20 0 740m 432m 2692 S 6 2.7 16247:35 p4
12453 user1 20 0 387m 74m 3056 S 5 0.5 178:45.72 p5
28801 user2 20 0 282m 148m 1448 S 4 0.9 12794:23 p6
13252 user1 20 0 850m 665m 2556 S 4 4.2 138:43.83 p7
29559 user2 20 0 504m 357m 1992 S 3 2.2 9450:05 p8
29154 user2 20 0 245m 172m 1972 S 3 1.1 7127:40 p9
29130 user2 20 0 245m 172m 1972 S 2 1.1 7104:03 p9
29140 user2 20 0 245m 172m 1972 S 2 1.1 7111:48 p9
29171 user2 20 0 244m 172m 1972 S 2 1.1 7137:48 p9
29129 user2 20 0 245m 172m 1980 S 2 1.1 7162:12 p9
Am i using correct method to check available free space? (I need to raise alarm when memory usage is too high)
2.From below 2 snapshots i see that free memory is reduced from "135M free" to "119M free" (Pls check mem: row of top command). But i see that memory related to my processes (even other) not changed but only that buffers and cache reduced. As i have read earlier these memory will be released by OS if enough memory is not available for processes. So should i really worry about this change? is there any way to clear this?
My system has Mem:15952M total, Swap:16378M total so what is the total available space? will the system performance will go down once swap memory starts being used?
Pls guide me
Example free memory output:
>free
total used free shared buffers cached
Mem: 8183648 7148324 1035324 0 150568 2352956
-/+ buffers/cache: 4644800 3538848
Swap: 17149376 24588 17124788

Debian Wheezy with default Kernel (3.2.0-4-amd64) high load average

I have recently upgraded to a new machine and to Debian Wheezy.
Everything ist running fine, except that even with low actual load, the load average is too high.
Example:
14:29:35 up 9:49, 1 user, load average: 1.96, 2.22, 2.14
This happens even tho all components are at a low load (almost no I/O and all CPU Cores are <50%)
top:
top - 14:30:31 up 9:50, 1 user, load average: 2.38, 2.32, 2.18
Tasks: 156 total, 3 running, 153 sleeping, 0 stopped, 0 zombie
%Cpu(s): 28.2 us, 1.3 sy, 0.0 ni, 69.8 id, 0.4 wa, 0.0 hi, 0.3 si, 0.0 st
KiB Mem: 32878740 total, 8036624 used, 24842116 free, 106544 buffers
KiB Swap: 16768892 total, 0 used, 16768892 free, 2897400 cached
iotop:
Total DISK READ: 0.00 B/s | Total DISK WRITE: 1004.39 B/s
vmstat:
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 24809288 107236 2921816 0 0 10 1 102 138 17 2 81 0
1 0 0 24809364 107244 2921908 0 0 6 6 14334 15108 24 1 75 0
4 0 0 24808784 107260 2921952 0 0 2 16 14407 15222 24 1 74 0
0 0 0 24808660 107272 2922096 0 0 4 14 14570 15373 26 1 73 0
1 0 0 24808156 107280 2922220 0 0 0 13 14783 15499 27 1 72 0
2 0 0 24807420 107292 2922684 0 0 0 23 14590 15344 26 1 72 0
uname -r:
3.2.0-4-amd64
Anyone got a clue?
Load average is usually the number of process waiting for execution, as in the queue.
As it doesn't seem to be a problem with CPU and I/O, I would expect to be something like a shared memory semaphore, or a network dependent code.
Try to see what processes are with:
# top -b -n 1 | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'

Linux free shows high memory usage but top does not

On RedHat Linux 6.2 I'm running free -m and it shows nearly all 8GB used
total used free shared buffers cached
Mem: 7989 7734 254 0 28 7128
-/+ buffers/cache: 578 7411
Swap: 4150 0 4150
But at the same time in top -M I cannot see any processes using all this memory:
top - 16:03:34 up 4:10, 2 users, load average: 0.08, 0.04, 0.01
Tasks: 169 total, 1 running, 163 sleeping, 5 stopped, 0 zombie
Cpu(s): 0.7%us, 0.3%sy, 0.0%ni, 98.6%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 7989.539M total, 7721.570M used, 267.969M free, 28.633M buffers
Swap: 4150.992M total, 0.000k used, 4150.992M free, 7115.312M cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1863 sroot 20 0 398m 24m 9.8m S 0.3 0.3 3:12.87 App1
1 sroot 20 0 2864 1392 1180 S 0.0 0.0 0:00.91 init
2 sroot 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 sroot RT 0 0 0 0 S 0.0 0.0 0:00.07 migration/0
4 sroot 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
5 sroot RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
6 sroot RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
7 sroot RT 0 0 0 0 S 0.0 0.0 0:00.08 migration/1
8 sroot RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
I also tried this ps mem script but it onlt shows about 400MB memory being used.
Don't look at the "Mem" line, look at the one below it.
The Linux kernel consumes as much memory as it can to provide the I/O cache (and other non-critical buffers, but the cache is going to be most of this usage). This memory is relinquished to processes when they request it. The "-/+ buffers/cache" line is showing you the adjusted values after the I/O cache is accounted for, that is, the amount of memory used by processes and the amount available to processes (in this case, 578MB used and 7411MB free).
The difference of used memory between the "Mem" and "-/+ buffers/cache" line shows you how much is in use by the kernel for the purposes of caching: 7734MB - 578MB = 7156MB in the I/O cache. If processes need this memory, the kernel will simply shrink the size of the I/O cache.
Also, as the first line shows
total used free shared buffers cached
Mem: 7989 7734 254 0 28 7128
-/+ buffers/cache: 578 7411
If we add (cached[7128] + buffers[28] + free[254]), we will get approximately the second line's free[7411] value
7128 + 28 + 254 = 7410
If the cached is small, try this command:
ps aux --sort -rss

Opening an existing process

I am using Eclipse in Linux through a remote connection (xrdp). My internet got disconnected, so I got disconnected from the server while eclipse was running.
Now I logged in again, and I do the "top" command I can see that eclipse is running and still under my user name.
Is there some way I can bring that process back into my view (I do not want to kill it because I am in the middle of checking in a large swath of code)? It doesnt show up on the bottom panel after I logged in again.
Here is the "top" output:
/home/mclouti% top
top - 08:32:31 up 43 days, 13:06, 29 users, load average: 0.56, 0.79, 0.82
Tasks: 447 total, 1 running, 446 sleeping, 0 stopped, 0 zombie
Cpu(s): 6.0%us, 0.7%sy, 0.0%ni, 92.1%id, 1.1%wa, 0.1%hi, 0.1%si, 0.0%st
Mem: 3107364k total, 2975852k used, 131512k free, 35756k buffers
Swap: 2031608k total, 59860k used, 1971748k free, 817816k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13415 mclouti 15 0 964m 333m 31m S 21.2 11.0 83:12.96 eclipse
16040 mclouti 15 0 2608 1348 888 R 0.7 0.0 0:00.12 top
31395 mclouti 15 0 29072 20m 8524 S 0.7 0.7 611:08.08 Xvnc
2583 root 20 0 898m 2652 1056 S 0.3 0.1 139:26.82 automount
28990 postgres 15 0 13564 868 304 S 0.3 0.0 26:33.36 postgres
28995 postgres 16 0 13808 1248 300 S 0.3 0.0 6:54.95 postgres
31440 mclouti 15 0 3072 1592 1036 S 0.3 0.1 6:01.54 gam_server
1 root 15 0 2072 524 496 S 0.0 0.0 0:03.00 init
2 root RT -5 0 0 0 S 0.0 0.0 0:04.53 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.04 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root RT -5 0 0 0 S 0.0 0.0 0:01.72 migration/1
6 root 34 19 0 0 0 S 0.0 0.0 0:00.07 ksoftirqd/1
7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
8 root RT -5 0 0 0 S 0.0 0.0 0:04.33 migration/2
9 root 34 19 0 0 0 S 0.0 0.0 0:00.05 ksoftirqd/2
It is a long shot, but you could try this little program from this thread
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
int main(int argc, char **argv)
{
if ( argc != 2 ) {
printf("Usage:\n\ttotop <window id>\n");
return 1;
}
Display *dsp = XOpenDisplay(NULL);
long id = strtol(argv[1], NULL, 16);
XRaiseWindow ( dsp, id );
XSetInputFocus ( dsp, id, RevertToNone, CurrentTime );
XCloseDisplay ( dsp );
return 0;
}
You can compile it with:
$ c++ totop.cpp -L/usr/X11R6/lib -lX11 -o totop
I assumed that you saved it in "totop.cpp".
It has problem I do not know how to fix:
if window is in another virtual desktop this program doesn't work.
Here another question rises: how to send window to current desktop?
You can get window id using xwininfo.
A little script using this program used to call Eclipse:
#!/bin/bash
if ps -A | grep eclipse; then # if Eclipse already launched
id=$(xwininfo -name "Eclipse" | grep id: | awk "{ print \$4 }")
totop $id
else # launch Eclipse
eclipse
fi

Resources