Swapping and Paging

Team-Fly    

Solaris™ Operating Environment Boot Camp
By David Rhodes, Dominic Butler
Table of Contents
Chapter 7.  Swap Space


To understand swap, we'll look at it in relation to the rest of the memory management mechanism system (i.e., virtual memory and paging). The reason for this is that they are all tied to each other quite tightly.

Solaris uses a virtual memory model that is made up from the total amount of physical memory installed on the system and the amount of swap space that has been defined. For example, if we had 4 GB of physical memory and created a swap area of 10 GB, this would provide us with 14 GB of virtual memory.

Paging

Whenever a program runs it is first allocated an amount of memory. The program code is split into chunks by the kernel; each of these is known as a "page." The kernel also loads a few of these pages into the memory space that has been allocated for the program; here, it will start to run the pages it has in memory. Additional pages will also be loaded when the first ones have been used. If a required page isn't found, a page fault occurs indicating that the kernel should load more pages into memory. This is known as "demand paging."

Once the amount of available free memory falls below a certain limit (lotsfreesee Table 7.1), paging will occur. The page scanner runs and, using a Least Recently Used (LRU) algorithm, determines any pages that have not been accessed for a while. These will be marked as unused; if they are still unused after a period of time, the page will be reclaimed and put back on the free list.

A number of variables can be set to tweak the way paging works. Although we should point out now that you must be aware of what you are doing if you change any of thisthe default values have been tried and tested and should be the best overall solution. The variables can be set by adding the required setting to /etc/system. Some of the more common paging variables are shown in Table 7.1.

Table 7.1. Common Paging Tuneable Variables

Variable

Value

Description

lotsfree

The greater of 1/64 of physical memory, or 512 KB

When paging occurs.

desfree

lotsfree/2

Amount of desired free memory.

minfree

desfree/2

Minimum acceptable memory level.

throttlefree

minfree

Level at which blocking memory allocation requests are put to sleep.

pageout_reserve

throttlefree/2

Number of pages reserved for the pageout or scheduler threads.

cachefree

2 x lotsfree

Not used in Solaris 8was used in priority paging to free file system data pages.

priority_paging

Not used in Solaris 8was used to enable priority paging.

fastscan

The minimum of 64 MB or ½ physical memory

Maximum number of pages per second that the system will look at.

slowscan

The smaller of 1/20 of physical memory or 100 pages

Minimum number of pages per second that the system will look at.

Swapping

Let's assume that the system has been working happily and paging has been occurring at normal levels. Suddenly, the system doesn't have enough memory to allocate to any new processes, which means an existing process, in its entirety, must be moved out of the way to let the new one run.

This is swapping. The process that is being swapped out is moved to a temporary area reserved for the kernel (i.e., swap space). In other words, swap is an area that can be used by the kernel to store running programs when there is not enough space in memory.

Which Is Best?

Paging is the mechanism of choiceit is much smoother than swapping and doesn't affect system performance anywhere near as much. It relies on the fact that "20 percent of a process's memory pages do 80 percent of the work!"

Swapping, on the other hand, is a harsh process that takes its toll on system resources and can cause problems such as disk thrashing as it moves whole processes in and out of swap. It is really used as a last resort, such as when the system must swap to avoid crashing.

Is Swap Really Needed?

In short, the answer ismaybe! Depending on the version of the operating system you are running, and possibly even the patch levels that have been applied, the amount of swap required may range from zero up to the same amount as physical memory.

The swapping and paging mechanisms are often changed between releases to make them more efficient. This quickly becomes a very complex subject, which is beyond the scope of this chapter, so let's just make a few points:

  • Early versions of Solaris used to implement an early allocation mechanism. When a process was started, space for it was reserved in swap in the event it would be swapped out. This meant that swap space needed to be at least as large as the physical memory.

  • Priority paging was introduced in Solaris 7 and made available to Solaris 2.5.1 and 2.6 through kernel patches. It was enabled by setting "priority_paging" in /etc/system. This is no longer supported in Solaris 8, as the memory allocation mechanism used is now more efficient that priority paging.

Nowadays it is possible to create swapless systems by adding enough physical memory to the machine to satisfy its requirements. The main problem here is how to determine exactly how much "enough" is, other than by carrying out tests on the system.


    Team-Fly    
    Top
     



    Solaris Operating Environment Boot Camp
    Solaris Operating Environment Boot Camp
    ISBN: 0130342874
    EAN: 2147483647
    Year: 2002
    Pages: 301

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