22.1 System Memory and Swap Space

   

The system memory is the actual physical memory installed in a system. When you boot a system, it probes all installed memory and displays information about the total memory. You can also use the dmesg command later to list the memory installed. If you extract information about the total memory by using the dmesg command, it looks like the following.

 Memory Information: physical page size = 4096 bytes, logical page size = 4096   bytes Physical: 16773120 Kbytes, lockable: 12179356 Kbytes,   available: 13986844 Kbytes 

As you can see, the command has listed three types of memory. The physical memory is the actual amount of memory installed in the system. When you boot your system, some amount of this memory is used by the kernel code and data structures. The remaining memory is the available memory. If you have a large kernel, with all subsystem and device drivers, it will consume more space compared with a carefully tuned kernel. Similarly, kernel parameters also affect how much memory will be used for kernel data structures. That is why it is important to fine-tune your kernel so that it consumes minimum memory when loaded.

User and system processes are loaded into the available memory. Processes and data in the lockable area are not eligible for swapping (paging).

A page is the minimum amount of memory that is considered one unit, used when data is transferred to and from the main memory to a swap area on the disk. A typical page size is 4 Kbytes. HP-UX keeps a record of free and occupied memory pages in a data structure known as a page table. When the kernel needs a page of data that is swapped out to the swap area, a page fault occurs and that data is brought back to the main memory from the swap area. If there are too many page faults, the system performance is degraded, as it is always busy moving data between main memory and the swap area.

Daemons Used with the Swap System

As soon as your system boots up and the kernel is loaded into memory, two daemons are started. These are the swapper and the vhand daemons and both perform separate jobs.

As has already been mentioned, the physical storage area is divided into pages and a record of these pages is kept in a page table. There is no swap activity as long as the number of these free pages remains larger than a predefined minimum limit. This threshold limit is known as lotsfree. As soon as this threshold limit is crossed and more memory is demanded by some of the processes, the vhand daemon is activated and starts using swap space. The vhand daemon implements a replacement policy for pages, one of which is the least recently used (LRU) policy, where pages that have been least used in the recent past are shifted to the swap area. There may be other policies such as the least frequently used (LFU) policy. Depending on the policy used, the daemon copies some of the pages that are not currently in use in the physical memory to the swap area. After copying these pages, it marks these pages as free in the page table area so that these may be used by some other processes.

If a page is referenced by a process that is currently on the swap area, a page fault occurs and the vhand daemon brings back that page to the main memory. To do so, it has to free other pages by copying them to the swap area. If the system has a small amount of physical memory installed, it may happen that the vhand daemon is overloaded with moving data to and from the swap space. This is the situation where the disk is continuously in use and vhand is taking most of the system time. No useful work is done in such a situation, and the system seems to have stopped swapping data. This situation is known as system thrashing.

Thrashing can be avoided if we are able to decrease the number of running processes. Some may be deactivated temporarily and swapped out of memory. Now the physical memory contains only that number of processes that can run smoothly. When some running processes are finished, the processes that were previously deactivated can be brought back to memory. The swapper daemon is used for this purpose. It checks the memory threshold known as desfree: When the memory falls below the value defined by desfree, it assumes that thrashing has started. It then deactivates some processes and puts them on hold. The memory pages allocated to these processes are swapped out of memory and are marked free in the page table. The swapper daemon reactivates these processes when conditions favorable to run these processes have returned.

To avoid running out of swap area, the system allocates swap space to a process as soon as the process is created. If all of the swap space is allocated, the system does not allow the creation of new processes. It may be noted that a swap space reserved for a process may never be used if not required by the system. Some processes may need additional memory at run time. This will also increase the demand for swap space for such processes. The system will terminate a process that is demanding more swap space than it has available.


   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net