JERARQUÍA DE MEMORIA MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ...

20
JERARQUÍA DE MEMORIA MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ [email protected] PROF. GUSTAVO PATIÑO [email protected] 1 Arquitectura de Arquitectura de Computadores Computadores Departamento de Ingeniería Electrónica Departamento de Ingeniería Electrónica Facultad de Ingeniería Facultad de Ingeniería

Transcript of JERARQUÍA DE MEMORIA MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ...

Page 1: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

JERARQUÍA DE MEMORIA MEMORIA VIRTUAL

SEMANA NO.15SEMESTRE 2012-1

PROF. EUGENIO DUQUE PÉ[email protected]. GUSTAVO PATIÑ[email protected]

1

Arquitectura de Arquitectura de ComputadoresComputadores

Departamento de Ingeniería ElectrónicaDepartamento de Ingeniería Electrónica

Facultad de IngenieríaFacultad de Ingeniería

Page 2: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Virtual MemoryVirtual Memory2

The main memory can act as a “cache” for the secondary storage, usually implemented with magnetic disks.

This technique is called Virtual Memory.There are two major motivations for virtual

memory: to allow efficient and safe sharing of memory among multiple programs and to remove the programming burdens of a small, limited amount of main memory.

Page 3: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Virtual Memory Virtual Memory (…cont)(…cont)3

Main memory needs to contain only the active portions of the many programs, just as a cache contains only the active portion of one program.

This allows us to efficiently share the processor as well as the main memory.

Virtual memory implements the translation of a program’s address space to physical addresses. This translations enforces protection of a program’s address space from other programs.

Page 4: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Virtual Memory Virtual Memory (…cont)(…cont)4

Virtual memory manages the two levels of the memory hierarchy represented by main memory (sometimes called physical memory to distinguish it from virtual memory) and secondary storage.

Although the concepts at work in virtual memory and in caches are the same, their differing historical roots have led to the use of different terminlogy.

Page 5: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

TerminologyTerminology5

Page : A block in the virtual memory. Page fault : A virtual memory miss.

A page fault will take millions of cycles to process. This enormous miss penalty, dominated by the time to get

the first word for typical page sizes, leads to several key decisions in designing virtual memory systems.

Memory mapping (or address translation) : With virtual memory, the CPU produces a virtual address which is translated by a combination of HW and SW to a physical address, which in turn can be used to access main memory.

Analogy : Virtual Address can be seen like book title

Physical address like location of that book in the library.

Page 6: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Mapeo de MemoriaMapeo de Memoria6

Page 7: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2011 - 2

Mapeo de Memoria (…cont)7

Page 8: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Mapeo de MemoriaMapeo de Memoria (…cont) (…cont)8

El número de bits en el page offset determina el tamaño de la página.

El número de páginas direccionables con la dirección virtual no necesita corresponder con el número de páginas direccionables con la dirección física.

Tener un número mayor de páginas virtuales, que el número de páginas físicas, es la base de la ilusión de una cantidad esencialmente ilimitada de memoria virtual.

Page 9: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2011 - 2

Decisiones claves para el diseño de memoria virtual

9

Page 10: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Placing a page and finding it againPlacing a page and finding it again10

If we allow a virtual page to be mapped to any physical page (fully associative placement), the operating system can then choose to replace any page it wants when a page faults occurs.

Problems : it would be necessary a full search.

Page 11: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Placing a page and finding it againPlacing a page and finding it again (… (…cont)cont)

11

In virtual memory, we locate pages by using a full table that indexes the memory.

This structure is called a page table.A page table is indexed with the page number

from the virtual address and contains the corresponding physical page number.

Page 12: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Placing a page and finding it againPlacing a page and finding it again (… (…cont)cont)

12

Each program has its own page table, which maps the virtual address space of that program to main memory.

To indicate the location of the page table in memory, the HW includes a register that points to the start of the page table. Page Table Register.

Page 13: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2011 - 2

The Page Table13

Page 14: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

The page tableThe page table (…cont) (…cont)14

Because the page table contains a mapping for every possible virtual page, no tags are required.

In cache terminology, the index, which is used to access the page table, consists of the full block address, which is the virtual page number.

Page 15: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

What happen with every program ?What happen with every program ?15

The page table, together with the program counter and the registers, specifies the state of a program.

If we want to allow another program to use the CPU, we must save this state.

Later, after restoring this state, the program can continue execution. This state is often refer as a process.

The process is considered active when it is in possesion of the CPU; otherwise, it is considered inactive.

Rather than save the entire page table, the operating system symply loads the page table register to point to the page table of the process it wants to make active.

Page 16: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

Making Address Translation Fast : The Making Address Translation Fast : The TLBTLB

16

Since the page tables are stored in main memory, every memory access by a program can take at least twice as long: one memory access to obtain the physical address and a second access to get the data.

The key to improving access performance is to rely on locality of reference to the page table.

When a translation for a virtual page number is used, it will probably be needed again in the near future because the references to the words on that page have both temporal and spatial locality.

Page 17: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2012 - 1

The TLBThe TLB17

Accordinly, modern machines include a special cache that keeps track of recently used translations.

This special address translation cache is traditionally referred to as a Translation Lookaside Buffer (TLB).

The TLB is a cache that holds only page table mappings. Thus each tag entry in the TLB holds a portion of the virtual page number, and each data entry of the TLB holds a physical page number.

Page 18: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2011 - 2

The TLB (…cont)18

Page 19: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2011 - 2

Integrating Virtual Memory, TLBs and Caches

19

Page 20: JERARQUÍA DE MEMORIA  MEMORIA VIRTUAL SEMANA NO.15 SEMESTRE 2012-1 PROF. EUGENIO DUQUE PÉREZ EADUQUE@UDEA.EDU.CO PROF. GUSTAVO PATIÑO GPATINO@UDEA.EDU.CO.

Departamento de Ing. Electrónica. Arquitectura de Computadores Facultad de Ingeniería 2011 - 2

Ejemplo del procesamiento de una condición de lectura o escritura en el procesador DECStation 3100

20