Top Banner
Virtual Memory ,Direct memory Virtual Memory ,Direct memory addressing and indirect memory addressing and indirect memory addressing addressing MADE BY: MADE BY: KASHISH-13ITU013 KASHISH-13ITU013 PRAPTI SETHI-13ITU028 PRAPTI SETHI-13ITU028 RITIKA MEHANDIRATTA-13ITU029 RITIKA MEHANDIRATTA-13ITU029 SHIVAM NAGPAL-13ITU038 SHIVAM NAGPAL-13ITU038 SHUBHAM CHOUDHARY-13ITU039 SHUBHAM CHOUDHARY-13ITU039 SMARTH BAJAJ-13ITU040 SMARTH BAJAJ-13ITU040 SONALI GUPTA -13ITU043 SONALI GUPTA -13ITU043 SURBHI GROVER-13ITU044 SURBHI GROVER-13ITU044
40

Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Jul 20, 2015

Download

Engineering

ITM University
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Virtual Memory ,Direct memory Virtual Memory ,Direct memory addressing and indirect memory addressing and indirect memory

addressingaddressing

MADE BY:MADE BY:KASHISH-13ITU013KASHISH-13ITU013

PRAPTI SETHI-13ITU028PRAPTI SETHI-13ITU028RITIKA MEHANDIRATTA-13ITU029RITIKA MEHANDIRATTA-13ITU029

SHIVAM NAGPAL-13ITU038SHIVAM NAGPAL-13ITU038SHUBHAM CHOUDHARY-13ITU039SHUBHAM CHOUDHARY-13ITU039

SMARTH BAJAJ-13ITU040SMARTH BAJAJ-13ITU040SONALI GUPTA -13ITU043SONALI GUPTA -13ITU043

SURBHI GROVER-13ITU044SURBHI GROVER-13ITU044

Page 2: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

FANTASTIC 8FANTASTIC 8

Page 3: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Topics coveredTopics covered Virtual memory Virtual memory Direct memory access (DMA)Direct memory access (DMA) Indirect memory accessIndirect memory access Addressing ModesAddressing Modes1.1. ImmediateImmediate2.2. DirectDirect3.3. IndirectIndirect4.4. RegisterRegister5.5. Register IndirectRegister Indirect6.6. Displacement (Indexed) Displacement (Indexed)

Page 4: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

INTRODUCTIONINTRODUCTION In computing, In computing, virtual memory virtual memory

is a memory management is a memory management technique that is implemented technique that is implemented using both hardware and using both hardware and software. It maps memory software. It maps memory addresses used by a addresses used by a program, called program, called virtual virtual addressesaddresses, into, intophysical physical addressesaddresses in computer  in computer memory. memory. 

Direct memory access (DMADirect memory access (DMA) is ) is a feature of computerized a feature of computerized systems that allows certain systems that allows certain hardware subsystems to hardware subsystems to access main system access main system memory independently of memory independently of the central processing the central processing unit (CPU).unit (CPU).

Page 5: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

INDIRECT ADDRESSINGINDIRECT ADDRESSING An address in a computer instruction that indicates a location where An address in a computer instruction that indicates a location where 

the address of the referenced operand is to be found. Alsoknown as the address of the referenced operand is to be found. Alsoknown as multilevel address.multilevel address.

Page 6: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

MemoryMemory

register

CPU cache

Main Memory

Secondary Storage

Server (or INTERNET)

• larger capacity• lower speed• lower cost

Page 7: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

What isWhat is…… Virtual memory as an alternate set of Virtual memory as an alternate set of

memory addresses. memory addresses. Programs use these virtual addresses Programs use these virtual addresses

rather than real addresses to store rather than real addresses to store instructions and data.instructions and data.

When the program is actually executed, When the program is actually executed, the virtual addresses are converted into the virtual addresses are converted into real memory addresses. real memory addresses.

Page 8: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Why is i t neededWhy is i t needed…….. Before the development of the virtual memory Before the development of the virtual memory

technique, programmers had to manage directly technique, programmers had to manage directly two-level storage such as main memory or ram two-level storage such as main memory or ram and secondary memory in the form of hard disks and secondary memory in the form of hard disks or earlier, magnetic drums.or earlier, magnetic drums.

Enlarge the address space, the set of addresses Enlarge the address space, the set of addresses a program can utilize.a program can utilize.

Virtual memory might contain twice as many Virtual memory might contain twice as many addresses as main memory.addresses as main memory.

Page 9: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

ObjectObject…… When a computer is executing many programs When a computer is executing many programs

at the same time, Virtual memory make the at the same time, Virtual memory make the computer to share memory efficiently. computer to share memory efficiently.

Eliminate a restriction that a computer works in Eliminate a restriction that a computer works in memory which is small and be limited. memory which is small and be limited.

When many programs is running at the same When many programs is running at the same time, by distributing each suitable memory area time, by distributing each suitable memory area to each program, VM protect programs to to each program, VM protect programs to interfere each other in each memory area.interfere each other in each memory area.

Page 10: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

How does it workHow does it work…… To facilitate copying virtual memory into real To facilitate copying virtual memory into real

memory, the operating system divides virtual memory, the operating system divides virtual memory into pages, each of which contains a memory into pages, each of which contains a fixed number of addresses.fixed number of addresses.

Each page is stored on a disk until it is needed.Each page is stored on a disk until it is needed. When the page is needed, the operating system When the page is needed, the operating system

copies it from disk to main memory, translating copies it from disk to main memory, translating the virtual addresses into real addresses.the virtual addresses into real addresses.

Page 11: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Virtual MemoryVirtual Memory Use main memory as a “cache” for secondary memoryUse main memory as a “cache” for secondary memory

Allows efficient and safe sharing of memory among multiple Allows efficient and safe sharing of memory among multiple programs.programs.

Provides the ability to easily run programs larger than the size of Provides the ability to easily run programs larger than the size of physical memoryphysical memory

Simplifies loading a program for execution by providing for code Simplifies loading a program for execution by providing for code relocation (i.e., the code can be loaded anywhere in main memory)relocation (i.e., the code can be loaded anywhere in main memory)

What makes it work? – again the Principle of LocalityWhat makes it work? – again the Principle of Locality A program is likely to access a relatively small portion of its address A program is likely to access a relatively small portion of its address

space during any period of timespace during any period of time Each program is compiled into its own address space – a “virtual” Each program is compiled into its own address space – a “virtual”

address spaceaddress space During run-time eachDuring run-time each virtual virtual address must be translated to a address must be translated to a physicalphysical address (an address in main memory)address (an address in main memory)

Page 12: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

MMU (Memory Management MMU (Memory Management Unit)Unit) The hardware base that makes a virtual memory system The hardware base that makes a virtual memory system

possible.possible. Allows software to reference physical memory by virtual Allows software to reference physical memory by virtual

addresses, quite often more than one.addresses, quite often more than one. It accomplishes this through the use of page and page It accomplishes this through the use of page and page

tables.tables. Use a section of memory to translate virtual addresses Use a section of memory to translate virtual addresses

into physical addresses via a series of table lookups.into physical addresses via a series of table lookups. The software that handles the page fault is generally part The software that handles the page fault is generally part

of an operating system and the hardware that detects of an operating system and the hardware that detects this situation.this situation.

Page 13: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Segmentation... & paging...Segmentation... & paging... Segmentation involves the relocation of variable sized Segmentation involves the relocation of variable sized

segments into the physical address space. segments into the physical address space. Generally these segments are contiguous units, and are Generally these segments are contiguous units, and are

referred to in programs by their segment number and an referred to in programs by their segment number and an offset to the requested data.offset to the requested data.

A technique used by virtual memory operating systems A technique used by virtual memory operating systems to help ensure that the data you need is available as to help ensure that the data you need is available as quickly as possible.quickly as possible.

Instead of utilizing a segment/offset addressing Instead of utilizing a segment/offset addressing approach, as seen in segmentation, paging uses a linear approach, as seen in segmentation, paging uses a linear sequence of virtual addresses which are mapped to sequence of virtual addresses which are mapped to physical memory as necessary. physical memory as necessary.

Due to this addressing approach, a single program may Due to this addressing approach, a single program may refer to series of many non-contiguous segments. refer to series of many non-contiguous segments.

Page 14: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Virtual Memory (Paging)Virtual Memory (Paging)

Page table

Address Space

Page table

Address Space

Physical

Memory

Page 15: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Two Programs Sharing Physical Two Programs Sharing Physical MemoryMemory

Program 1virtual address space

main memory

A program’s address space is divided into pages (all one fixed size) or segments (variable sizes)

The starting location of each page (either in main memory or in secondary memory) is contained in the program’s page table.

Program 2virtual address space

