Memory management overlays and virtual memory, Thesis of Operating Systems

to study the overlays

Typology: Thesis

2014/2015

Uploaded on 09/01/2015

maliknadeem
maliknadeem 🇵🇰

1 document

1 / 31

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction to Embedded Systems
Memory Management:
Memory Management:
Overlays and Virtual Memory
Overlays and Virtual Memory
Lecture 14
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Partial preview of the text

Download Memory management overlays and virtual memory and more Thesis Operating Systems in PDF only on Docsity!

Introduction to Embedded Systems

Memory Management:^ Memory Management:Overlays and Virtual Memory^ Overlays and Virtual Memory

Lecture 14

Introduction to Embedded Systems

How Does a Program Start Running?^ How Does a Program Start Running?

0x3fff 0x

RAM

  • CPU’s Program Counter is then

set to the starting address of theprogram and the program beginsexecution.

OS (loader) copies a program frompermanent storage into RAM - on PCsand workstations, the “operating system”copies the program (bits) from disk.

Introduction to Embedded Systems

Solution: Only Load Part of the Program^ Solution: Only Load Part of the Program

One option: programmer breaks code into pieces that fit intoRAM

Pieces, called

overlays

, are loaded and unloaded by the program

Does not require OS help

RAM

0xff 0x

0x01ff 0x01000x00ff 0x

load one overlay and rununtil other overlayis needed

Program

Introduction to Embedded Systems

ARM Linker Supports Overlays^ ARM Linker Supports Overlays •

Overlay manager

loads an overlay segment when it is not

in RAM

Supports Static and Dynamic Overlays

Static overlays

One root segment

2 or more memory partitions (1 for the root partition which is alwaysin RAM)

Within each partition, any number of overlay segments

Only 1 overlay segment can be in a partition at a given time

Application writer specifies what is in each partition and segment^ root segment

2_

2_

2_

2_

1_

1_

1_

1_

high address low address

  • segments 1_1 .. 1_4 share the same

memory area

  • so do segments 2_1 .. 2_

Introduction to Embedded Systems

Dynamic Overlay^ Dynamic Overlay •

Include

re-location information

with each overlay segment

Have overlay manager allocate memory for an overlaysegment when it is first loaded

Load and unload overlay segments by explicit calls tooverlay manager

Each overlay segment is given its own name - linker linkseach as if it were in its own partition

Introduction to Embedded Systems

Problems with Overlays^ Problems with Overlays •

Difficult for programmer to manage

Not general - management of resources (RAM) is anoperating system issue

But many embedded systems do not have the space or power for a“real” OS

Introduction to Embedded Systems

The Memory Pyramid^ The Memory Pyramid

Introduction to Embedded Systems

How Does VM Work?^ How Does VM Work? •

Two memory “spaces”

Virtual memory space

  • what the program “sees”

Physical memory space

  • what the program runs in (size of RAM)

On program startup

OS copies program into RAM

If there is not enough RAM, OS stops copying program and starts itrunning with only a portion of the program loaded in RAM

When the program touches a part of the program not in physicalmemory (RAM), OS catches the memory abort (called a

page fault

)

and copies that part of the program from disk into RAM

In order to copy some of the program from disk to RAM, OS mustevict parts of the program already in RAM

  • OS copies the evicted parts of the program back to disk

Introduction to Embedded Systems

Example (^ Example (

con'tdcon'td

Need VANeed VA

toto

PA mappingsPA mappings

bne

0x

add

r10,r1,r

sub

r3,r4,r

sw

r5,0x0c

0x000x040x080x0C0x100x140x180x1C

0x000x040x080x0C

add

r1,r2,r

sub

r2,r3,r

lw

r2,

0x

mult

r3,r4,r

add

r1,r2,r

sub

r2,r3,r

lw

r2,

0x

mult

r3,r4,r

Virtual Address Space

Physical Address Space

0x

0x

0x

0x

0x

0x

0x

Disk

0x

Disk

0x

Disk

Disk

VA->PA

Introduction to Embedded Systems

Example (^ Example (

con'tdcon'td

AfterAfter

handling ahandling a

page faultpage fault

bne

0x

add

r10,r1,r

sub

r3,r4,r

sw

r5,0x0c

0x000x040x080x0C0x100x140x180x1C

0x000x040x080x0C

add

r1,r2,r

sub

r2,r3,r

lw

r2,

0x

mult

r3,r4,r

bne

0x

sub

r2,r3,r

lw

r2,

0x

mult

r3,r4,r

Virtual Address Space

Physical Address Space

0x

Disk

0x

0x

0x

0x

0x

0x

0x

Disk

0x

Disk

Disk

VA->PA

Introduction to Embedded Systems

Basic VM Algorithm^ Basic VM Algorithm •

Program asks for virtual address

Computer translates

virtual address

(VA) to

physical

address

(PA)

Computer reads PA from RAM, returning it to program

0x000x040x080x0C

add

r1,r2,r

sub

r2,r3,r

lw

r2,

0x

mult

r3,r4,r

RAM

0x

0x

0x

0x

0x

0x

0x

Disk

0x

Disk

0x

Disk

Disk

VA->PA

Processor

(running program)

Instructions

(or data)

Virtual address

Introduction to Embedded Systems

Page Tables^ Page Tables

Table which holds VA -> PA translations is called the

page table

In our current scheme, each word is translated from a virtualaddress to a physical address

How big is the page table?

0x000x040x080x0C

add

r1,r2,r

sub

r2,r3,r

lw

r2,

0x

mult

r3,r4,r

RAM

0x

0x

0x

0x

0x

0x

0x

Disk

0x

Disk

0x

Disk

Disk

VA->PA

Processor

(running program)

Instructions

(or data)

Virtual address

Introduction to Embedded Systems

Virtual Pages & Physical Page Frames^ Virtual Pages & Physical Page Frames

0x7fff0x6fff0x5fff0x4fff0x3fff0x2fff0x1fff0x0fff0x

0x3fff0x2fff0x1fff0x0fff0x

Virtual Address Space

Physical Address Space

virtual page 0x000-0xfff

4KB

physical page frame

Introduction to Embedded Systems

Page Frames^ Page Frames •

Every address within a virtual page maps to the samelocation within a physical page frame

In other words, bottom

log 2

(page size in bytes) is

not

translated