CS GRIND

Main Memory

Chapter Objectives

  • To provide a detailed description of various ways of organising memory hardware
  • To discuss various memory-management techniques, including paging and segmentation
  • To provide a detailed description of the Intel Pentium, which supports both pure segmentation and segmentation with paging

Background

Memory consists of a large array of words or bytes, each with its own address. The CPU fetches instructions from memory according to the value of the program counter. These instructions may cause additional loading from and storing to specific memory addresses.

Basic Hardware

Main memory and the registers are the only storage that the CPU can access directly. This reality leads to 2 implications:

Difference between register and memory:

Since accessing memory is slow, the processor needs to stall when accessing memory. This is intolerable and can be solved a memory buffer called cache.

Besides the accessing speed, the hardware also provides protection from mis-operations on memory. Here is one of the possible mechanism:

Loading base and limit registers can only be performed by OS in kernel mode via privileged instructions.

OS, executing in kernel mode, can unrestrictedly access both OS memory and users' memory to dump out those programs in case of errors, to access and modify parameters of system calls, and so on.

Address Binding

Processes on the disk that are waiting to be brought into memory for execution form the input queue.

The binding of instructions and data to memory addresses:

Logical versus Physical Address Space

The compile-time and load-time address-binding methods generate identical logical and physical addresses.

The execution-time address-binding scheme results in differing logical and physical addresses. In this case, we usually refer to the logical address as a virtual address.

In the execution-time address-binding scheme, the logical and physical address spaces differ. The mapping from virtual to physical addresses in the execution-time is done by a hardware device called memory-management unit(MMU).

The user program never sees the real physical addresses. The user program deals with logical addresses. MMU maps these logical addresses to real physical addresses.

Dynamic Loading

Procedures:

Advantages:

Dynamic loading is up to users' implementation of their programs and does not require special OS support. OS may help the programmer by providing library routines to implement dynamic loading.

Dynamic Linking and Shared Libraries

Usage:

This system is also known as shared libraries.

Dynamic linking usually requires help from the OS.

Swapping

A process must be in memory to be executed. A process, however, can be swapped temporarily out of memory to a backing store and then brought back into memory for continued execution.

Swapping in RR scheduling:

roll out, roll in:

Normally, a process that is swapped out will be swapped back into the same memory space it occupied previously. This restriction is dictated by the method of address binding.

The process of swapping:

Contiguous Memory Allocation

In contiguous memory allocation, each process is contained in a singlecontiguous section of memory.

Memory Mapping and Protection

CPU checks every generated memory address to protect both OS and the other users' programs and data from being modified.

Memory Allocation

Multiple-partition method: partition the memory into some fixed parts and each for a process.

Variable-partition: the operating system keeps a table indicating which parts of memory are available and which are occupied. Initially, all memory is available for user processes and is considered one large block of available memory, a hole.

Fragmentation

Paging

Basic Method

logical address is mapped into physical memory via page table.

Hardware Support

Protection

Shared pages

If the code is reentrant code(or pure code), it can be shared. Reentrant code is non-self-modifying code: it never changes during execution. Thus, two or more processes can execute the same code at the same time.

Structure of the Page Table

Hierarchical Paging

Useful in the situation that the page table is large -- instead of keeping a large chunk of continuous memory to story the large page table, divide the page table into smaller pieces.

Hashed Page Tables

Inverted Page Tables

Reentrant code is non-self-modifying code: it never changes during execution. Thus, two or more processes can execute the same code at the same time.

Segmentation

Segmentation: a memory-management scheme that supports the user's view of memory. A logical address space is a collection of segments. Each segment has a name and a length. The addresses specify both the segment name and the offset within the segment. The user therefore specifies each address by two quantities: a segment name and an offset.

Summary