Memory and MS Windows Enhanced Mode The following information was obtained from Microsoft Online services. -------------------------------------------------------------------- | INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY | | ACCOMPANY THIS DOCUMENT (collectively referred to as an | | Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY | | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO | | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A | | PARTICULAR PURPOSE. The user assumes the entire risk as to the | | accuracy and the use of this Application Note. This Application | | Note may be copied and distributed subject to the following | | conditions: 1) All text must be copied without modification and | | all pages must be included; 2) If software is included, all files | | on the disk(s) must be copied without modification (the DOS | | utility DISKCOPY is appropriate for this purpose); 3) All | | components of this Application Note must be distributed together; | | and 4) This Application Note may not be distributed for profit. | | | | Copyright 1990 Microsoft Corporation. All Rights Reserved. | | Microsoft and the Microsoft logo are registered trademarks of | | Microsoft Corporation. | -------------------------------------------------------------------- ENHANCED MODE WINDOWS 3.00 ========================== Entering the world of virtual memory Enhanced Mode and Conventional Memory ------------------------------------- Windows 3.00 enhanced mode deals with conventional memory in much the same way as standard mode. When enhanced mode Windows 3.00 is executed, it adds the amount of free conventional and extended memory, but in addition, Windows 3.00 combines a virtual hard drive memory factor and looks at the total amount as one contiguous block of memory. Conventional memory has no special meaning under enhanced mode, except when running DOS applications. Enhanced mode runs DOS applications by creating virtual DOS machines up to 640K in gross size. Each virtual DOS machine inherits the environment that was present before Windows enhanced mode was executed. This means that every driver and TSR loaded before you run Windows is present and consumes memory in every subsequent virtual DOS machine. The net memory available within virtual DOS machines under enhanced mode is slightly less than the free memory at the DOS prompt before you start Windows. Enhanced Mode and the 384K Reserved I/O Address Space ----------------------------------------------------- Windows/386 versions 2.x use the 384K reserved I/O address space only to place the expanded memory page frame, and then to a maximum of only four 16K pages. Windows 3.00 enhanced mode uses the 384K reserved I/O address space for two purposes: 1) to place DOS protected mode application program interface (API) translation buffers, and 2) to place the expanded memory page frame (if required). Frequently, all of the free pages in the 384K reserved I/O address space are utilized by enhanced mode. API TRANSLATION BUFFERS IN THE 384K RESERVED I/O ADDRESS SPACE Although Windows 3.00 enhanced mode breaks the 640K barrier for Windows applications, it still runs on top of DOS. The copy of DOS upon which Windows is running can execute and access data only within conventional memory. The same restriction applies to network software or other drivers loaded before enhanced mode Windows. Enhanced mode allocates buffers in the 384K reserved I/O address space to translate DOS and network API calls from protected mode to real mode. Since the 384K reserved I/O address space is within the first megabyte of address space, it can be accessed by DOS in real mode. The translation buffers are used as a window through which applications executing in protected mode can pass information to and from DOS and the network. Ideally, there would be enough free space in the 384K reserved I/O address space to place both the translation buffers and the expanded memory page frame. Yet on many configurations there isn't enough room. This means you have to make a choice. Either the expanded memory page frame can be eliminated or the translation buffers can be allocated in conventional memory instead of in the 384K reserved I/O address space. If the translation buffers are allocated in conventional memory, they take up space in every virtual machine from Windows that you create. You will have less space in virtual machines to run DOS applications. The translation buffers can be allocated either in the 384K reserved I/O address space or in conventional memory, but never half-and-half. Fortunately, Windows 3.00 enhanced mode provides a method for specifying your preference. To do this, place the following switch in the [386ENH] section of the SYSTEM.INI: ReservePageFrame=Boolean If ReservePageFrame=true (the default), enhanced mode Windows allocates the page frame first and the translation buffers second. This makes it likely that the translation buffers will be forced into conventional memory but allows you to use expanded memory in DOS applications. If ReservePageFrame=false, the translation buffers are allocated first and the page frame second if there is still room. This setting gives you the most free memory within virtual machines, but you may not be able to use expanded memory in DOS applications. However, remember that Windows applications do not need expanded memory to function; only DOS applications that can utilize expanded memory will be affected. One important note: If you are using the EMM386.SYS driver, translation buffers are always placed in conventional memory. PAGE FRAME PLACEMENT IN THE 384K RESERVED I/O ADDRESS SPACE As noted in the expanded memory discussion earlier in this document, expanded memory support requires a page frame located in the 384K reserved I/O address space. With LIM 4.0 expanded memory, it is not necessary to have a 64K contiguous page frame in this area. It's not necessary to have a page frame at all in LIM 4.0. Still, if you want to use expanded memory in your DOS applications, you must have a 64K contiguous page frame. This is composed of four contiguous 16K pages in the 384K reserved I/O address space. On a typical IBM machine there are only eight free 16K pages in the 384K reserved I/O address space (refer to Figure 2). Four contiguous pages are required for expanded memory support in DOS applications, leaving only four other free pages. Other cards such as network adapters and ESDI hard disk controllers also need to occupy pages in the 384K reserved I/O address space. Frequently the combination of installed adapters can break up the free area in the 384K reserved I/O address space so there is no 64K contiguous area in which to place the page frame. In this case, you will not see any free expanded memory in your DOS applications running under Windows 3.00 enhanced mode. If you experience this problem, you may need to rearrange your adapter memory locations to get expanded memory support for DOS applications. This is easiest to do on machines using the Micro Channel Architecture (MCA) or Extended Industry Standard Architecture (EISA) bus standards. IBM Personal System/2 models 50 and above are equipped with the Micro Channel bus. The PS/2 machines allow you to change adapter memory locations simply by booting with the PS/2 Reference Disk and choosing Change Configuration. A similar procedure is available on most EISA bus machines such as the COMPAQ SYSTEMPRO and HP Vectra 486. Normal Industry Standard Architecture (ISA) bus machines such as the IBM AT and COMPAQ 386 may require you to open the case and flip DIP switches on the cards to change their memory addresses. Use Figure 2 as a handy worksheet when readdressing adapters to open a 64K page frame. If you want, you can disable expanded memory support entirely under Windows 3.00 enhanced mode by adding the NoEMMDriver=yes parameter in the [386ENH] section of the SYSTEM.INI file. CONTROLLING ENHANCED MODE 384K RESERVED I/O ADDRESS SPACE MAPPING In Windows/386 versions 2.x, the WIN.INI parameters EMMExclude= and EMMInclude= are used to control expanded memory page frame placement. These parameters are used under Windows 3.00 enhanced mode to control not only the expanded memory page frame but also the API translation buffer mapping. Under Windows 3.00 these switches begin with the letters EMM only for downward compatibility reasons. They no longer apply only to expanded memory. The EMMPageFrame= parameter still applies only to the expanded memory page frame. In Windows 3.00 these switches have been moved from the WIN.INI file to the [386ENH] section of the SYSTEM.INI. Windows/386 versions 2.x do not use the E000-EFFF area of the 384K reserved I/O address space unless specifically instructed. Windows 3.00 enhanced mode will use this segment unless the machine identifies itself as a PS/2. To explicitly exclude an area of the 384K reserved I/O address space from mapping by Windows 3.00 enhanced mode, use the EMMExclude= statement. The EMMExclude= parameter accepts a four- digit hexadecimal memory range, such as EMMExclude=E000-EFFF. Since there is no standard for hardware implementation of the E000-EFFF area, it is frequently necessary to exclude this range for enhanced mode to function properly. Most adapter cards are automatically detected and excluded by Windows 3.00 enhanced mode. If you suspect a problem with a 384K reserved I/O address space memory conflict, use EMMExclude=. There are very few uses for the EMMInclude= statement. Normally Windows 3.00 enhanced mode automatically uses all free pages in the 384K reserved I/O address space. Likewise, there are few uses for the EMMPageFrame= statement, since it controls only the expanded memory page frame and not the translation buffers. The Windows/386 2.x LastEMMSeg= parameter is not used by Windows 3.00. Enhanced Mode and Expanded Memory --------------------------------- Windows 3.00 enhanced mode does not use expanded memory itself. It can create expanded memory for use by DOS applications written to use expanded memory, such as Lotus 1-2-3. Expanded memory required by a DOS application can be specified in the Advanced section of the application's PIF. It is no longer necessary for Windows applications to use expanded memory because they can now access extended memory directly. The main issues for expanded memory under Windows 3.00 are page frame conflicts, as discussed above. Windows/386 versions 2.x provide large page frame expanded memory only for the Windows virtual machine. Windows 3.00 enhanced mode provides large page frame LIM 4.0 expanded memory in all virtual DOS machines. This is not currently useful for most DOS applications that use expanded memory. Most DOS applications use only the 64K page frame itself, not the additional bankable pages in conventional memory that large page frame LIM 4.0 supplies. However, this feature may be useful in the future. A compatible external 386 memory manager such as EMM386.SYS can be loaded to provide expanded memory for DOS applications running outside of Windows 3.00 enhanced mode. Note: EMM386.SYS is specifically designed to work in conjunction with Windows 3.00. This driver is not needed to have expanded memory available inside of Windows 3.00 and is actually turned off when Windows 3.00 enhanced mode is run. See the "Expanded Memory for DOS Applications" section of this application note for more information. Enhanced Mode and Extended Memory --------------------------------- Like standard mode, Windows 3.00 enhanced mode can access extended memory directly. It adds the free conventional memory and free XMS extended memory plus a virtual hard drive memory factor. It then provides the total as memory for Windows applications to use (minus the memory required by enhanced mode Windows itself). DOS applications that use XMS memory can also access XMS in virtual machines under enhanced mode Windows. The XMS memory supplied to DOS applications by Windows 3.00 enhanced mode can be virtualized. RUNNING PROTECTED MODE DOS APPLICATIONS Windows enhanced mode allows DOS applications to run in protected mode if they are written to use the Microsoft DOS Protected Mode Interface (DPMI) specification. NOTE: Enhanced mode uses the XMS to initially load itself and its drivers into extended memory before starting up. This is why enhanced mode requires the presence of HIMEM.SYS, the XMS device driver. Enhanced Mode and Virtual Memory -------------------------------- A VIRTUAL MEMORY CONCEPTUAL ANALYSIS Virtual memory gives you the ability to run more simultaneous programs than the amount of physical memory installed on your computer would normally allow. Virtual memory has been widely used for years in the world of mainframe computers and recently came to the IBM world with the introduction of the IBM/Microsoft OS/2 operating system, which is based on the 80286 processor. Windows 3.00 enhanced mode goes beyond the world of OS/2 to offer virtual memory using the special demand paging capabilities of the Intel 80386 processor. The best thing about virtual memory in Windows 3.00 enhanced mode is that programs do not need to be written specifically to take advantage of it. When you start Windows 3.00 enhanced mode and from the Help menu, choose Help About Program Manager, you will see that much more memory is available than is installed in your machine. Windows applications can use this extra memory without being written specially for it because Windows applications are device independent. They let Windows handle the memory management and simply ask Windows for memory allocations. With virtual memory, Windows applications keep asking for more memory, which Windows 3.00 enhanced mode is now able to deliver. If you have less memory, the application runs slower; if you have more memory, it runs faster; but it is almost always able to run. At any given moment during the execution of a program, some parts of its code and data are in physical memory; the rest is swapped to the hard disk. Whenever a reference is made to a memory address, if the information is currently in physical memory, it is used without program interruption. If the information isn't in physical memory, a page fault occurs. The Windows 3.00 enhanced mode virtual memory manager takes control. The required code or data is pulled into physical memory from the hard disk, and if necessary, some other information is swapped out. Pages are swapped out on a least recently used (LRU) basis. The page(s) that have not been accessed for the longest time are the first to be swapped out. All this swapping occurs without notice to the user, who sees only a little hard disk activity. Windows 3.00 enhanced mode virtual memory is a demand-paged system. This means that pages of data are brought into physical memory when they are referenced. A demand-paged system does not attempt to predict what pages will be required in the future. The enhanced mode virtual memory subsystem is implemented by the Windows 3.00 Virtual Memory Manager (VMM) along with the pageswap device. The VMM maintains the virtual memory page table. The page table lists which pages are currently in physical memory and which are swapped to disk. Because Windows 3.00 enhanced mode is a multitasking environment, the VMM page table also contains a list of which memory pages belong to which process. When the VMM needs a page that is not currently in physical memory, it calls the pageswap device. Pageswap allocates and deallocates virtual memory and maps pages into and out of physical memory. Some virtual memory systems rely on program segmentation to do their work. Windows applications are segmented. However, virtual memory under Windows 3.00 enhanced mode is not related to the segmentation of Windows applications. All memory, virtual and physical, is divided into 4K pages and the system is managed on this basis. Page mapping starts at 0 kilobytes and works up. There are two kinds of pages that can be allocated: physical pages and virtual pages. The amount of physical pages is simply the amount of physical memory in the machine divided by 4K. In contrast, memory allocated to an application is made up of virtual pages. At any given time, a virtual page can be in physical memory or swapped to the hard disk. As mentioned above, Windows 3.00 enhanced mode virtual memory management uses the least recently used (LRU) page replacement algorithm. The virtual page table contains flags for each page that indicate whether the page has been "accessed" and if the page is "dirty." Accessed means that a process has made a reference to the page since it was originally loaded. Dirty means that a write has been made to the page since it was loaded. Because a memory write qualifies as an access, the Dirty attribute implies the Accessed attribute. To illustrate, assume Windows 3.00 enhanced mode is out of physical memory space. A process requests additional memory. Windows has to decide which page(s) currently in physical memory it should swap to disk to fulfill the request. This decision is a three-step process: 1. The virtual memory manager scans the page table, looking for pages that have neither an Accessed nor a Dirty attribute. During the scanning process, it clears the Accessed attribute from all the pages. 2. If it can find enough pages meeting the not Accessed/not Dirty requirement, it fulfills the request. It swaps the pages to disk and gives the resulting free memory to the process. 3. If it can't find enough pages the first time through, it repeats the scan. Yet this time through, none of the pages has an Accessed attribute because it was cleared by the first scan. Theoretically, therefore, more pages will meet the requirements, and the request can be fulfilled. If the required pages are still not found by the second scan, Windows then swaps out the pages regardless of their attributes. The benefit of Windows 3.00 enhanced mode virtual memory support is the ability to run more programs than could be supported by actual physical memory. The drawbacks are the disk space requirement for the virtual memory swap file and a decrease in overall execution speed when swapping is required. However, it's better to be able to run a program slowly in a virtual memory system than not to be able to run it at all. VIRTUAL MEMORY PAGING FILE OPTIONS AND CONTROLS Windows 3.00 enhanced mode can use one of two types of virtual memory paging files, or swap files: temporary or permanent. Only one type of swap file can be used when running Windows 3.00. Do not attempt to create a swap file on a RAMDisk. Creating a swap file on a RAMDisk is a self-defeating pursuit -- you would be sacrificing physical memory to provide a place to create virtual memory to replace the physical memory you have used to create the RAMDisk. Windows 3.00 in 386 enhanced mode requires a minimum of approximately 1.5 megabytes of hard disk space free on the paging drive to provide virtual memory support with a temporary swap file. A temporary swap file is simply a normal DOS file created on the hard disk that can shrink and grow in size as necessary. The temporary swap file is called WIN386.SWP. It does not have a Hidden or System attribute and can be deleted at any time you are not currently running Windows, if necessary. It is normally deleted automatically when you exit Windows 3.00 enhanced mode. This temporary swap file is the default swap file that Windows 3.00 uses and is created automatically when Windows 3.00 is started. Temporary swap file location and size can be adjusted by inserting parameters in the [386ENH] section of the SYSTEM.INI file. The temporary swap file is always created in your Windows 3.00 directory unless you set the PagingDrive= parameter. If the PagingDrive= parameter is set (for example, PagingDrive=D:), the swap file will be created in the root directory of the specified drive. There is no way to specify a subdirectory for the temporary swap file location. Temporary swap file size is controlled by the MaxPagingFileSize= parameter. The size of the temporary swap file can also be limited in a different way by the use of the MinUserDiskSpace= parameter, which tells enhanced mode to leave the specified amount of disk space in kilobytes free when creating a temporary swap file. A permanent swap file occupies a contiguous section of your hard disk. Because it is contiguous, using a permanent swap file moderately improves the speed of the Windows 3.00 virtual memory system, and its access requires less overhead than a normal DOS file. The permanent swap file is a hidden file called 386SPART.PAR, which also has a System attribute. It is always placed in the root directory. Since the permanent swap file must be contiguous, you can't create a permanent swap file larger than the largest contiguous free segment of your hard disk. Permanent swap files are created and deleted with the Windows 3.00 SWAPFILE.EXE utility program. A SYSTEM.INI parameter is not used to point to the location of the permanent swap file. Instead, the Swapfile utility program creates a SPART.PAR file in your Windows 3.00 directory. Windows 3.00 enhanced mode reads the SPART.PAR file to find out where the permanent swap file is and how large it is. SPART.PAR is marked read-only to keep you from accidentally deleting it. If you delete SPART.PAR, Windows will not know about the permanent swap file. Also you can't delete the permanent swap file with the Swapfile utility because Swapfile also reads SPART.PAR. The Swapfile utility makes DOS calls that cannot be made from protected mode Windows. Therefore, SWAPFILE.EXE can be run only from real mode Windows 3.00 to create or delete a permanent swap file and cannot run with other applications. If the Swapfile utility program says that the maximum swap file size it can create is smaller than your free disk space, your hard disk is fragmented. If you want to create a larger permanent swap file, you must optimize your hard disk (optimizing is also known as unfragmenting, or compacting). This must be done with a third-party utility program such as Bridgeway Publishing FastTrax, Norton Utilities, Mace Utilities, Golden Bow VOpt, or Central Point PCTools. If you have already created a permanent swap file, make sure to delete it using the Swapfile utility program before optimizing your hard disk. It is not necessary to delete the permanent swap file every time you optimize your hard disk -- only when you want to increase the size of the permanent swap file by optimizing, then re-creating it. The Swapfile utility program supports only disks that use 512-byte sectors. If 512-byte sectors are not being used, this indicates a nonstandard configuration such as a third-party disk partitioning driver. Swapfile (and Windows 3.00 itself) supports drives with 512-byte sectors that have been partitioned with the DOS FDISK utility. Never run Swapfile on a drive that uses a partitioning driver in the CONFIG.SYS, with the exception of COMPAQ's ENHDISK.SYS. If you receive a message that your swap file is corrupted, run the Swapfile utility, delete the current swap file, and create a new one. PAGING TO NETWORK DRIVES Paging to a network drive, while certainly possible, is extremely slow and is not recommended. Only temporary swap files can be used on network drives. If you want to page to a net drive, the directory must not have a DOS Read-Only attribute. You must have Create and Write access to the directory. Note that because they are not MSNet-Redirector compatible, the root of a Novell network drive is the root of the server. Do not set the PagingDrive= parameter to a Novell network drive. If you do so and multiple users run Windows 3.00 enhanced mode, their computers will hang because they will overwrite each other's swap files, all with the same name and all created in the root directory of the server. ms-windows