Docsity

Main Memory - Operating System - Lecture Slides, Slides of Computer Science

Toggle sidebar
bg1
Chapter 7: (RAM) Main
Memory: Outline
•RAM: one of the resources an O/S manages
•Memory addressing
–Types of addresses; address binding
–Physical vs. logical; address generation
•Hardware support for memory management
–MMU: Memory Management Unit; Memory protection
•Memory allocation
–How & when do we allocate RAM memory to processes? Includes
consideration of both code (text) and data
–Dynamic loading; dynamic linking; swapping;
contiguous memory allocation
• Paging
• Segmentation
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Partial preview of the text

Download Main Memory - Operating System - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Chapter 7: (RAM) Main

Memory: Outline

  • RAM: one of the resources an O/S manages
  • Memory addressing
    • Types of addresses; address binding
    • Physical vs. logical; address generation
  • Hardware support for memory management
    • MMU: Memory Management Unit; Memory protection
  • Memory allocation
    • How & when do we allocate RAM memory to processes? Includes consideration of both code (text) and data
    • Dynamic loading; dynamic linking; swapping; contiguous memory allocation
  • Paging
  • Segmentation (^1)

Types of RAM Memory Addresses

  • Symbolic addresses
    • Can have these in program language code and in Object Modules
    • Translated to relocatable or absolute addresses through linking
  • Relocatable addresses
    • Can be bound to physical or absolute addresses, after compile time
    • Addresses generated relative to part of program, not to start of physical RAM memory (e.g., 0 is first byte of program)
  • Absolute (physical) addresses
    • Specific addresses in RAM, relative to 0 at start of RAM
    • Eventually, as a program executes, all program addresses must resolve to absolute addresses (^2)

Runtime Address Generation

  • When are RAM addresses generated when a

machine language program runs, i.e., when are

addresses generated by the CPU, by the running

program, in order to access RAM memory?

  • Processes are comprised of a series of bytes of

RAM

  • Some of those bytes are data, some are machine instructions (text)
  • Addresses are generated by: PC (program

counter), indexing, indirection, literal addresses

etc.

Consider the following fragment of

an assembly language program

6

When are addresses generated when this program runs? Docsity.com

  • CPU generates a logical address (a kind of relocatable address)
  • MMU translates logical address to physical address (an absolute address), and puts this in MAR
  • Physical address used to access RAM (i.e., load or store value at the physical address)

Address generation:

Memory Management Hardware

CPU

Memory Management Unit (MMU)

RAM

MAR

MAR=

Memory Address Register

8

MMU: Memory Management Unit

  • Translates logical addresses to physical addresses
    • I.e., performs address binding
  • Also enables memory protection
  • General memory protection problem
    • Check each address generated by program running on CPU to see if it is within address space of process
    • If not, then generate an error (e.g., page fault or terminate the process)
  • MMU implemented in hardware
    • Memory protection and address binding generally requires support from hardware
    • Why not implement MMU in software? 9

Relocation Register

Figure 7.4: Dynamic relocation using a relocation register– defines the start of an address space (^11)

Can this provide memory protection?

Base & Limit Registers

(Modified Fig. 7.6)

12

MMU

Provides memory protection, but no relocation

Main Issues in Memory Management

  • How do we represent address space of a process?
    • logically, address space is a contiguous series of

addresses (i.e., text and data of process)

  • in physical RAM, we can either (a) map entire address

space to physically contiguous addresses or (b) break

into smaller pieces in some manner

  • When and where do we load or unload address

space from disk into/from RAM?

  • if physically contiguous address space, load all or none
  • if program loaded in smaller pieces, we have more

options 14

Contiguous Memory Allocation

  • O/S kernel divides user memory up into

relatively large partitions

  • Keeps a table recording these partitions
  • One process per partition
  • Partition methods:
    • Fixed size partitions
      • When we have a single partition per process, there is a static (fixed) limit on degree of multiprogramming
    • Variable size partitions 15

What do we do when we run out

of memory?

  • E.g., all memory partitions of operating

system available for user processes are full

  • Options

A) System.exit

B) Something else

17

Swapping is one solution

(Fig. 7.5)

18

Paging

  • Non-contiguous memory allocation
    • Breaking up program into fixed size, relatively small units (partitions) of RAM
    • Within paging, still thinking about loading all of process into RAM at once
  • Real RAM memory typically divided into relatively

small physical frames

  • Fixed size blocks, e.g., 1024 bytes
  • Address space of process divided into sequence of

logical pages

  • Frame size same as page size 20

Example

  • We might have a process with a 3 page logical address space
  • And physical RAM consisting of 6 frames

frame (^0)

frame (^1)

frame (^2)

frame (^3)

frame (^4)

frame (^5)

1024 byte page size

1024 byte frame size

21

page (^0)

page (^1)

page (^2)

Logical address space of program

Physical RAM