Model Operating Systems - Memory Management
您目前处于:技术核心竞争力  2017-11-05

Main memory is an important resource that must be very carefully managed. Over the years, people discovered the concept of a memory hierarchy, in which computers have a few megabytes of very fast, expensive, volatile cache memory, a few gigabytes of medium-speed, medium-priced, volatile main memory, and a few terabytes of slow, cheap, nonvolatile magnetic or solid-state disk storage, not to mention removable storage, such as DVDs and USB sticks. It is the job of the operating system to abstract this hierarchy into a useful model and then manage the abstraction.


No Memory Abstraction

The simplest memory abstraction is to have no abstraction at all. Early mainframe computers (before 1960), early minicomputers (before 1970), and early personal computers (before 1980) had no memory abstractiion. Every program simply saw the physical memory.


A Memory Abstraction: Address Spaces

All in all, exposing physical memory to processes has several major drawbacks. First, if user programs can address every byte of memory, they can easily trash the operating system, intentionally or by accident, bringing the system to a grinding halt.

# The Notion of an Address Space

Just as the process concept create a kind of abstract CPU to run programs, and address space creates a kind of abstract memory for programs to live in. Each process has its own address space, independent of those belonging to oher processes.

# Swapping

Keeping all processes in memory all the time requires a huge amount of memory and cannot be done if there is insufficient memory.

Two general approaches to dealing with memory overload have been developed over the years. The simplest strategy, called swapping, consists of bringing in each process in its entirety, running it for a while, then putting it back on the disk. Idle processes are mostly stored on disk, so they do not take up any memory when they arenot running. The other strategy, called virtual memory, allows programs to run even when they are only partially in main memory.

When swapping creates multiple holes in memory, it is possible to combine them all into one big one by moving all the processes downward as far as possible. This technique is known as memory compaction. It is usually not done because it reuqires a lot of CPU time.

A point that is worth making concerns how much memory should be allocated for a process when it is created of swapped in.

# Managing Free Memory

When memory is assigned dynamically, the operating system must manage it. In general terms, there are two ways to keep track of memory usage: bitmaps and free lists.


转载请并标注: “本文转载自 linkedkeeper.com (文/张松然)”  ©著作权归作者所有