Skip to content
UoL CS Notes

Memory Fragmentation

COMP124 Lectures

Simple Memory Management

  • Memory is allocated to program in contiguous partitions from one end of the store to the other.
  • Each process has a base, or datum (where it starts).
  • Each process also has a limit (length).

Filling Empty Memory

With this method you are unable to move existing programs in memory. This results in fragmentation and ineffective memory usage.

Choosing Programs

In a multiprogramming system where we have a queue of programs waiting, select a program of the right size to fit.

This has the following problems:

  • Large programs may never get loaded (permanent blocking or starvation).
  • Small gaps are created (fragmentation).

Avoiding Starvation

To avoid starvation, we may need to let a large program hold up the queue until enough space becomes available.

In general we have to make a choice of which selection policy to use:

  • First fit:
    • Choose first partition of suitable size.
  • Best fit:
    • Choose smallest partition which is big enough.
  • Worst fit:
    • Choose the biggest partition.

Fragmentation

When fragmentation is severe the following is true:

  • 50% rule:
    • For first-fit, if the amount of memory allocated is $n$, then the amount of unusable owing to fragmentation is $\frac 1 2 n$.
  • May have to compact memory:
    • Requires programs to be dynamically relocatable.

This is difficult when dealing with large programs.

Other Issues

  • Shortage of Memory:
    • Arising from fragmentation or anti-starvation policy.
    • May not be able to support enough users.
    • May have difficulty loading enough programs to obtain a good job mix.
  • Imposes limitations on program structure:
    • Not suitabel for shareing routines and data.
    • Does not reflect high level language structures.
    • Does not handle memory expansion well.
  • Swapping is inefficient.

Swapping

To start more programs than can fit into physical memory a swap must be used:

  • During scheduling, a process image may be swapped in, and another swapped out to make room:
    • Aldo helps to prevent starvation.
  • For efficiency, you may have dedicated swap space on a disk.
    • This is as opposed to a swap file.

Swapping whole processes adds considerably to the time of a context switch.