Difference between revisions of "DOS memory management"
(→High memory area) |
(→Upper memory) |
||
Line 10: | Line 10: | ||
=== Upper memory === | === Upper memory === | ||
− | The upper memory is memory in the range between 640 kb and 1 Mb. By default there is no RAM in this range as it is reserved for use with hardware that is able to map own memory to this range. Usually present in this region is a part of the graphics cards RAM and the BIOS ROMs of the graphics card and mainboard. Additional hardware like mass storage controllers, network adapters... can use additional parts for own BIOS ROMs or buffer RAM. Mainboard chipsets allow to map blocks of mainboard RAM in the remaining unused memory range. These blocks are called Upper Memory Blocks (UMB) and are treated from DOS as High Memory. The default memory management driver that enables this mapping is EMM386.EXE. It has to be loaded in config.sys as second driver after HIMEM.SYS. The driver tries to detect common unused blocks and maps UMBs there. | + | The upper memory area is memory in the range between 640 kb and 1 Mb. By default there is no RAM in this range as it is reserved for use with hardware that is able to map own memory to this range. Usually present in this region is a part of the graphics cards RAM and the BIOS ROMs of the graphics card and mainboard. Additional hardware like mass storage controllers, network adapters... can use additional parts for own BIOS ROMs or buffer RAM. Mainboard chipsets allow to map blocks of mainboard RAM in the remaining unused memory range. These blocks are called Upper Memory Blocks (UMB) and are treated from DOS as High Memory. The default memory management driver that enables this mapping is EMM386.EXE. It has to be loaded in config.sys as second driver after HIMEM.SYS. The driver tries to detect common unused blocks and maps UMBs there. |
− | TSR-programs can be loaded to UMBs (in High Memory) in config.sys by using ''DEVICEHIGH=driver.sys'' or in autoexec.bat with the loadhigh statement, like ''LH driver.com''. If no High RAM is avilable the drivers will be loaded to Conventional Memory. | + | TSR-programs can be loaded to UMBs (in High Memory) in config.sys by using ''DEVICEHIGH=driver.sys'' or in autoexec.bat with the loadhigh statement, like ''LH driver.com''. If no High RAM is avilable the drivers will be loaded to Conventional Memory. The external program MEM reports the amount of High RAM. Parts of DOS can be loaded into Upper Memory Blocks by specifying DOS=UMB in config.sys but usually it is better to load DOS to the High Memory Area leaving Upper Memory Blocks free for TSR-programs. |
− | The external program MEM reports the amount of High RAM. | + | |
− | + | ||
=== High memory area === | === High memory area === |
Revision as of 08:44, 11 April 2013
With modern operating systems, all memory management you need to do is installing enough RAM. And that's it. The OS determines how to use it, and you usually don't need to worry about it at all. In DOS hardware and memory access is closely related to the standards defined by the x86 architecture. In DOS memory is split into different regions and there are several standards as EMS and XMS for accessing memory. To use the available RAM effectively in DOS you have to know how the x86 architecture splits up RAM, what these different regions are for. It is also helpful to know the most common memory management drivers. Optimizing your system to attain enough free memory for your programs is called memory management.
This page will try to explain, in simple language, all the technical terms you will encounter in DOS memory management, and provide you with practical information to get your favorite games and programs running. If you really want to understand how this all works, see the Wikipedia article on DOS memory management, or use your web search engine of choice.
Contents
Types of memory
Conventional memory
Conventional memory or base memory is the memory range between 0 kb and 640 kb. Programs are loaded to this memory range. The available free memory can be lower as some drivers have to leave a part of their code in memory to handle e.g. hardware. This is called Terminate and Stay Resident (TSR). By default such drivers are placed in conventional memory. The amount of free conventional memory is reported by CHKDSK or MEM.
Upper memory
The upper memory area is memory in the range between 640 kb and 1 Mb. By default there is no RAM in this range as it is reserved for use with hardware that is able to map own memory to this range. Usually present in this region is a part of the graphics cards RAM and the BIOS ROMs of the graphics card and mainboard. Additional hardware like mass storage controllers, network adapters... can use additional parts for own BIOS ROMs or buffer RAM. Mainboard chipsets allow to map blocks of mainboard RAM in the remaining unused memory range. These blocks are called Upper Memory Blocks (UMB) and are treated from DOS as High Memory. The default memory management driver that enables this mapping is EMM386.EXE. It has to be loaded in config.sys as second driver after HIMEM.SYS. The driver tries to detect common unused blocks and maps UMBs there. TSR-programs can be loaded to UMBs (in High Memory) in config.sys by using DEVICEHIGH=driver.sys or in autoexec.bat with the loadhigh statement, like LH driver.com. If no High RAM is avilable the drivers will be loaded to Conventional Memory. The external program MEM reports the amount of High RAM. Parts of DOS can be loaded into Upper Memory Blocks by specifying DOS=UMB in config.sys but usually it is better to load DOS to the High Memory Area leaving Upper Memory Blocks free for TSR-programs.
High memory area
The High Memory Area (HMA) are the 64 kb directly above 1 Mb. To use HMA it is required to load HIMEM.SYS in config.sys that enables the A20-gate to gain access to memory beyond 1 Mb. The HMA is typically used to move parts of DOS there that normally occupy conventional memory. For this in config.sys the line DOS=HIGH has to be specified. The external program MEM reports if DOS is using the HMA.
Expanded memory
EMS (todo)
Extended memory
XMS (todo)
Memory management
Getting more conventional memory
A challenging aspect of DOS memory management can be to free enough conventional memory. Often games require a high amount of free conventional memory and sometimes also free EMS or XMS. To achieve this you have to use memory managers that allow e.g. enabling of UMBs and installation of APIs for XMS and EMS access. The availability of memory types depends on CPU and chipset.
On 286 CPUs special chipset support is required to enable UMBs. Rather well supported is the NEAT chipset. The HIMEM.SYS driver takes control of the A20-gate, makes HMA available and installs a XMS API. It is also possible to emulate a EMS page frame with the EMM286 driver.
386 and later CPUs feature an protected mode extension called Virtual 8086 mode that allows mimicking a 8086 memory layout for applications. With MS-DOS 5 a second memory manager was included called EMM386.EXE that uses the advanced features of 386 CPUs. It is loaded after HIMEM.SYS and enables UMBs and EMS emulation. This allows to load TSRs to UMBs freeing conventional RAM. The corresponding load statement in config.sys is DEVICEHIGH= and in autoexec.bat LOADHIGH which can be shortened to LH. EMM386 switches the CPU to Virtual 8086 mode.
(todo UMBPCI)
Generally memory managers must be loaded first. As rule of thumb TSRs taking more memory should be loaded before small TSRs to prevent memory fragmentation. Some drivers require a specific load order e.g. SMARTDRV.EXE after MSCDEX.EXE if the CD-ROM should be read cached. Some TSRs do not work correctly when loaded to upper memory, resulting in crashs or erratic system behavior. If you notice any instability in your DOS system, try to move TSRs back into conventional memory to find the culprit. You may look for driver alternatives or in worst case need to change hardware. Mainboard BIOS, graphic card BIOS and also additional cards as mass storage controllers or network cards use the memory area between 640K and 1 MB sharing space with UMBs. Especially newer graphic cards and mainboards are not designed with DOS in mind and are delivered with large BIOSes (> 32 kB). This can reduce available UMBs considerably. A classic DOS system has about 128 kB to 192 kB free UMBs for TSRs. Using EMS emulation requires a 64 kB area between 640K and 1 MB where the page frame of a virtual EMS card is mapped. If not required EMS emulation can be disabled freeing 64 kB of UMBs.
(todo: expand)
Software
(todo: list of memory managing software?)