HP-UX 11i v3 Memory Management Subsystem
22
For systems such as factory-floor controllers, which perform best when the entire application is resident
in memory, pseudo-swap space can be used to enhance performance: you can either lock the
application in memory or ensure that all processes don't use more than
7
/
8
of system memory.
When the number of processes created approaches capacity, the system might exhibit thrashing and
a decrease in system response time.
Physical Swap Space
There are two kinds of physical swap space: device swap and file system swap.
Device Swap Space
Device swap space resides in its own reserved area (an entire disk or logical volume of a disk) and is
generally faster than file system swap.
File system Swap Space
File system swap space is located on a mounted file system and can vary in size with the system's
swapping activity. However, its throughput is slower than device swap, because free file system
blocks may not always be contiguous, leading to extra read/write requests; and because of the extra
overhead of an additional layer of code.
Reservation of Physical Swap Space
Swap reservation is a numbers game. The system has a finite number of pages of physical swap
space. By decrementing the appropriate counters, HP-UX reserves space for its processes.
Most UNIX® systems and UNIX-like systems allocate swap when needed. However, if the system runs
out of swap space but needs to write a process's pages to a swap device, it has no alternative but to
kill the process. To alleviate this problem, HP-UX by default reserves swap at the time the process is
forked or exec'd. When a new process is forked or executed, if insufficient swap space is
available and reserved to handle the entire process, the process may not execute.
The exception to this general rule is called "lazy swap". An entire program may be designated for
lazy swap through use of the
chatr(1) +z option, and so can any private memory mapped object
through the use of the
mmap(2) MAP_NORESERVE flag. Swap space is not reserved in advance for
any object designated for lazy swap. If page out for such an object is required and there is no swap
space available, then the responsible process is given a
SIGBUS signal, which usually results in
process termination.
Whenever the swapon() call is made to add device or file system swap, the amount of swap newly
enabled is converted to units of pages and added to the two global swap-reservation counters
swapspc_max (total enabled swap) and swapspc_cnt (available swap space).
Each time swap space is reserved for a process (that is, at process creation or growth time),
swapspc_cnt is decremented by the number of pages required. The kernel does not actually assign
disk blocks until needed.
Once swap space is exhausted (that is, swapspc_cnt == 0), any subsequent request to reserve
swap causes the system to allocate file system swap space. If the allocation is successful, both
swapspc_max and swapspc_cnt are updated and the request can be satisfied. If file system
space cannot be allocated, the request fails, unless pseudo-swap is available.
When swap space is no longer needed (due to process termination or shrinkage), swapspc_cnt is
incremented by the number of pages freed.
swapspc_cnt never exceeds swapspc_max and is
always greater than or equal to zero. If any file system swap is no longer needed, it is released back
to the file system and
swapspc_max and swapspc_cnt are updated.
If no device or file system swap space is available, the system uses pseudo-swap as a last resort. It
decrements
swapmem_cnt and locks the pages into memory. Pseudo-swap is either free or
allocated; it is never reserved.