Swapping and Paging

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 (lotsfree—see 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 this—the 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
VariableValueDescription
lotsfreeThe greater of 1/64 of physical memory, or 512 KBWhen paging occurs.
desfreelotsfree/2Amount of desired free memory.
minfreedesfree/2Minimum acceptable memory level.
throttlefreeminfreeLevel at which blocking memory allocation requests are put to sleep.
pageout_reservethrottlefree/2Number of pages reserved for the pageout or scheduler threads.
cachefree2 × lotsfreeNot used in Solaris 8—was used in priority paging to free file system data pages.
priority_pagingNot used in Solaris 8—was used to enable priority paging.
fastscanThe minimum of 64 MB or ½ physical memoryMaximum number of pages per second that the system will look at.
slowscanThe smaller of 1/20 of physical memory or 100 pagesMinimum 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 choice—it 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 is—maybe! 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset