TOPIC
Why is the RAM requirement lower for a program when virtual memory (VM) is running? When you do a Get Info on an application on a Power Macintosh you get an additional message that gives a lower memory requirement if you have virtual memory turned on. Since this still looks like RAM to the application, why is there a lower RAM requirement?
DISCUSSION
Overview With the introduction of Power Macintosh, virtual memory, the ability to assign part of a hard drive as if it were additional physical memory, gains advantages over previous systems. By enabling virtual memory, Power Macintosh computers are able to utilize a feature called file mapping, which can significantly reduce the amount of physical memory required to launch a native application. Enabling Virtual Memory reduces the overall memory requirements of large native Power Macintosh applications. After enabling Virtual Memory, the Application Partition is substantially smaller and the System Partition increases by a relatively small amount. In a sampling of native Power Macintosh applications, we found the average RAM required to launch an application was almost 2 MB less when virtual memory was enabled. In the past, the only reason to enable virtual memory was to simulate the addition of real memory to a system. With Power Macintosh, simply enabling virtual memory without adding any virtual space has the desirable effect of reducing the application RAM footprint. Excerpts from "Inside Macintosh: PowerPC System Software" Without Virtual Memory When virtual memory is not enabled, the application's Stack (temporary data storage), Heap (dynamically allocated storage), and all Code Fragments (Executable PowerPC code) must load into the Application Partition, resulting in increased launch times and RAM requirements for large applications. With Virtual Memory With Virtual Memory enabled, only the application's Stack and Heap load into the Application Partition, reducing the launch times and RAM requirements for native applications. The application's Code Fragments are then tracked by the Virtual Memory Manager, which only writes the Code Fragments to the System Partition when needed, resulting in fewer Code Fragments loaded into memory at one time. As an additional benefit, the Operating System assumes the application's code section is always read-only, meaning that, when it's time to remove some of the application's code from memory (to page in other code or data), the Virtual Memory Manager doesn't need to write the code back to the hard disk. Instead, it simply purges the code from the System Partition and writes new code to the System Partition, reducing the time required to load applications code. Virtual Memory Benefits So, by enabling Virtual Memory you have these benefits: How Virtual Memory on Works on 680x0 Macintosh On a 680x0 Macintosh, the Segment Loader loads as much of the application as possible into memory, which is dictated by both the amount of available memory and the application's heap size (set using the Finder's Get Info dialog). If you want to increase an 8 MB system to 12 MB by using Virtual Memory, the system creates a 12 MB space on disk. When instructions or data are accessed by the system, and are not resident in memory, a "page fault" occurs. A page fault causes the system to write the least recently used "page" to disk and then satisfies the page fault by "swapping" in the page which contains the required data. This mechanism is designed to keep the most frequently used pages in physical memory ("working set") and the least frequently used ones on disk. The task of keeping all the locations straight is the job of virtual memory and the Memory Management Unit (MMU). How Power Macintosh VM Is Different With native applications on Power Macintosh, there is no Segment Loader. When virtual memory is disabled, applications are loaded into memory as a contiguous block. The amount of space required for all of the code in a single application can be quite large. However, Power Macintosh applications are written to a strict new specification for the types of data that reside in the data and resource forks. In particular, the data fork contains read-only data for the application, whereas the resource fork contains information that can be modified. This is an important distinction because these rules, with virtual memory enabled, let the Code Fragment Manager (CFM) take advantage of file mapping. With file mapping active, only some of the resource fork needs to be loaded into memory. Items in the data fork of the application can remain on disk and will be "mapped" into memory by the CFM as needed. This has the advantage of dramatically reducing the amount of data that has to immediately copied into memory at application launch time. Additionally, read-only items in the data fork can be trashed when a page fault occurs, rather than writing the old information out to disk. This reduces a write-read cycle, to a single read. This is why Power Macintosh virtual memory performance is improved over 680x0, even though the core code is unchanged. The Modern Memory manager does not affect how the Virtual Memory Manager handles Code Fragments. So, enabling Virtual Memory and not enabling the Modern Memory has the same result. Virtual Memory Diagram The following diagram may be helpful in describing how Virtual Memory affects RAM requirements. The left column lists possible memory configuration for a Power Macintosh with three native applications with virtual memory enabled. The right column is for three native applications with virtual memory not enabled. The center column provides possible memory requirements. Power Macintosh with Physical Power Macintosh with Virtual Memory Enabled RAM Virtual Memory not Enabled ---------------------- ------- -------------------------- System Software 1MB System Software System Partition *** System Partition Application A, Code Section 1 2MB Application A Partition Application B, Code Section 1 *** Heap Application C, Code Section 1 3MB Stack Application A Partition *** Application A, Code Section 1 Heap 4MB Application A, Code Section 2 Stack *** Application A, Code Section 3 Application B Partition 5MB Application A, Code Section 4 Heap *** Application B Partition Stack 6MB Heap Application C Partition *** Stack Heap 7MB Application B, Code Section 1 Stack *** Application B, Code Section 2 8MB Application B, Code Section 3 *** Application B, Code Section 4 9MB Application C Partition *** Heap 10MB Stack *** Application C, Code Section 1 11MB Application C, Code Section 2 *** Application C, Code Section 3 12MB Application C, Code Section 4 Because of file-mapping and the Code Fragment Manager, most Power Macintosh users will want to activate virtual memory. For those wishing to take advantage of increased memory space, Apple recommends setting virtual memory on Power Macintosh computers to 50% more than the amount of physical memory. Example: If you have 8MB of RAM, set the system to 12 MB in the Memory control panel. Customers who want the highest performance possible, but still want the benefits of the reduced application footprint of file-mapping, can set virtual memory to the minimum amount of 1 MB more than physical RAM. Example: If you have 8 MB of RAM, set the system to 9 MB in the Memory control panel. |
Document Information | |
Product Area: | Mac OS System Software |
Category: | General OS |
Sub Category: | General Topics |
Keywords: | kppc, kalley |
Copyright © 2000 Apple Computer, Inc. All rights reserved.