Page 16: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Address TranslationAddress Translation

Virtual Address (VA)

Page offsetVirtual page number31 30 . . . 12 11 . . . 0

Page offsetPhysical page number

Physical Address (PA)29 . . . 12 11 0

Translation

So each memory request So each memory request firstfirst requires an address requires an address translationtranslation from the from the virtual space to the physical spacevirtual space to the physical space A virtual memory miss (i.e., when the page is not in physical A virtual memory miss (i.e., when the page is not in physical

memory) is called a memory) is called a page faultpage fault

A virtual address is translated to a physical address by a combination of hardware and software

Page 17: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

VIRTUAL ADDRESSING WITH VIRTUAL ADDRESSING WITH CACHECACHE

Thus it takes an Thus it takes an extraextra memory access memory access to translate a VA to a PA.to translate a VA to a PA.

CPUTrans-lat ionCacheMain

Memory

VAPAmiss

hit

data

This makes memory (cache) accesses very expensive (if every access was really two accesses)

The hardware fix is to use a Translation Lookaside Buffer (TLB) – a small cache that keeps track of recently used address mappings to avoid having to do a page table lookup

Page 18: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Translation Lookaside Buffers Translation Lookaside Buffers (TLBs)(TLBs)

Just like any other cache, the TLB can be Just like any other cache, the TLB can be organized as fully associative, set associative, organized as fully associative, set associative, or direct mappedor direct mapped V Virtual Page # Physical Page # Dirty Ref Access

TLB access time is typically smaller than cache access time (because TLBs are much smaller than caches)

� TLBs are typically not more than 128 to 256 entries even on high end machines

Page 19: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

A TLB in the Memory HierarchyA TLB in the Memory Hierarchy

A TLB miss – is it a page fault or merely a TLB miss? A TLB miss – is it a page fault or merely a TLB miss? If the page is loaded into main memory, then the TLB miss can If the page is loaded into main memory, then the TLB miss can

be handled (in hardware or software) by loading the translation be handled (in hardware or software) by loading the translation information from the page table into the TLBinformation from the page table into the TLB

Takes 10’s of cycles to find and load the translation info into Takes 10’s of cycles to find and load the translation info into the TLBthe TLB

If the page is not in main memory, then it’s a true page faultIf the page is not in main memory, then it’s a true page fault Takes 1,000,000’s of cycles to service a page faultTakes 1,000,000’s of cycles to service a page fault

TLB misses are much more frequent than true page faultsTLB misses are much more frequent than true page faults

CPU TLBLookup Cache Main

Memory

VA PA miss

hit

data

Trans-lat ion

hit

miss

¾ t¼ t

Page 20: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Summarizing(virtual memory)Summarizing(virtual memory)…… Virtual memoryVirtual memory is a common part of most operating is a common part of most operating

systems on computers. systems on computers. It has become so common because it provides a big It has become so common because it provides a big

benefit for users at a very low cost. benefit for users at a very low cost. benefits of executing a program that is only partially in benefits of executing a program that is only partially in

memory. memory. program is program is no longer constrainedno longer constrained by the amount of by the amount of

physical memory.physical memory. ⇒ ⇒ user would be able to write programs for an user would be able to write programs for an extremely large virtual address space. extremely large virtual address space.

more programsmore programs could be run at the same time could be run at the same time ⇒ ⇒ increase CPU utilization and throughput. increase CPU utilization and throughput.

less I/Oless I/O would be needed would be needed to load or swapto load or swap each user each user program program

⇒ ⇒ run faster run faster

Page 21: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation
Page 22: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Addressing ModesAddressing Modes ImmediateImmediate DirectDirect IndirectIndirect RegisterRegister Register IndirectRegister Indirect Displacement (Indexed) Displacement (Indexed)

Page 23: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Immediate AddressingImmediate Addressing Operand is part of instructionOperand is part of instruction Operand = address fieldOperand = address field e.g. ADD 5e.g. ADD 5

Add 5 to contents of accumulatorAdd 5 to contents of accumulator 5 is operand5 is operand

No memory reference to fetch dataNo memory reference to fetch data FastFast Limited rangeLimited range

Page 24: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Immediate Addressing Immediate Addressing DiagramDiagram

OperandOpcode

Instruction

Page 25: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

DIRECT ADDRESSINGDIRECT ADDRESSING Address field contains address of operandAddress field contains address of operand Effective address (EA) = address field (A)Effective address (EA) = address field (A) e.g. ADD Ae.g. ADD A

