Modern computer systems typically have many programs active at the same time. A single processor can, of course, only execute instructions from one program at any instant, but by switching rapidly between the active programs they all appear to be executing at once, at least when viewed on a human timescale.
The rapid switching is managed by the operating system, so the application pro- grammer can write his or her program as though it owns the whole machine. The mechanism used to support this illusion is described by the term memory manage- ment unit (MMU). There are two principal approaches to memory management, called segmentation and paging.
The simplest form of memory management allows an application to view its memory as a set of segments, where each segment contains a particular sort of information. For instance, a program may have a code segment containing all its instructions, a data segment and a stack segment. Every memory access provides a segment selector and a logical address to the MMU. Each segment has a base address and a limit associated with it. The logical address is an offset from the seg- ment base address, and must be no greater than the limit or an access violation will occur, usually causing an exception. Segments may also have other access controls, for instance the code segment may be read-only and an attempt to write to it will also cause an exception.
Segmentation allows a program to have its own private view of memory and to coexist transparently with other programs in the same memory space. It runs into diffi- culty, however, when the coexisting programs vary and the available memory is lim- ited. Since the segments are of variable size, the free memory becomes fragmented over time and a new program may be unable to start, not because there is insufficient free memory, but because the free memory is all in small pieces none of which is big enough to hold a segment of the size required by the new program.
The crisis can be alleviated by the operating system moving segments around in memory to coalesce the free memory into one large piece, but this is inefficient, and most processors now incorporate a memory mapping scheme based on fixed-size chunks of memory called pages. Some architectures include segmentation and pag- ing, but many, including the ARM, just support paging without segmentation.