DOS MEMORY MANAGEMENT
The memory manager of DOS has a relatively simple job – it’s managing a single job for a
single user. To run a second process, the user must pause or close the first one.
Originally used first fit method for early versions. Most efficient for single user
environment.
First one megabyte of memory would be:
Reserved for BIOS (1M)
Unused
------------------------- (640K)
Transient part of
Command.com
-------------------------
User Memory (transient program area, TPA)
-------------------------
TSR programs
-------------------------
Resident part of
Command.com
-------------------------
Installable drivers
------------------------
Buffer cache
------------------------
MS-DOS kernel
------------------------
BIOS interface
------------------------
Interrupt vector
------------------------ (0M)
If the user needed more space, can use transient portion of command.com. Is re-loaded after
process is complete. The transient portion is where commands that can’t be executed while a
program is running reside.
First version of DOS gave all the memory to the resident application, but didn’t allow
applications to dynamically allocate and deallocate memory blocks. Version 2 supported dynamic
allocation, modification and release of main memory blocks by the application.
Programs with COM extension given all TPA.
Programs with EXE extension given only amount of memory then need. These files have a header
indicating minimum and maximum amount of memory to run. Ideally, DOS gives maximum, but if not
possible, tries to satisfy the minimum. If not enough for minimum, program won’t run.
Except for COM files there can be any number of files in the TPA at one time, even though DOS
can only run one at a time. By having several files in memory at once, the user can open one and
work on it and close it before starting on the next. User can use two or more programs quickly
and easily. E.g. a word processing package may allow user to display two files on the screen as
split screen. One active, the other dormant. Switch to dormant screen indicates that other file
should become active. A spellchecker is an example of a process that becomes active as your word
processor becomes dormant.
If a program when running should need more memory, memory manager checks to see whether there
is enough memory left. If there is, will allocate it and update status of memory blocks. If not,
will report error to the user.
The initial DOS memory manager allocated memory by using a first fit algorithm and a linked
list of memory blocks. With Version 3 and above, best-fit or last-fit can be selected. In
last-fit, DOS allocates the highest addressable memroy block big enough.
Size of the block can vary from 16 bytes (called a paragraph) to maximum available memory.
When a block is formed, first five bytes contain following info:
- Byte 0 : 90h if it’s the last block, 77h if it is not
- Bytes 1-2: includes 0 to indicate busy block and pointer to the Program Segment Prefix
that is created when the program is loaded.
- Bytes 3-4: Gives the number of paragraphs contained in the block.
If a block contains four paragraphs and is the first of two blocks its code would be :
7700000004h
When memory request arrives, DOS looks through the free/busy list, until it finds a free block
that’s fits the request. . If the link list of blocks becomes disconnected, computer must be
re-booted. Well designed application program releases memory blocks it no longer needs. It is
merged back into list. Badly designed program will hoard its memory blocks until it stops running.
Writing overlays in DOS allows other portions of an application to be put into the freed up
spaces.
Why 640K?
Microprocessors work with memory chips via address lines, which are physical connections
between the processor and the memory locations (each of which stores a single byte of memory).
Each address line carries a single bit of a memory address, so the total amount of memory – the
address space – any microprocessor can work with is limited to the number of address lines.
A single address line can only address two bytes (0 and 1), whereas a two-line situation there
are four addresses (00,01,10,11). Intel’s 8088 processor has 20 address lines, and this gives an
address space of 1,048,576 bytes.) or I Mb. 286 has 24 address lines and can access up to 16MB,
and the 386 an address space of 4 GB, because it has 32 lines.
However, if the 8088 can address 1Mbwhy was DOS restricted to 640Kb? Well – IBM PC engineers,
in their not so infinite wisdom, decided to reserve the last 384K for hardware uses
(video buffers, ROM BIOS and so on) . Called upper memory area