Add contents of cell A to accumulatorAdd contents of cell A to accumulator Look in memory at address A for operandLook in memory at address A for operand

Single memory reference to access dataSingle memory reference to access data No additional calculations to work out effective No additional calculations to work out effective

addressaddress Limited address spaceLimited address space

Page 26: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Direct Addressing DiagramDirect Addressing Diagram

Address AOpcode

Instruction

Memory

Operand

Page 27: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

INDIRECT ADDRESSINGINDIRECT ADDRESSING

In this mode the address field of the instruction gives the address where the effective address is stored in memory.Memory cell pointed to by address field contains the address of (pointer to) the operandEA = (A)

Look in A, find address (A) and look there for operand

e.g. ADD (A)Add contents of cell pointed to by contents of A to accumulator

Page 28: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

INDIRECT ADDRESSING INDIRECT ADDRESSING CONT...CONT...

Large address space 2n where n = word lengthMay be nested, multilevel, cascaded

e.g. EA = (((A)))Indirect addressing is often combined with pre or post increment or decrement addressing allowing the address of the operand tobe increases by one either before or after using it.

Multiple memory accesses to find operandHence slower

Page 29: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Indirect Addressing Indirect Addressing DiagramDiagram

Address AOpcode

Instruction

Memory

Operand

Pointer to operand

Page 30: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

DIRECT AND INDIRECT DIRECT AND INDIRECT EXAMPLEEXAMPLE

Page 31: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Register Addressing (1)Register Addressing (1) Operand is held in register named in Operand is held in register named in

address filedaddress filed EA = REA = R Limited number of registersLimited number of registers Very small address field needed Very small address field needed

Shorter instructionsShorter instructions Faster instruction fetchFaster instruction fetch

Page 32: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Register Addressing (2)Register Addressing (2) No memory accessNo memory access Very fast executionVery fast execution Very limited address spaceVery limited address space Multiple registers helps performanceMultiple registers helps performance

Requires good assembly programming or Requires good assembly programming or compiler writingcompiler writing

N.B. C programming N.B. C programming register int a;register int a;

c.f. Direct addressingc.f. Direct addressing

Page 33: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Register Addressing Register Addressing DiagramDiagram

Register Address ROpcode

Instruction

Registers

Operand

Page 34: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Register Indirect Register Indirect AddressingAddressing

C.f. indirect addressingC.f. indirect addressing EA = (R)EA = (R) Operand is in memory cell pointed to by Operand is in memory cell pointed to by

contents of register Rcontents of register R Large address space (2Large address space (2 nn)) One fewer memory access than indirect One fewer memory access than indirect

addressingaddressing

Page 35: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Register Indirect Addressing Register Indirect Addressing DiagramDiagram

Register Address ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Page 36: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Displacement AddressingDisplacement Addressing EA = A + (R)EA = A + (R) Address field hold two valuesAddress field hold two values

A = base valueA = base value R = register that holds displacementR = register that holds displacement or vice versaor vice versa

Page 37: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Displacement Addressing Displacement Addressing DiagramDiagram

Register ROpcode

Instruction

Memory

OperandPointer to Operand

Registers

Address A

+

Page 38: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Relative AddressingRelative Addressing A version of displacement addressingA version of displacement addressing R = Program counter, PCR = Program counter, PC EA = A + (PC)EA = A + (PC) PC holds the address of next instruction to PC holds the address of next instruction to

be read.be read. Used with branch type instructions.Used with branch type instructions. Results in shorter address field.Results in shorter address field.

Page 39: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Base-Register AddressingBase-Register Addressing The content of the base address is added The content of the base address is added

to the address part of the instructionto the address part of the instruction It is assumed to hold a base address and It is assumed to hold a base address and

address field which gives displacement address field which gives displacement relative relative

The are used in computers for reallocation The are used in computers for reallocation of programsof programs

R may be explicit or implicitR may be explicit or implicit

Page 40: Virtual Memory ,Direct memory addressing and indirect memory addressing presentation

Indexed AddressingIndexed Addressing EA = A + REA = A + R It is a special type of cpu register.It is a special type of cpu register. The distance b/w beginning address and The distance b/w beginning address and

operands address is index valueoperands address is index value In this mode the content of an index In this mode the content of an index

register is added to the address part of register is added to the address part of the register to obtain EA the register to obtain EA

Good for accessing arraysGood for accessing arrays