How MS-DOS 6.22 Manages Conventional Memory

MS-DOS 6.22 manages conventional memory—the foundational 640 kilobytes (KB) of random-access memory—by structuring it into a continuous sequence of allocated and free regions tracked by linked data structures called Memory Control Blocks (MCBs). Operating in real mode on x86 processors, the operating system sits directly in this address space, allocating portions of it to system files, device drivers, terminate-and-stay-resident (TSR) programs, and active software applications. By using specific allocation strategies like First Fit, Best Fit, and Last Fit, MS-DOS 6.22 ensures that programs receive the contiguous memory blocks they require while attempting to preserve as much space as possible in the Transient Program Area for user applications.

The 640 KB Conventional Memory Layout

Conventional memory spans the physical address range from 00000h to 9FFFFh (0 to 640 KB). In MS-DOS 6.22, this space is partitioned strictly from the bottom up:

  1. Interrupt Vector Table (IVT): Occupies the first 1,024 bytes (00000h to 003FFh). It holds pointers (segment:offset) to hardware and software interrupt handlers.
  2. BIOS Data Area (BDA): Located directly above the IVT (00400h to 004FFh), storing basic hardware states, keyboard buffers, and display configurations.
  3. DOS Data and Kernel Code: The system files (IO.SYS and MSDOS.SYS) initialize right above the BDA. This area contains low-level device drivers, internal buffers, and core operating system routines.
  4. Resident Drivers and TSRs: Drivers loaded via CONFIG.SYS (using DEVICE=) and background utilities executed from AUTOEXEC.BAT claim the space immediately following the kernel.
  5. Transient Program Area (TPA): The remaining contiguous free memory extending up to the 640 KB barrier. This is the primary execution area where user applications are loaded, executed, and terminated.

Memory Control Blocks (MCBs)

MS-DOS 6.22 tracks every block of memory in the TPA using Memory Control Blocks, often referred to as "arena headers." An MCB is a 16-byte (one paragraph) data structure placed immediately before the memory block it describes.

An MCB contains three primary pieces of metadata:

  • Block Type (1 byte): Contains the ASCII character 'M' (4Dh) if it is an intermediate block in the chain, or 'Z' (5Ah) if it is the final block in the memory chain.
  • Owner PID (2 bytes): The segment address of the Program Segment Prefix (PSP) that owns the memory. If this field is set to 0000h, the block is free and unallocated.
  • Size (2 bytes): The length of the memory block immediately following the MCB, represented in 16-byte paragraphs.

Because each MCB records the size of its memory block, MS-DOS navigates the entire memory map as a singly linked list. To find the next MCB, the operating system adds the current MCB's segment address, its recorded paragraph length, and one paragraph (the MCB itself). If the chain is corrupted—such as when a misbehaving program overwrites an MCB—MS-DOS halts the system with the error: "Memory allocation error. Cannot load COMMAND, system halted."

Allocation Strategies via Interrupt 21h

Applications interact with conventional memory through MS-DOS API functions invoked via INT 21h:

  • Function 48h (Allocate Memory): Requests a specific number of paragraphs.
  • Function 49h (Free Memory): Releases an allocated block back to the pool.
  • Function 4Ah (Modify Allocation): Shrinks or expands an existing allocated block.

To determine which free block to assign when a program calls Function 48h, MS-DOS 6.22 relies on an internal allocation strategy (controllable via INT 21h, Function 58h):

  • First Fit (Default): Searches the MCB chain from the lowest address upward and allocates the first free block large enough to satisfy the request.
  • Best Fit: Scans the entire chain to locate the smallest free block that fulfills the requested size, reducing internal fragmentation.
  • Last Fit: Searches the chain and allocates the highest available memory block, keeping lower conventional memory free for large application loads.

Minimizing Conventional Memory Footprint

Because MS-DOS 6.22 and its resident programs share the same 640 KB limit as running software, the operating system includes mechanisms to minimize its conventional footprint:

  • HMA Offloading: When configured with DOS=HIGH in CONFIG.SYS, MS-DOS moves substantial portions of the kernel code out of conventional memory into the High Memory Area (the first 64 KB of extended memory above 1 MB, enabled by HIMEM.SYS).
  • Upper Memory Blocks (UMBs): When configured with DOS=UMB alongside EMM386.EXE, MS-DOS extends its MCB chain into Upper Memory (between 640 KB and 1024 KB). This allows device drivers and TSRs to be loaded into upper memory via DEVICEHIGH and LOADHIGH, preserving the maximum amount of contiguous conventional memory for primary executable tasks.