HPlogo HP-UX Memory Management: White Paper > Chapter 1 MEMORY MANAGEMENT

THE ROLE OF PHYSICAL MEMORY

» 

Technical documentation

Complete book in PDF

 » Table of Contents

Memory is the "container" for data storage; the general repository for high-speed data storage is close to the CPU, and is termed random access memory (RAM) or "main memory." For the CPU to execute a process, the code and data referenced by that process must reside in random access memory (RAM). RAM holds data during process execution in two even-faster implementations of memory, registers and cache, found on the processor. RAM is shared by all processes.

The more main memory in the system, the more data the system can access and the more (or larger) processes it can retain and execute without having to page or cause deactivation as frequently. Memory-resident resources (such as page tables) also take up space in main memory, reducing the space available to applications.

At boot time, the system loads HP-UX from disk into RAM, where it remains memory-resident until the system is shut down.

User programs and commands too are loaded from disk into RAM. When a program terminates, the operating system frees the memory used by the process.

Disk access is slow compared to RAM access. Excessive disk access can lead to increased latency or reduced throughput and can lead to the disk access becoming the bottleneck in the system. To avoid this, you need to do some sort of buffering. Buffering, paging, and deactivation algorithms optimize disk access and determine when data and code for currently running programs are returned from RAM to disk. When a user or system program writes data to disk, the data is either written directly to RAM (if raw data) or buffered in what is called buffer cache and written to disk in relatively big chunks. Programs also read files and database structures from disk into RAM. When you issue the sync command before shutting down a system, all modified buffers of the buffer cache are flushed (written) out to disk.

Figure 1-1 Physical memory available to processes

[Physical memory available to processes]

Available Memory

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.

Not all physical memory is available to user processes. Kernel text and initialized data occupy about 8 MB of RAM.

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.

Physical address space is the entire range of addresses used by hardware (4GB), and is divided into memory address space, processor-dependent code (PDC) address space, and I/O address space. The next figure shows the expanse of memory available for computation. Memory address space takes up most of the system address space, while address space allotted to PDC and I/O consume a relatively small range of addresses.

Figure 1-2 Major sections of system address space.

[Major sections of system address space]

Lockable Memory

Pages kept in memory for the lifetime of a process by means of a system call (such as mlock, plock, or shmctl) are termed lockable memory. Locked memory cannot be paged and processes with locked memory cannot be deactivated. Typically, locked memory holds frequently accessed programs or data structures, such as critical sections of application code. Keeping them memory-resident improves application performance.

The lockable_mem variable tracks how much memory can be locked.

Available memory is a portion of physical memory, minus the amount of space required for the kernel and its data structures. The initial value of lockable_mem is the available memory on the system after boot-up, minus the value of the system parameter, unlockable_mem.

The value of lockable memory depends on several factors:

  • The size of the kernel varies, depending on the number of interface cards, users, and values of the tunable parameters.

  • Available memory varies from system to system.

  • The system parameter unlockable_mem is a kernel tunable parameter. Changing the value of unlockable_mem alters the default value of lockable_mem also.

HP-UX places no explicit limits on the amount of available memory you may lock down; instead, HP-UX restricts how much memory cannot be locked.

Other kernel resources that use memory (such as the dynamic buffer cache) can cause changes.

  • As memory is used, the amount of memory that can be locked decreases.

  • As memory is freed up, the amount of memory that can be locked increases.

As the amount of memory that has been locked down increases, existing processes compete for a smaller and smaller pool of usuable memory. If the number of pages in this remaining pool of memory falls below the paging threshold called lotsfree, the system will activates its paging mechanism, by scheduling vhand in an attempt to keep a reasonable amount of memory free for general system use.

Care must be taken to allow sufficient space for processes to make forward progress; otherwise, the system is forced into paging and deactivating processes constantly, to keep a reasonable amount of memory free.

Secondary Storage

Data is removed to secondary storage if the system is short of main memory. The data is typically stored on disks accessible either via system buses or network to make room for active processes.

Swap refers to a physical memory management strategy (predating UNIX) where entire processes are moved between main memoryand secondary storage. Modern virtual memory systems today no longer swap entire processes, but rather use a deactivation scheme that allows pages to be pushed out over time by a paging mechanism. While executing a program, pages of data and instructions can be paged out to or paged in from secondary storage if the system load warrants such behavior.

Device swap can take the form of an entire disk or LVM[2] logical volume of a disk. A file system can be configured to offer free space 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 swapon command is used to allocate disk space or a directory in a file system for swap.



[2] Logical Volume Manager (LVM) is a set of commands and underlying software to handle disk storage resources with more flexibility than offered by traditional disk partitions.