• Aucun résultat trouvé

The physical memory of most interest to system administrators is the random access memory (RAM). RAM usually consists of memory cards that plug into the computer's backplane. For the CPU to execute a process, the relevant parts of a process must exist in RAM.

The more main memory in the system, the more data it can access and the more (or larger) processes it can execute without having to page or swap.

This is because the system can retain more processes in main memory, thus requiring the kernel to page less frequently. Memory-resident resources (such as page tables) also take up space in main memory, reducing the space available to applications.

During system startup, the system displays on the system console the amount of physical memory installed:

real mem

=

no_oi_bytes

Refer to the HP Configuration Guide for your system's minimum, maximum, and recommended RAM requirements.

Power and Data Permanence

A characteristic of memory is its volatility or nonvolatility-whether or not a storage medium retains data when power is removed. Before the system boots, only data or microcode stored in nonvolatile memory (ROM, EPROM, magnetic tape, disk) is available.

Once the system is brought up, data is stored and used in RAM. Data held in RAM is volatile; that is, it is not retained in RAM when the system is brought down.

7 -2 Memory Management

Transactions between RAM and Disk

At boot time, the system loads the operating system from disk. (This is essentially what booting means.) The operating system then resides in RAM until the system is shut down.

When the user runs programs and commands, they too are loaded from disk into RAM. When a program terminates, it is usually flushed out of RAM (that is, the operating system frees the memory used by the process).

Complex swapping and paging algorithms determine when data and code for currently running programs will get returned from RAM to disk.

User and system programs write data to disk (for example, to update the password file or write a database record). This data-to-be-written is either written directly to RAM (if raw data) or buffered in cache and written to disk in relatively big chunks. Programs also read files and database structures from disk into RAM. Buffering algorithms try to minimize disk access by going to disk as infrequently as possible; disk access is a bottleneck on all systems.

When you issue the sync command before shutting down a system, all modified buffers of the buffer cache are flushed (written) out to disk.

On the Series 800, if the system loses power for a short time and powerfail is enabled, the powerfail routines will put the system in a consistent state and bring it back up without the user having to reboot it.

There are two other characteristics of physical memory involved at system start-up: available memory and lockable memory.

Available Memory

Not all physical memory is available to user processes. The kernel (/hp-ux) always resides in main memory (that is, it is never swapped), occupying approximately 1.6 MB on a Series 300/400 and 3 MB on a Series 700/800 system. (Note, however, these are static sizes only, and do not include kernel tables, daemons, device drivers, processes, diagnostics, user interfaces, or other executing code on a working system.)

The amount of main memory not reserved for the kernel is termed available memory. Available memory is used by the system for executing user processes.

Memory Management 7-3

7

7

Instead of allocating all its data structures at system initialization, the HP- UX kernel dynamically allocates and releases some kernel structures as needed by the system during normal operation. This allocation comes from the available memory pool; thus, at any given time, part of the available memory is used by the kernel and the remainder is available for user programs.

During system startup, the system displays on the system console the amount of available memory:

avail mem = no_oj_bytes

~---~

.

>-~I Lockable Memory

>-:-Available Memory

>-- PHYSICAL MEMORY

