2

For some reason, overall CPU usage on my FreeBSD machine fluctuates between 1% and 85%, but the CPU usage in processes column never adds up to this amount. For example here the overall CPU usage is 83.5%, but CPU usage in processes list is less than 2%:

last pid: 22965;  load averages:  1.45,  1.72,  3.06                                                                                                                                                                                                  up 151+20:08:57 12:32:38
137 processes: 2 running, 135 sleeping
CPU: 83.5% user,  0.0% nice, 12.8% system,  0.0% interrupt,  3.8% idle
Mem: 222M Active, 88M Inact, 315M Wired, 16M Cache, 110M Buf, 342M Free
Swap: 1996M Total, 30M Used, 1966M Free, 1% Inuse

  PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME    CPU COMMAND
22965 martin       1  96    0  7704K  4172K RUN      0:00  1.27% snmpset
 1234 root          1  44    0  3804K  1068K select  50:36  0.00% hald-addon-storage
 1204 haldaemon     1  44    0  7236K  2300K select  24:13  0.00% hald
 1135 root          1  44    0  3372K   928K nanslp   9:34  0.00% cron
46828 martin       1  44    0 11844K  4140K select   6:06  0.00% irssi
  407 _pflogd       1  44    0  3528K   604K bpf      5:41  0.00% pflogd
86984 root          1  44    0  5284K   996K select   5:14  0.00% gam_server
95843 martin       1  76    0  4560K  1192K wait     5:03  0.00% bash
 6714 martin       1  44    0  5748K  2512K select   4:46  0.00% screen
  775 root          1  44    0  3344K   532K select   3:48  0.00% syslogd

How are those two CPU fields different? What might cause such behavior? The machine definitely responds slower at the times when the total CPU usage is around 60 - 80%.

EDIT:

Output of top if kernel threads are also shown(Shift + s):

last pid: 54866;  load averages:  0.62,  0.90,  1.02                                                                                                                                                                                                  up 153+19:26:17 11:49:58
208 processes: 3 running, 188 sleeping, 17 waiting
CPU: 75.3% user,  0.0% nice, 12.4% system,  0.0% interrupt, 12.4% idle
Mem: 395M Active, 154M Inact, 324M Wired, 16M Cache, 110M Buf, 94M Free
Swap: 1996M Total, 112M Used, 1883M Free, 5% Inuse, 8K In

  PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME    CPU COMMAND
   11 root          1 171 ki31     0K     8K RUN    2809.4 52.78% idle
54866 martin       1  96    0  6680K  3548K RUN      0:00  0.98% snmpset
15836 root          1  44    0   322M   307M select  31:51  0.29% Xorg
   12 root         17 -60    -     0K   136K WAIT   455:55  0.00% intr
   17 root          1  44    -     0K     8K syncer 162:57  0.00% syncer
 1234 root          1  44    0  3804K  1068K select  51:16  0.00% hald-addon-storage
    3 root          1  -8    -     0K     8K -       27:06  0.00% g_up
 1204 haldaemon     1  44    0  7236K  2268K select  24:32  0.00% hald
    4 root          1  -8    -     0K     8K -       23:52  0.00% g_down
   13 root          1 -16    -     0K     8K -       20:20  0.00% yarrow
   14 root         20 -64    -     0K   160K -       14:37  0.00% usb
    2 root          1  -8    -     0K     8K -       10:42  0.00% g_event
2

By default top only displays user processes (i.e. processes other than the kernel and its threads). It's possible that the kernel is busy with disk or network IO that is not showing up in top's display. You can toggle the display of kernel threads in top by pressing SHIFTs.

You can use the vmstat utility to display statistics about (among other things) network and disk activity since the system started. vmstat -i will show the number of interrupts received by each device since start up, and the average rate per second at which they were received. Use vmstat -p da to see what your disks are doing.

Other tools like iostat, systat and netstat may also prove informative.

You can increase the responsiveness of your system under load by tweaking the scheduler config. To change it now, run sysctl kern.sched.preempt_thresh=240 as root. To have the same settings apply at boot, make sure you add it to /etc/sysctl.conf as well. This should help, but note that its effectiveness will be limited by your workload, and characteristics of the hardware.

  • Thanks! As this machine handles fairly lot of network traffic, then this might indeed cause the high CPU usage. Am I correct that each network packet will cause an interrupt to CPU? If yes, how can I see those because even with Shift + s in top, the CPU utilization of all the processes in CPU column is very low while the overall CPU usage is high. I updated the original post with another top output with kernel threads shown and where the overall CPU usage is 75.3%, but CPU usage in processes list is less than 2%. – Martin Nov 7 '14 at 11:52
  • You can try tools like systat, tcpdump and netstat to get an idea of network load. vmstat -i will show what's generating interrupts, and might be a good place to start. – D_Bye Nov 7 '14 at 12:24
  • But still, how are the CPU utilization in top header different from CPU utilization in CPU column? – Martin Nov 13 '14 at 10:23
  • I'm afraid I don't know without digging through the top source. It's probably to do with sample intervals, but that's just a guess. – D_Bye Nov 13 '14 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.