 |
|
Paging and Swapping Devices
Linux Tips by Burleson Consulting |
Linux uses a swap disk as a
repository for segments of memory that are paged out from physical RAM. Linux
will use swap very intelligently even when sufficient physical memory is
available. When too many things are running at once and the demand for memory
exceeds the size of physical memory excessive paging will likely take place,
eventually impacting system performance. The Linux default is to set the size
of the swap disk to twice the size of physical RAM installed in the server.
Linux stores information about devices used for system
paging and swapping activities in a file called /proc/swaps. To display
information regarding swap devices, the file can be displayed using either the
cat command or the swapon command with the -s option. As shown below, the
results are the same using either method.
# cat /proc/swaps
Filename Type
Size Used Priority
/dev/hdf2 partition
524152 0 -1
# swapon -s
Filename Type
Size Used Priority
/dev/hdf2 partition
524152 0 -1
Here we see the device name, type, size and amount used
for each swap device. In this case we only have the one swap device.
Kernel Parameters
Linux is a parameter driven system. Kernel parameters
used for system configuration are found in /proc/sys/kernel, where there is an
individual file for each configuration parameter. Since these parameters have a
direct effect on system performance, root access is required in order to modify
them.
You can view the current configuration parameters by
using the cat command on the appropriate file.
# cat msgmax
8192
Occasionally, a prerequisite to a software installation
requires the modification of kernel parameters. Since each parameter file
contains a single line of data consisting of either a text string or numeric
values, it is often easy to modify a parameter by simply using the echo command:
# echo 2048 > /proc/sys/kernel/msgmax
The aforementioned command will set the value of the
msgmax parameter to 2048. This change will only remain in effect until the
system is rebooted.
Linux also provides the sysctl command to modify kernel
parameters at runtime. sysctl uses parameter information stored in a file called
/etc/sysctl.conf. If, for example, we needed to change the value of the msgmax
parameter as was accomplished above, we could accomplish the same thing with the
sysctl command like this:
# sysctl -w kernel.msgmax=2048
The next section will introduce some useful utilities
that are provided with most Linux releases. These utilities allow some
interactive monitoring of the system.
Server monitoring commands
Some popular commands/utilities for monitoring system
resources and tasks managed by the Linux kernel are as follows:
* top: Provides a dynamic real-time view of a running
system, including information about system resource usage and a constantly
updated list of the processes which are consuming the most resources. Because
it is so useful for administration we will talk quite a bit about top in chapter
8.
* mpstat: Reports activities for each available
processor, processor zero being the first one reported. Global average
activities across all processors are also reported.
* iostat: Used for monitoring the load on system
input/output devices by observing the time the devices are active compared to
the average transfer rate of the device.
* vmstat: Displays information about processes, memory,
paging, block IO, and different levels of CPU activity
Interactive Statistics using the top Utility
The top program provides a dynamic real-time view of a
running Linux system. This can be one of the most useful ways to monitor the
system as it shows several key statistics on the same page with information on
the busiest processes. It is also one of the few commands which will constantly
update. For more information on the top utility refer to chapter 8.
Displaying Multi-Processor Statistics
The mpstat command displays statistics for each and
every processor within the system. The mpstat command accepts interval (delay)
and count (repeat) values as parameters. mpstat will repeat the output count
times every interval seconds. This is very useful for monitoring changes over
time.
The following example uses an interval of three seconds
and a count of five iterations of the report detail lines. An average summary
line is produced at the end of the report.
$ mpstat 3 5
Linux 2.6.5-1.358 (Dell-Linux) 10/18/2004
10:33:26 PM CPU %user %nice %system %iowait %irq
%soft %idle intr/s
10:33:29 PM all 1.00 0.00 0.33 0.00
0.00 0.00 98.67 1001.99
10:33:32 PM all 0.33 0.00 0.33 0.00
0.00 0.00 99.33 1007.02
10:33:35 PM all 0.67 0.00 0.33 0.00
0.00 0.00 99.00 1002.67
10:33:38 PM all 0.66 0.00 0.33 0.00
0.00 0.00 99.00 1000.33
10:33:41 PM all 0.67 0.00 0.33 0.00
0.00 0.00 99.00 1005.67
Average: all 0.67 0.00 0.33 0.00
0.00 0.00 99.00 1003.53
The columns in the report generated by the mpstat
command are defined as follows:
* CPU: Either the processor number or the keyword all,
which indicates that statistics are calculated as averages among all processors
or that there is only one processor in the server
* %user: The percentage of CPU used by user applications
* %nice: The percentage of CPU utilization at the user
level with nice priority
* %system: The percentage of CPU used by the system.
This does not include the time spent servicing interrupts or softirqs. A softirq
is a software interrupt, one of up to 32 software interrupts which can run on
multiple CPUs simultaneously.
* %iowait: The percentage of time the system had a
pending disk I/O request
* %irq: The percentage of time spent by the CPUs
servicing interrupts
* %soft: The percentage of time the processors spent
servicing softirqs.
* %idle: The percentage of time that the processors were
idle and the system did not have a pending disk I/O request.
* intr/s: The total number of interrupts per second
received by the processor(s)
The information from the mpstat report can be used to
determine if processor load is being distributed evenly across the existing
processors and if the multi-processing capabilities of the server are being
utilized effectively.
This is an excerpt from "Easy
Linux Commands" by Linux guru Jon Emmons. You can purchase it for only
$19.95 (30%-off) at
this link.