588
◾
Linux with Operating System Concepts
not currently in memory. Two more page faults occur within a single iteration of the loop.
If there are four page faults per iteration, then this set of code could result in a total of 4*n
total page faults!
It should be obvious that this example is artificial and should never arise. For one rea-
son, a process will be given far more than two frames. Another is that it is unlikely that
the division within a program would fall exactly as shown in this example (although
this is possible). However, as unlikely as the example is, it illustrates the potential prob-
lem of thrashing.
14.4.3 Process System-Monitoring Tools
The system monitor program provides us with both an overview
and detail of what is
going on with many system resources. Specifically, we can see the amount of CPU usage,
memory usage, network usage, virtual memory usage, and file system usage. For CPU,
memory, swap space, and network utilization, the tool shows us the changes taking place
over the past minute.
As a system administrator, a quick look at this tool can indicate
that your system is
running smoothly. You would hope to see CPU load is not approaching or at 100% for any
length of time and that swap space is not approaching 100% utilization. Further, if memory
use has not come close to 100%, you should expect swap space usage to remain low. If you
find swap space usage to be high and remain high, it means that your system is doing a lot
of very inefficient paging.
Through the system monitor, you can inspect the running processes (the Processes tab)
and see the status, CPU, and memory usage of the processes. If you see many processes
with
high CPU utilization, you might inspect these processes. Which processes are owned
by root that can be postponed? Which processes are owned by users that you might deem
of low priority that could be moved either to the background or have their priority low-
ered? You could even select some user process(es) to run later via scheduling.
If memory utilization is approaching capacity causing a lot of virtual memory usage,
you might again select some of the processes to move into the background or schedule
them later. Moving processes to the background permits the operating system to tem-
porarily swap their content out of memory and thus free up space for other processes.
Lowering the priority of running processes will not impact their memory usage as they
would remain in memory. If you find that memory usage remains very high, it might
indicate that either you have too many users for your Linux system or that you need more
memory in your computer.
Top also provides information about processes and system resource usage.
While top
and the system monitor will tell you much of the same information, top displays pro-
cess and resource utilization on one screen, rather than having to switch between tabs.
Additionally, top can be tailored to display different types of information. See Chapter 4
for more details on top.
Other tools for querying the system are command line programs. These include ps (see
Chapter 4) as well as
mpstat
,
sar
,
pidstat
,
uptime
,
vmstat
,
free
,
stat
,
df
,
du
,
netstat
,
nmap
,
ip
,
ss
,
lnstat
,
iostat
, and
lpstat
.
Maintaining and Troubleshooting Linux
◾
589
Another command that might provide useful information is called
strace
, which
traces the system calls made by a particular Linux command. We have already looked at
some of these programs earlier in the chapter (stat, df, du, ip, and ss). We will examine the
remainder here.
The first set of commands explores the processor’s performance and the active pro-
cesses. The mpstat command reports processor-related statistics for each of the system’s
processors. It is implied that mpstat is used on a multiprocessor system, but it can also be
used for a single-processor computer.
The mpstat command provides for each CPU the percentage of time it spends on user
activities, system activities, hardware interrupts, software interrupts, guest activities,
ideal time,
cycle stealing, and periods of input or output when it is forced to wait. The
user activity is broken into two different values: ordinary user activity and user activity
with niced processes (those given lower priority). Guest activities are actions that the
CPU takes to run a virtual processor. Cycle stealing occurs when the CPU is given a
lower priority to accessing resources than the disk drive (this is described in more detail
later).
Similar to mpstat, sar reports on CPU utilization. The primary difference is that mpstat
reports an average over some duration of time. Sar on the other hand, outputs a series of
snapshots of processor utilization over a period of time.
The output shows, row by row, the
processor’s utilization at each timed interval.
By default, the interval is every 10 minutes. This information is stored in log files under
the directory /
var/log/sa
. You might find numerous entries in this directory with
names such as
sa
Do'stlaringiz bilan baham: