• Aucun résultat trouvé

Swap Space Management

Swap space is an area on a high-speed storage device (almost always a disk drive), reserved for use by the virtual memory system for swapping and paging processes.

There are two types of swap space, device swap space and file-system swap space, both of which can be configured using SAM or the swapon(lM) command .

• Device swap space is located on a raw partition (or raw logical volume on a Series 800 system implementing LVM). Device swap is faster than file-system swap. On a system with traditional disk partitions, device swap space is fixed in size; on a system implementing LVM, the swap logical volume can be increased as needed. Typically, at least one swap device (primary swap) must be present on the system .

• File-system swap space is located on a mounted file system. File-system swap is slower, but varies in size with the system's swapping activity.

HP- UX swap-space management allows you to allocate swap as needed (that is, dynamically) while the system is running, without having to regenerate the kernel.

Total available swap on a system consists of all swap space available on all devices and file systems enabled as swap. The swapping subsystem reserves swap space at process creation time, but does not allocate swap space from the disk until swap time. Reserving swap at process creation protects the swapper from running out of swap space.

In a cluster (Series 300/400/700 only), multiple cluster nodes can share a single swap area. (Refer to Chapter 12 of Managing Clusters of HP 9000 Computers:

Sharing the HP- UX File System.)

For sample swap-space configurations and procedures on setting them up, consult the HP- UX System Administration Tasks manual for your system.

A variation on traditional swapping, called pseudo-swap reservation, allows users to execute processes in memory without allocating physical swap.

Pseudo-swap reservation is described at the end of this chapter.

Memory Management 7-41

7

7

Swap Parameters

HP- UX deals with swapping in terms of several parameters:

swchunk The number of DEV _ESIZE blocks in a unit of swap space, by default, 2 MB on all systems. (For information on DEV _ESIZE, see Chapter 8, "HFS File System".)

maxswapchunks Maximum number of swap chunks allowed on a system.

min- Number of chunks the system reserves for swapping at boot-up.

swap chunks

Parameter allowing creation of more processes than you have swap space for. (See "Pseudo-Swap Reservation," at the end of this chapter.)

During system startup, the size and location of each swap device is displayed in 512-KB blocks:

st art = xxxxxx size

=

xxxxxx

Device Swap Space

indicates the swap space's starting disk block number indicates size of swap space

Device swap space resides in its own reserved area-an entire disk, or a section or logical volume of a disk-and is not taken from file system space.

At least one swap device should be present on a system (unless you use

pseudo-swap reservation). Device swap space is required during system startup.

You can also configure device swap space dynamically, without bringing the system into single-user mode. Unless you are using LVM (Series 800), device swap is fixed in size and location.

Using LVM, you cannot reduce the size of active device swap, because virtual memory cannot dynamically reconfigure the size of the swap device; thus, reducing the size of active device swap might cause a system panic. You can, however, increase the size of device swap by extending the swap logical volume as needed. However, the system will not recognize the change until you reboot.

One or more swap device can be configured into the system, by specifying the swap devices in the configuration file (dfile for Series 300/400/700 or S800 for Series 800). You can also configure one swap device in the configuration file and dynamically configure more swap devices later, with swapon.

7 -42 Memory Management

The first swap device listed in the configuration file is termed the primary swap device; that is, the swap space used first by the operating system. Primary swap defaults to the disk that contains the root file system.

By listing swap devices in / etc/ checklist, you ensure that the swap devices are automatically enabled when the system is rebooted. The primary swap device might be listed in / etc/ checklist as, for example, the device file /dev/dsk/cOdOs15 (Series 800) where cO refers to the logical unit number 0, which is the first disk in the system, and s15 is the section on that disk.

Or, on a Series 800 system using LVM, the device might be listed as a logical volume, such as /dev/vgOO/rlvo12.

The Series 300/400/700 and 800 systems handle disks differently, and this instructs the system to read / etc/ checklist for swap information and mount all swap sections.

7

Having multiple swap devices on a system also increases throughput, by using the principle of "interleaving swap." Interleaving swap is achieved by assigning identical priority to multiple swap devices to minimize disk-head movement and enhance performance. (See Chapter 7, "Managing Swap Space" in System Administmtion Tasks manual.)

The required secondary storage for data, stack, and shared process segments is reserved from swap space during bootup. Therefore, swap space must be large enough to hold all segments of all existing processes. When it lacks sufficient swap space, the system either returns an error (such as ENOMEM) for some system calls, or kills the user process.

If you need more swap space, follow the procedures in the System Administmtion Tasks manual to do one of the following:

• Enable an additional swap device or file-system swap to your running system.

• (Series 300/400/700 only) Rebuild the file system on the existing device to reserve more swap space. To do this, you will also need to back up the existing file system, remake the file system using mkfs (1M), then restore the saved file system to the new configuration. For Series 700 only, run mkboot if this is the root disk. This must be done from another system.

• (Series 300/400/700 only) Enable swap area to be shared within a cluster.

(See Chapter 12 of Managing Clusters of HP 9000 Computers: Sharing the HP- UX File System for procedures.)

• (Series 800 only) Rebuild the kernel using SAM or uxgen to change primary swap space. (You would do this if your needs have changed, and rather than continually allocating swap as needed, you decide to reorganize your disk space and allocate a different primary swap.)

• (Series 800 only) Create another logical volume or extend an existing swap logical volume. Note: to make use of the extended swap volume space, you must reboot the system.

7 -44 Memory Management

File-System Swap

File-system swap, another form of secondary swap space, can also be configured dynamically. File-system swap space allows a process to use an existing file system if it needs more than the designated device swap space. The operating system swaps to space in the file system, in addition to device swap space.

File-system swap is used only when device swap space is insufficient to meet demand-paging needs.

Whereas a swap device is limited in size to a specific section of a disk (or logical volume), file-system swap consumes a variable amount of space. This is an efficient use of disk space, because it enables the system to swap to unused portions of a file system as needed.

A process might need 20 MB of swap space for a short time. If only device swap is enabled, an entire 20 MB of swap space would have to be allocated permanently just to handle that brief work. With file-system swap, the paging system (that is, swapper" daemon) can fill these temporary needs from

file-system space. The paging system and the file system share file system space. You can also limit file-system swap to a fixed size to prevent it from consuming too much space.

To optimize system performance, file-system swap space is allocated and de-allocated in swchunk-sized chunks. swchunk is a configurable operating system parameter; its default is 2048 KB (2 MB). Once a chunk of file system space is no longer being used by the paging system, it is released for file

system use, unless it has been preallocated with swapon. (See swapon(lm) or 7 swapon(2) in the HP-UX Reference.)

Guidelines for Adding Swap Space

Swap configured into the system is always available to a booted and running system. However, file-system and device swap can be allocated to a running system for short-term use, and is used by the system like any other configured swap device.

To make swap-space allocation automatic at boot time, you must include it in the / etc/ checklist file. This ensures that the swap area is enabled when the system is rebooted.

Memory Management 7-45

7

If a swap area is not added to /etc/checklist, the system will no longer swap to that area after a reboot. To disable swap, you must edit / etc/ checklist before rebooting. (These procedures can be performed using SAM.)

If you need more swap space but do not have any spare devices, we recommend that you add file-system swap space. System performance is nearly as good when using file-system swap space as device swap. If the system is using so much file-system swap space that performance degrades badly, you might want to increase device swap space.

If you have additional devices that can be used for swapping, enable these before file-system swap, because the performance is better. If using both device and file-system swap, give devices a higher priority (that is, a lower number in the pri argument when executing the swapon command). File system swap, given equal priority, is always used after device swap.

For instructions on adding swap space, see Chapter 7, "Managing Swap Space"

in the System Administration Tasks manual and swapon(1M) in the HP- UX Reference.

Sample jete/checklist Entry for Device Swap

To enable your swap device each time the system is rebooted, be sure to include an entry in / etc/ checklist, as shown:

/dev/dsk/cldOsl /default swap pri=l or when using LVM (Series 800 only):

/dev/vgOO/lvo13 /default swap pri=l

Refer to the checklist ( 4) manual page of the HP- UX Reference for a thorough discussion of the fields used when adding device swap.

Sample jetcjchecklist Entry for File-system Swap

To enable file-system swap when the system is rebooted, include an entry in /etc/checklist.

The following / etc/ checklist entry enables swap on the file system containing the directory /swap. The size of a swap block is set by swchunk.

It is currently set to 2048 bytes, in units of dev_bsize, which is 1024 bytes.

(2048/size of swap block X 1024 bytes

=

2MB, which is the allocation size

7 -46 Memory Management

of file-system swap-space chunks.) A minimum of ten file-system blocks are consumed immediately; a maximum of 4500 blocks can be used; 100 blocks are reserved for file system use; and the priority is 2:

default /swap swapfs min=10,lim=4500,res=100,pri=2

Refer to the checklist ( 4) manual page of the HP- UX Reference for a thorough discussion of the fields used when adding file-system swap.

Memory Management 7-47

7

Comparing Device and File-System Swap

Device swap is faster than file-system swap. This is because the system can write an entire request (64 KB on Series 300/400 or 256 KB on Series 700/800) to a device at once. File-system swap must be done in file-system blocks, which are typically 8 KB. As a result, the time it takes for one request in device swap might take longer using file-system swap. For example, a 2 MB chunk of file-system swap space is written to the disk in 256 requests in an 8 KB- block file system, or 32 requests in a 64 KB-block file system.

File-system swap makes more efficient use of file-system space, but it might degrade system performance somewhat, because its throughput is slower than device swap. This is because free file-system blocks may not always be contiguous; therefore, separate read/write requests must be made for each file-system block.

Swap Space Priorities

Priorities, ranging from zero to ten, can be set for all devices or file systems.

The lower the number, the higher the priority. Thus, a device with a priority of zero is used for swapping before a device of priority one or higher.

Swapping rotates among both devices and file systems of equal priority. Given equal priority, however, devices are swapped to by the operating system before file systems, because devices make more efficient use of CPU time.

7 We recommend that you assign the same swapping priority to most swap devices, unless a device is significantly slower than the rest. Assigning equal priorities limits disk head movement, which improves swapping performance.

The swapon Command

The swapon(lM) command allows you to enable additional device or file system for paging and swapping. The swap space can be added while the system is running.

7 -48 Memory Management

Sample Swap-Device Allocations

Example Description

/etc/sTJapon -e /dev/dsk/3s0 Enables swapping to a block device on a Series 300/400/700 system using the space after the end of the file system (-e option) for swap and letting the priority default to 1.

/etc/sTJapon -p 0 /dev/dsk/cOdOsO Enables swapping to a block device on a Series 800 system with logical number 0, CS/80 drive unit number 0, section 0, with the highest priority (zero) .

/etc/sTJapon /dev/vg03/1vo14 Enables swapping on logical volume 1 vo14 of volume group vg03 on a Series 800 system using LVM. (See the section on Device Swap for limitations to changing the size of device swap. Also, see chapter 7,

"Managing Logical Volumes" in the System Administration Tasks manual for use of LVM commands.)

/etc/sTJapon -p 2 -f /dev/dsk/c12dOsO Forces swapping (-f option) to be enabled on Series 800 block device

/dev/dsk/c12dOsO, even if a file 7 system exists on the device. (Note

that the -f option makes this a potentially destructive command, to be used with caution.) The device is assigned a swapping priority of 2.

Memory Management 7-49

Sample File-System Swap Allocations

Example Description

/etc/swapon /swap -m 256 -1 1024 -r 0 Enables file-system swap to a

-p 3 directory named /swap. Initially, 256

file-system blocks are consumed; no more than 1024 file-system blocks may be consumed. Also, 0 blocks are file-system blocks maximum may be consumed. No file-system blocks are reserved for file-system use. The swapping priority is 10, meaning that /disk2 is the least likely file system to be used for swap space.

/etc/swapon /bigdisk -m 1024 -1 4096 Enables file-system swap to a

-r 0 -p 0 directory named /bigdisk. Initially,

1024 file system blocks are consumed, no more than a maximum of 4096

7 file-system blocks may be consumed.

No file-system blocks are reserved.

/bigdisk is assigned a swapping priority of 0, meaning it will be used most often for swap space.

/etc/swapon /dyndisk -m 0 -1 0 -r 2048 Enables file-system swap to a

-p 0 directory named /dyndisk. Although

no file-system space is allocated initially, no limit is set on the amount

Evaluating Swap-Space Needs

As a system administrator, you need to monitor your system's swap space regularly, because swap space usage varies with system load. You want to understand your system's swap requirements when demand is heaviest.

Swap space must be large enough to hold the sum of all shared memory, shared libraries, stack, and data for the largest executable process.

The size command is a useful tool for acquiring information on process size:

%

size /usr/bin/vi

243332 + 222992 + 147620 = 423944

size returns the code (text), data, and bss (data uninitialized at the beginning of process execution) for a program. Since no swap space is reserved for

code (the first figure), you would combine only the second and third sizes to estimate the size a program occupies in the swap area. Multiply the figure by the number of users executing the program at the system's busiest time, since each user is allocated data and bss. Repeat this calculation for each program executed when the system is at its busiest.

Shared memory must also be included in your swap-space needs assessment.

To display the amount of shared memory your system is using at any given moment, use the ipcs command:

% ipcs -b

IPe status from /dev/kmem as of Fri May 29 14:53:42 1992

T ID KEY MODE OWNER GROUP QBYTES

Message Queues:

q

o

Ox3c341834 -Rrw--w--w- root root 16384 q 1 Ox3e341834 --rw-r--r-- root root 264

T ID KEY MODE OWNER GROUP SEGSZ

Shared Memory:

m

o

Ox41341837 --rw-rw-rw- root root 512 m 1 Ox4134184f --rw-rw-rw- root root 7452 m 2 Ox411800ac --rw-rw-rw- root root 8192

T ID KEY MODE OWNER GROUP NSEMS

Semaphores:

s

o

Ox4134184f --ra-ra-ra- root root 2

Memory Management 7-51

7

7

In this example, 512, 7452, and 8192 are shared memory segment sizes. You would add them to the data and bss sizes. To account conservatively for page boundaries, round up your estimate.

Because the swap allocation unit, swchunk, is by default 2MB, your figure should be a multiple of 2MB. If you do not use a multiple of swchunk some swap space is wasted.

The value of swchunk is derived as follows: A chunk is an integer with a

default value of 2048. Multiplying that integer by the default block size of 1024 bytes found in /etc/disktab, you derive the swap chunk size of 2 MB.

The figure of 2 MB is then multiplied by the operating-system parameter, maxswapchunks, to derive the limit of swap space allowed on your system.

maxswapchunks is by default 256 (28), but can be set to any value up to 214.

The value specified does not have to be a power of 2.

One more parameter should be considered when determining swap-space requirements. While overlaying the old process image with the new process image, the exec system call uses an area of swap space to temporarily hold arguments and environment variables. The size of this area is determined by the configurable system parameter argdevnblks, whose default size is 256 KB.

If you need to change the amount of swap space to accomodate an application, refer to the application's manual to see if it describes swap space requirements.

For details on setting and changing device and file-system swap space, see the System Administration Tasks manual.

Swapping in an HP-UX Cluster (Series 300/400/700 only)

Swapping on a cluster server is identical to swapping on a standalone system:

the server must swap to a disk that is physically connected to it. A cluster client can do anyone of the following:

• Swap to the server's swap area.

• Swap to a swap area on the client's own local disk.

• Swap to a swap area on another client's local disk.

To set up local swap in a clustered environment, see Managing Clusters of HP9000 Computers: Sharing the HP- UX File System.

7 ·52 Memory Management