[Horwitz02] Section 11.8 Tuning Memory and Swap Performance

来源:百度文库 编辑:神马文学网 时间:2024/04/28 19:04:59

Tuning Memory and Swap Performance

The virtualmemory subsystem on Unix operating systems relies heavily on bothphysical memory and disk; ironically, the VM subsystem performanceoften relies on the optimization of the swap partitions on disks. Muchof the performance of memory and swap lie deep within highly optimizedkernel code, but there are a few things administrators can do tooptimize memory and swap performance. These tuning measures includetweaking various operating system-specific settings, optimizing theplacement of swap partitions, and taking advantage of programming techniques that minimize the use of memory.

Using Solaris Priority Paging

File system cachingcan severely degrade the performance of virtual memory on Solaris 7 andearlier, so Sun introduced a new paging algorithm called prioritypaging. Priority paging limits the size of the file system cache. Whenthe free list shrinks to a certain limit (called cachefree),the operating system begins to reclaim file system cache pages for useby processes, keeping the free list well above the dangerouslotsfree low-water mark at which the pagedaemon begins scanning.

You can enable priority paging in Solaris 7 and earlier by adding the following line to /etc/system and rebooting:

set priority_paging=1

Don't Set Priority Paging in Solaris 8

Never set this variable on a Solaris 8 system—Solaris 8 includes a more elegant solution called cyclic caching that eliminates the need for priority paging.


Optimizing the Access to Swap Partitions

Optimizingthe position of swap partitions and using multiple swap partitions areother effective ways to tune memory and swap performance. Paging andswapping perform best when the kernel can read and write to swap withthe lowest latency and highest possible throughput. Placing the swappartition in the outer tracks of a disk takes care of this for you—infact, the traditional location for Solaris swap is on slice 1, thesecond outermost track on a disk (/ is usually on slice 0).

Multipleswap partitions allow swap activity to occur over two or more physicaldevices, increasing throughput as it does with RAID-1 striping. Infact, both Solaris and Linux interleave multiple swap devices,providing a native striping to improve swap performance.

Taking Advantage of Shared Libraries

Shared librariescontain code common to many applications and typically save disk spaceby putting this code in a single file instead of having copies of it inall of the executables that use the code. Shared libraries have a moreobscure benefit too—their code segments are shared among processes inmemory. Large portions of code in shared libraries have to be loadedinto memory only once, yielding a huge savings in memory if many programs are linked with those libraries.

Real-World Example: Memory on Login Servers

A large university hosted a pool of 16 login servers that students, staff, and faculty primarily used to check their email using the popular open-source email program, pine. When usage increased to about 120 users per machine, the 192MB on each machine (in 1996) became woefully inadequate to run all of those pine processes, each requiring between 4MB and 8MB. Excessive paging, swapping, and sluggish interactive performance were commonplace. Fortunately, the source code for pine was very modular, and the bulk of its code was isolated in a library called c-client.a, which was statically linked into the pine binary. System administrators quickly realized that they could rebuild the pine program with a shared version of c-client.a, thus sharing those code pages among the hundred or so pine processes on any one machine. The plan worked, and memory consumption was reduced to reasonable levels, increasing the performance of each of the login servers.