|
FALL 2000 Lecture Notes 9: MEMORY MANAGEMENT 1 SINGLE USER CONTIGUOUS SYSTEM :
Algorithm to load job in single user system: If yes, stop loading program If yes, stop loading the program Memory management very easy – just needs to keep track of base address and value of accumulator. First computers (40’s and 50’s) had this type of memory management. Very uneconomical system $200,000 for equipment that could only be used by one person at a time. FIXED PARTITIONS. First attempt to allow for multiprogramming. One fixed (or static) partition for each job. Partition size designated when machine started. To change has to power down. Critical factor to protect the partition’s boundaries. Algorithm more complex: Determine job’s requested memory size. This algorithm still requires that the entire program be stored contiguously in memory from the beginning to the end of execution. Memory manager must keep a table of partitions, their size, the job that is in them and their current status.
would be the status for an empty machine in the following jobs had come in : Job1 30K, Job2 50K, Job3 30K, Job4 25k. Job 3 must wait even though there is 70K space in partition 1. If partitions are set too small, larger jobs will be rejected or have a longer turnaround. If partitions set too big, space will be wasted. The creation of unused spaces within partitions because of too large partition size is called internal fragmentation.
DYNAMIC PARTITIONS With dynamic partitioning, available memory is still kept in contiguous blocks, but jobs are only given as much memory as they need. This is an improvement over fixed partitions, but still has problems. When jobs first loaded in, memory fully utilized. When jobs are finished, a memory space the size of the previous job is freed up. These partitions can be allocated by best fit or first fit. Subsequent allocation creates fragments of free memory between blocks. This is called external fragmentation. FIRST-FIT Job list (J1 10K, J2 20K, J3 30K, J4 10K)
Available 115K Used 40K In this algorithm, a job is put into the first free space that it fits into, but you can see there can be problems. In example above there is 75 K of unused space, but Job 3 that needs 30K cannot be allocated 30K of contiguous space. First fit requires memory manager to keep lists of busy blocks and free blocks. Size of each incoming job compared to block until large enough block is found. counter = 0;do while counter <= # blocks if job_size > memory[counter].size To show how free list would change... Suppose a job requests 200K from the following free list.
BEST-FIT Job list (J1 10K, J2 20K, J3 30K, J4 10K)
Available 115K Used 70K Fragmentation has been reduced and J3 got to run faster, but the allocation process takes more time. Algorithm for best fit. Initialize Min_waste to 99999. Entire set of free memory blocks must be searched because they are stored in physical sequence. This takes time – they could be sorted but that would take time too.
To show how free list would change... Suppose a job requests 200K from the following free list.
Best fit results in a better fit, but results in slivers of unused memory. DEALLOCATION Fixed partition can just use binary 0,1 for free and busy.With dynamic partitions, must take account of these situations:
RELOCATABLE DYNAMIC PARTITIONS In this approach to memory management, programs are relocated to put together all the empty space – a bit like defragging a disk. This is called "garbage collection". The great difficulty with this approach is the overhead associated with the relocation of the instructions. A computer instruction is a series of binary codes that contain addresses and instruction codes. However, if the program is to be moved each address must be flagged so that later the amount of memory locations to which the program has been displaced can be accounted for. Particularly important for loops and branching, since this is done by address. What has to be done by the memory manager to implement this approach?
The overhead is so large in this approach that a crucial question is how often should it be done?
Common elements of all these early approaches to memory management is that they require the entire program
Later memory managers allow programs to not be stored contiguously – but can be divided into segments or pages. Each page or segment could be stored wherever there was an empty space. Furthermore, these pages or segments do not all have to reside in memory during the execution of the job. Worked examples: Given the following information:
Repeat with the following:
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) 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:
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 |