• Aucun résultat trouvé

Understanding Memory Management

Dans le document Performance Management Guide ULTRIX (Page 23-26)

Memory management is the allocation of memory. If physical or main memory is insufficient for any process, the kernel moves processes between main memory and secondary memory (refers to back-end storage or page/swap storage) so all processes can execute. The subsystems of the kernel and hardware that work together to translate virtual to physical addresses make up the memory management subsystem.

1.3.1 Types of Memory Management

ULTRIX systems use two types of memory management: simple memory management, and memory management with swapping and paging. ULTRIX uses memory management with swapping and paging.

With simple memory management, the kernel allocates the necessary memory from physical memory to execute a process. Physical memory is divided into a set of equal sized blocks, called pages. Pages can vary in size from 4K to 512K bytes. Page tables exist that identify the location of these pages. For example, in one popular simple memory modeJ1, the system contains a set of memory-management register triples. A register triple is a set of three registers that contain the following information:

• The first register contains the address of the page table in physical memory.

• The second register contains the virtual address mapped via the triple.

• The third register contains control information, such as number of pages in the page table and page access permissions.

Maurice J. Bach, The Design of the UNIX Operating System, Englewood Cliffs, NJ: Prentice-Hall, Inc., 1986, pp. 155-158.

Review of ULTRIX Subsystem Resource Usage 1-9

When the kernel prepares a process for execution, it loads these registers with the corresponding data stored in the pregion (per process region table) tables. A pregion table includes information to determine where the contents related to the process are located in physical memory. 2

In memory management with swapping and paging, the kernel is responsible for making certain that sufficient primary memory exists for a process. It might be necessary at times to write processes to a secondary memory device to provide more space in primary memory. The secondary memory device is called a swap device and is on a configurable disk.

By understanding how memory is stored and allocated, you can plan your workload so that the machine is not running too many processes simultaneously. Through monitoring the CPU, using the vrnstat command for example, you can learn whether paging and swapping are occurring and to what extent. Both swapping and paging are CPU intensive and are considered common elements in poor system performance.

1.3.2 Allocating Memory

ULTRIX allocates a number of blocks of memory to a program when it first starts. As the program executes, it can request additional memory. The kernel allocates additional memory up to a predefined maximum that also is determined when the kernel is built.

When a program is run, the memory management subsystem sets up two separate areas, the text area (or region) and the data area. The program instructions are assigned to the text area; the data related to the process is located in the data area. By keeping these two sections separate, both protection and sharing are possible.

The kernel tries to use memory as efficiently as possible. It allows users executing the same program to share the text segment, the section of memory in which the program's instructions are stored. This is possible through the use of virtual addresses. The compiler generates addresses for virtual address space, and the memory management subsystem translates these virtual addresses into address locations in physical memory. Thus, several programs can execute the same virtual addresses but use different physical addresses.

1.3.3 Buffer Cache

The buffer cache is the part of random access memory (RAM) used for disk blocks that contain data from recently used or frequently used data. A buffer is memory in which information is temporarily stored and cache is a hiding place. Thus, the buffer cache functions between the kernel and the memory as a quickly accessible source of data and instructions.

The buffer cache decreases the frequency of disk access. When the kernel tries to read data from the disk, it first reads from the buffer cache. If the data is not there, it reads the data from the disk and caches it for potential future use. Similarly, pages are written to the buffer cache first until the buffer cache is full. Only then are the oldest pages written to the disk swap area.

The size of the buffer cache is determined when you configure the system.

The default size of the buffer cache is 10 percent of physical memory. By increasing the size of the buffer cache, the system may perform fewer reads

2 Ibid., p. 155.

1-10 Review of ULTRIX Subsystem Resource Usage

and writes from the disk and therefore runs more quickly. However, as more memory is allocated to the buffer cache, less memory is available for program execution. This reduces the system's capacity, and paging or swapping or both will increase when the system is loaded. As a result, fewer users can run programs, and fewer processes can run simultaneously.

1.3.4 Swap Area

The swap area, (also known as swap space) is the section of the swap device allocated in groups of contiguous blocks. The swap device is a block device in a configurable section of a disk. The kernel's allocation of swap space depends on the process scheduling. An in-core table, called a map, maintains a directory of free space for the swap area. As the kernel allocates and frees up resources, it updates this map. This enables the kernel to have current information about free resources.

1.3.5 Changes in Memory Management that Can Affect Performance

You can improve performance by the way you configure the kernel and through ongoing system management. The size of the buffer cache and the size and location of the swap partition are two variables that you can set when you configure the kernel. You can add memory, change process priorities, and set the sticky bit for executable files. These are examples of system management that affect system performance.

1.3.5.1 Size of the Buffer Cache

The default size of the buffer cache is usually 10 percent of physical memory.

The increase or decrease in the buffer cache size affects both the speed of the system and the amount of swapping and paging. The buffer cache is best tuned for each application. For example, a file server application benefits from 50 percent of physical memory allocated to the buffer cache, but it does not benefit from a large number of swap segments. By reducing the size of the buffer cache, you can give some memory back to the system to use for programs.

1.3.5.2 Size and Location of the Swap Area

The ULTRIX operating system allows multiple swap devices. The kernel interleaves swap requests; that is, the kernel attempts to evenly distribute the swap requests among all the swap devices. A parameter in the configuration table determines the size of the swap area. The number and location of swap devices is also specified in the configuration file. Place the swap partition on the fastest disk. The swap areas are best spread between the controllers and disks.

Review of ULTRIX Subsystem Resource Usage 1-11

1.3.5.3 System Management

Once you configure the system, the opportunities to effect higher performance in memory management are reduced. The purchase of additional memory is the most obvious option. Using the iostat and vrnstat commands, you can determine the extent of paging and swapping. If extensive paging is occurring, the system might require more memory.

These monitoring programs and utilities can measure the efficiency of the buffer cache by its hit rate. A 98 percent hit rate is possible with a machine that has sufficient memory. As the hit rate improves, the number of blocks transferred to and from the disks will be reduced. It is important to monitor the buffer cache before you decide to purchase additional memory.

Administrators can create and remove swap devices by reconfiguring the kernel and rebooting the system.

A revaluation of the priorities assigned to various processes can also affect memory management. Managing processes that require a large amount of CPU time, have exclusive access to devices that are in short supply, or consume a large quantity of a system's scarcest resources, can affect system performance as well. You can improve the system's efficiency by doing the following:

• Lowering the priority of memory or disk intensive applications

• Educating users to avoid running a large number of processes simultaneously

• Informing users of the memory requirements of various processes and programs

• Reducing the number of users working simultaneously

The system administrator can set the sticky bit for frequently used executable files. The sticky bit is a permissions flag that tells the kernel to retain the text segment of a program. If the text segment remains in memory, it does not have to be reloaded when another process executes it. If the system does not have to reload the program, the program will be executed much more quickly.

Even if the kernel swapped the file to the swap device, it is still faster to load the text from the swap device than to load it from the file system.

Dans le document Performance Management Guide ULTRIX (Page 23-26)