HP-UX { I o o f : -Kernel at

Boot-up L-________________________ ~I _ _ _

Figure 7-1. Physical Memory Available to Processes

7 -4 Memory Management

Lockable Memory

As shown in Figure 7-1, physical memory that can be "locked" (that is, its pages kept in memory for the lifetime of a process) by the kernel or plock

0

is known as lockable memory.

User processes can lock memory using the plock or shmctl system call (see plock(2) or shmctl(2) in the HP-UX Reference). Locked memory cannot be paged or swapped out. Typically, locked memory holds frequently accessed programs or data structures, such as critical sections of application code.

Keeping them memory-resident improves system performance.

By default, lockable memory can be no more than three-fourths of available memory during bootup. Available memory is a portion of physical memory, minus the amount of space required for the kernel and its data structures. The size of the kernel varies depending on the number of interface cards, users, and values of the tunable parameters; thus, available memory varies from system to system.

Lockable memory is extensively used in "real-time" environments, like hospitals, where some processes require immediate response and must be constantly available.

A Series 800 feature called pseudo-swap reservation (discussed at the end of this chapter) also does not allow lockable memory to exceed three-fourths of available memory.

If the default value of lockable memory is changed, care must be taken to allow 7 sufficient space for paging and swapping. As this space is decreased, the system

is more likely to deadlock. The system parameter to change the amount of unlockable memory is unlockable_mem. (See System Administration Tasks manual for information on tunable operating-system parameters.)

During system startup, the system displays on the system console the amount of its lockable memory (along with available memory and physical memory).

You can display the values later by running / etc/ dmesg.

lockable mem = no_of_bytes

lockable_mem is the total amount of physical memory all users can lock down at once. This value can be changed by modifying the operating-system parameter, unlockable_mem.

Memory Management 7-5

7

The system has boundary conditions requiring that unlockable_mem be more than zero and less than the amount of memory available after boot. If unlockable_mem is set to zero or a negative value, the kernel will compute an appropriate default value at boot time.

Available memory minus the memory locked by processes is the memory actually available for virtual memory demand paging.

You can determine the default value of unlockable_mem by subtracting the amount of lockable memory from the available memory during boot-up.

available memory - lockable memory = unlockable_mem The resulting value must be less than three quarters of free memory.

For example, the following boot information was displayed on a Model 835:

physical page size = 2 KB avail mem

=

9670656 bytes real mem

=

1677216 bytes lockable mem = 659456 bytes The system's unlockable memory would be

9670656 - 659456

=

9011200 bytes

For details on setting lockable memory, refer to the unlockable_mem tunable parameter in the system parameters chapter of the System Administration

Tasks manual.

Secondary Storage

Main memory (RAM) stores computer data required for progra,ffi execution.

During process execution, data resides in two faster implementations of memory found in the processor subsystem, registers and cache. Program files are kept in secondary storage or secondary memory, typically disks accessible either via system buses or network. Data is also stored when no longer needed in main memory, to make room for active processes.

7 -6 Memory Management

Processor subsystem

D

Registers in CPU

D

Cache

r - -...._-_----... _

I I I I

Input/Output (I/O) Subsystem

Main Memory

: I

L __ ~~ice

.:.wap _ _ _ _ _ _ file

syst~

.:.wap _ _ _ _ _ _ _ _

J

secondary memory

LG200211_ 001

Figure 7-2. Relationship between Main Memory and Secondary Storage A transitory form of secondary data storage is termed swap, dating from early UNIX implementations that managed physical memory resources by moving entire processes between main memory and secondary storage. Besides swapping, HP -UX uses paging, a more effiicent memory resource management mechanism for virtual memory.

While executing a program, data and instructions can be swapped (copied) to and from secondary storage if the system load warrants such behavior.

Swap space is initially allocated when the system is configured. Device swap can take the following forms:

• an entire disk (Series 300/400/700/800)

• a designated area on a disk (Series 300/400/700)

Memory Management 7-7

7

7

• a section or LVM logical volume of a disk (Series 800)

• a software disk-striped partition on a disk (Series 700); see sdsadmin(lM)

You can also configure a file system so that remaining space not used for files is used for swap; this is termed file-system swap. If more swap space is required, it can be added dynamically to a running system, as either device swap or file-system swap.

The SliJapon command is used to allocate disk space or a directory in a file system for swap.

Note You cannot remove swap without rebooting the system.

The concepts of swap and swap-space management are further discussed in

"Swap Space Management," later in this chapter. For procedures on allocating swap space, see the HP- UX System Administration Tasks manual for your system, Chapter 7, "Managing Swap Space" and Appendix B, "Swap Space Computation" .

7 -8 Memory Management