Basic/Contiguous Memory Allocation
Objectives
We would like to :
- Discuss one technique for placing programs in memory.
Notes
- This is section 9.2
- This is not the actual way things are done, but leads us up to it.
- Memory is large and we want to put multiple programs into it.
- Remember, programs will be of different size
- Different amounts of preallocated memory
- Different text segments.
- One way to do this is allocate all of the memory for a process contiguously
- This is sort of what the previous discussion has implied.
- Contiguous memory allocation is the name of this scheme.
- They provide a picture of addressing on page 357
- Using the base register and the limit register swapping memory becomes quick.
- And memory access protection is built in.
- Memory can be allocated in variable sized blocks.
- This depends on the needs of the process
- The OS needs to keep track of
- The location and size of the memory for each process.
- And somehow keep track of the free space.
- Figure 9.7 page 358 shows how memory can become fragmented.
- How do we handle a new process arriving
- First Fit: Find the first hole a process will fit into
- May not need to search the entire list of holes
- Best Fit: Search the entire list of holes for the most appropriate place to put the process.
- Need to search the entire list.
- But tends to minimize left over space.
- IE a process needs 4k, the best fit is 4.1k so a new .1k hole is created.
- Worst Fit: Search for the worst possible place to put the process
- Dumb name.
- largest space is worst
- Again search of entire memory.
- But tends to produce the largest left over holes.
- They mention that Best and First are better strategies than worst
- Time and increased storage utilization.
- But fragmentation becomes a problem in any case
- External fragmentation:
- Memory external to processes
- It is broken into such small chunks that we might have a large amount of free memory, but no single chunk is large enough to hold a new process.
- Simulations have shown that if N blocks are allocated, 1/2N or 50% more blocks can be unusable.
- Tracking this can become a problem as well
- They give the example:
- A process needs 18,462 bytes of memory
- A hole of size 18,464 bytes is available
- A new hole of 2 bytes is created.
- MANY of these can form, which makes searching much more difficult.
- We could allocate all the memory in the block to the processes
- This is known as internal fragmentation.
- Unused memory is part of the block allocated to a process
- We could compact memory, much like defragmenting a disk.
- Migrate all processes to one end of memory
- Creating a single large hole at the other end.
- But this is expensive time wise.
- Another possible scheme is to use standard sized blocks
- And permit processes to use multiple of these.
- This is paging
- And is the next topic.