Performance Testing, LoadRunner Tips&Tricks

This site is moving to a bigger space @ LoadRunner TnT

General: Understanding Memory - LRU

LRU maintains an ordering of resident virtual memory pages from Most Recently Referenced to Least Recently Used. When real memory is full and an executing program references a pages that is not currently resident in memory (i.e. a page fault occurs), the Least Recently Used page in real memory is replaced with the current Most Recently Referenced page. Older pages, by inference, are less likely to by referenced again soon by executing programs, so they are the best candidates for page replacement. Older pages selected for replacements are effectively removed from memory – the next time they are referenced they must be retrieved from a paging file. If the page in memory was modified, the OS must first update the copy on the paging file before it is definitely removed.

In practice, many LRU virtual memory implementations, including the one found in Windows, attempt to maintain some pool of free pages in RAM. This pool of Available Bytes allows the OS to schedule an I/O to the paging file to resolve the page fault immediately. Then, when this pool becomes depleted, a round of page stealing is triggered, which replenishes the pool of free pages before it is completely exhausted. (Windows refer it as page trimming). Windows uses page trimming on a regular basis to maintain its pool of free pages (reported as Available Bytes).

The challenge in Windows is to identify older pages without relying on specific processor hardware support. This is accomplished by trimming pages from process working sets provisionally. After trimming pages aggressively from active processes, Windows adds them to the pool of Available Bytes, but tags them initially as being in a provisional state. They are not immediately removed from RAM. The next time threads from active processes are scheduled to run, they reference the pages are active and these stolen pages are allowed to transition back into the process working set. So-called transition faults or soft page faults are handled quickly, with a minimum overhead. Eventually, what are left behind in the pool of Available Pages are older, unused pages that are good candidates to be replaced.

Trimmed process working set pages are placed initially in the Standby List, where they are allowed to transition fault back into their process working set the next time they are referenced. Transition faults are distinguished from hard page faults, which must be satisfied by reading the paging file disk. Pages in the Standby List that are un-referenced long enough are eventually moved to the Free List. When the System Zero Thread executes, it zeros out the contents of pages on the Free List, which allows them to move to the Zero List. Pages from the Zero List are allocated whenever either a hard page fault occurs or a process references a brand new page (also known as Demand Zero page faults). Together, the size of the Standby List, the Free List, and the Zero List are added together and reported as Available Bytes.

The page trimming procedure is threshold-driven. Page trimming is invoked when one or more of the List structures that make up the pool of Available Bytes is depleted. In addition, Windows schedules writes to the paging file when the number of changed pages exceeds a threshold value. Modified pages are written in bulk to disk by Modified Page Writer threads, again based on the threshold values being exceeded.

Measurement Support

The Transition Faults/sec counter in the Memory object reports the rate at which soft page faults occur. Similarly, Demand Zero Faults/sec reports the rate at which new pages are being created. Pages Output/sec shows the rate at which changed pages had been copied to disk. By implication, since real memory is a closed system:

Pages trimmed/sec = Transition Faults + Demand Zero Faults + Hard page faults

Plus any change in the size of the Available Bytes buffer from one interval to the next. The individual sizes of the Standby, Free, and Zero lists are not reported. Nor does Windows report the rate at which the Balance Set Manager’s page trimming routine runs, nominally at least once per second.
The Pages Read/sec counter corresponds to the rate of hard page faults requiring the OS to retrieve a page from disk. The fact that Pages Input/sec is usually larger than Pages Read/sec reflects the use of anticipatory paging. Pages Input/sec is the actual number of pages retrieved from disk. Calculating:

Pages per page fault = Pages Input/sec / Pages Read/sec

Reports the average number of pages retrieved per page fault. Similarly, the Pages written/sec counter shows the number of page write operations that were initiated, and Pages output/sec counts the number of physical 4K pages actually written.

When the average number of pages read or written to disk is consistently above two pages per page fault or page write operation, and more than 10 – 20% of all I/Os to the disk are the result of paging operations, it is probably time to add another paging file , if possible. Adding a second paging file spreads the paging I/O load across another physical disk and usually improves page fault resolution time substantially.

Windows supplies one other important measurement of overall paging activity, namely Paging Faults/sec. Unfortunately, interpreting how the Page Faults/sec counter relates to the other paging activity counters is problematic. Page Faults/sec includes both Transition (soft) Faults/sec and hard page faults (Pages Read/sec). It evidently also includes the number of Cache Faults/sec due to the normal diversion of application I/O to the paging subsystem. There is strong evidence that it also includes the number of Demand Zero Faults/sec.

Page Faults/sec = Cache Faults/sec + Demand Zero Faults/sec + Pages Read/sec + Transition Faults/sec

Labels: , , , , , , ,

Bookmark this article now! AddThis Social Bookmark Button

technorati reddit digg

0 Responses to “General: Understanding Memory - LRU”

Post a Comment

Powered by Google

Enter your email address:

Delivered by FeedBurner

Add to Technorati Favorites


Powered by Blogger

make money online blogger templates

Powered by FeedBurner

Blog Directory

Top Blogs

Software Blogs -  Blog Catalog Blog Directory

© 2007 Performance Testing, LoadRunner Tips&Tricks | Blogger Templates by GeckoandFly.
No part of the content or the blog may be reproduced without prior written permission.
Learn how to make money online | First Aid and Health Information at Medical Health