computer organization cs 147 prof. lee azita keshmiri

29
Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Post on 21-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Computer Organization

Cs 147 Prof. Lee

Azita Keshmiri

Page 2: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Virtual memory What is virtual memory?- A memory management unit that

swaps data in and out of physical memory.

- virtual memory makes it appear to the CPU that there is more physical memory than is actually presents.

Page 3: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Virtual Memory How does virtual memory works?- Virtual memory uses auxiliary

storage, such as a disk, to expand the memory space available to the processor.

To understand how virtual memory works, compare it to cache memory.

Page 4: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Cache memory

A cache memory works by moving data to and from physical memory.

When the CPU request data that is stored in cache, it receives this data faster than if it had to retrieve the data from physical memory.

Page 5: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Virtual memory and physically indexed caches

Cache page frames

.notion of bin -region of cache that may contain cache blocks from

a page.

- random vs careful mapping

-selection of physical page frame

dictates cache index.

- overall goal is to minimize

cache misses

Page 6: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Virtual memory A virtual memory system may use

paging or segmentation. A paging system moves frames of

fixed size between physical memory and virtual memory.

Page 7: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Virtual Memory Organization

The virtual address space is divided into pieces of the same size Main memory is divided into pieces of the same size as pages called page

frames. real memory virtual address space

Page Page 6page0Page 2

Page 0Page 1Page 2Page 3Page

Page 5Page 6

Page 8: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Virtual Memory

Memory that a single process “sees” - for example: 4 GB/process

Real/physical memory

Process 1

Process 2

Page 9: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

memory management unit (MMU) A memory management unit

moves data between physical memory and some slower storage device, usually a disk.

This storage area may be referred to as a swap disk or swap file, depending on its implementation.

Page 10: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Paging In paging, the entire range of

logical addresses those addresses that can be output by the CPU, is divided into blocks called pages.

Each page is the same size. each logical address takes exactly

one page.

Page 11: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Paging -1 Paging moves pages from the

swap disk to frames of the physical memory so data can be accessed by the processor.

Any page can occupy any frame. A page is small enough to fit in

main memory.

Page 12: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Practical paging:Segmentation Based on the observation the most processes use only a

small portion of the 4 GB addr space. Segmentation: partition the address space into large

manageable chunks.

Segment # page # offset Phy Addr.Index 4

Segment table page table

Page 13: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

One possible memory configuration for the Relatively Simple CPU

Address Space Physical memoryPage F

. . .

Page 2

Page 1

Page 0

Frame 3

Frame 2

Frame 1

Frame 0

Page 14: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

frames Physical memory is divided into

non overlapping frames. the size of each frame is the same

as the size of one page.

Page 15: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Page fault If the data is not located in

physical memory,it generate a page fault and moves the page from the swap disk to

a frame. - removes another page if

necessary.

Page 16: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

MMU configuration within the memory hierarchy

CPU MMU Physical Memory

SwapDisk

logicaladdress

Physical

address

control signals

Page 17: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Memory Hierarchy

Memory is used to store programs and data.

The lowest level of the memory hierarchy is a small, fast and costly memory called cache, usually implemented by static RAM chips.

- primary Cache is located on the CPU chip.

- Secondary cache is placed between the primary cache and main memory.

Page 18: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Memory Hierarchy(cont) Main Memory can be built by tens

of megabytes at a reasonable cost. The affordable size is still small

compared to the demands of very large programs.

Page 19: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Memory hierarchy

The memory hierarchy of most computer systems includes not only physical memory, but also cache and virtual memory.

Cache memory is a high-speed memory situated between the CPU and physical memory.

- one level of cache is often located within the CPU chip.

Page 20: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Segmentation

Segmentation is another method of allocating memory that can be used instead of or in conjunction with paging.

A program is divided into several segments, each of which is a self-contained unit, such as a subroutine or data structure.

Page 21: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Segmentation-1 A segmented memory management

unit (MMU) includes a segment table to keep track of the segments resident in memory.

Since a segment can start at one of many addresses and can be of any size.

each segment table entry must include the start address and segment size.

Page 22: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Memory management unit A memory management unit maps

the logical addresses issued by the processor to their corresponding physical addresses.

Page 23: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Memory management unit The memory management unit

uses page tables and translation look aside buffers to keep track of which frame corresponds.

Page 24: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Page tables

Virtual page Hash table1 entry perPage frame

Full table:1 entry Per page

Page frame #index

hash

Page 25: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Conversion of logical address to physical address using segmentation

segment offset

Segment table

compare

+

Out of bounds

Error (if offset >= size)

Physical memory address

Fault(if not inmemory)

Logical Address:

size

Address ofStart of segment

Page 26: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Internal fragmentation

In the paged memory implementation, each page is of size 4k.

A program of size 4k+1 would require the memory management unit (MMU) to allocate two pages of memory, even though the second page would use only one of its 4k locations.

This is referred to as internal fragmentation.

Page 27: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Protection bits

A preferable option is to protect the segment or page, rather than individual locations.

This produces the desired memory protection at an acceptable cost in terms of overhead.

To accomplish this, protection bits are added to each entry in the segment or page table.

Page 28: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

Page directory The Pentium microprocessor can

use either segmentation or paging. the windows NT virtual memory

manager uses paging. The 10 high-order bits of the 32-bit

virtual address select an entry in the page directory, which is stored in physical memory.

Page 29: Computer Organization Cs 147 Prof. Lee Azita Keshmiri

THE END