Jerarquía de Memoria

Presenter Notes

Escala de tiempos de la tecnología actual

Presenter Notes

Escala de tiempos de la tecnología actual

Presenter Notes

Sci-Fi

Star Trek: First Contact (1996)

Data: [about the Borg Queen] She brought me closer to humanity than I ever thought possible. And for a time, I was tempted by her offer.

Picard: How long a time?

Data: 0.68 seconds sir. For an android, that is nearly an eternity.

Her (2013)

It's like I'm reading a book… and it's a book I deeply love. But I'm reading it slowly now. So the words are really far apart and the spaces between the words are almost infinite. I can still feel you… and the words of our story… but it's in this endless space between the words that I'm finding myself now. It's a place that's not of the physical world. It's where everything else is that I didn't even know existed. I love you so much. But this is where I am now. And this who I am now. And I need you to let me go. As much as I want to, I can't live your book any more.

Presenter Notes

Memory Wall

Presenter Notes

Memory Wall

Wulf, McKee, Hitting the Memory Wall: Implications of the Obvious, 1995.

if the microprocessor/memory performance gap continues to grow at a similar rate, in 10-15 years each memory access will cost, on average, tens or even hundreds of processor cycles. Under each scenario, system speed is dominated by memory performance.

PowerEdge CPU vs. Memory

(Memory Wall -- HPBD 070809 HIGH PERFORMANCE COMPUTING - WIKI, Dell Inc.)

Presenter Notes

Jerarquía de Memoria

Jerarquía de Memoria

(Penn CIS565)

Presenter Notes

Latencia vs. Ancho de Banda

Latencia, ancho de banda y tamaño de la jerarquía de memoria

(Penn CIS565)

  • Trade-off entre: latencia, ancho de banda, tamaño, precio.
  • Falta un nivel más arriba: registros.

Presenter Notes

4 preguntas de Jerarquía de Memoria

  • (Q1) ¿Dónde pongo un bloque en la caché?
  • (Q2) ¿Cómo encuentro un bloque en la caché?
  • (Q3) ¿Qué bloque reemplazo en un fallo?
  • (Q4) ¿Qué pasa en una escritura?

Presenter Notes

(Q1) Caché: mapa de muchos a n-way

Asociatividad de Caché

(Hennessy, Patterson, Computer Architecture ...)

Presenter Notes

(Q1) Caché: mapa de muchos a n-way (2)

Típicamente 8 o 16-way, más no paga:

Miss rate versus cache size on the Integer portion of SPEC CPU2000

(Wikipedia, CPU Cache)

Presenter Notes

Línea de caché

Se trae mucho más que una palabra (4 u 8 bytes).

Típicamente 64 bytes.

Favorece la localidad espacial.

1 unsigned int i = 0, s = 0;
2 for (i=s=0; i<size; ++i) {
3     s +=a[i];
4 }

Presenter Notes

(Q2) ¿Cómo distingo el uno en muchos?

Cache address

(Hennessy, Patterson, Computer Architecture ...)

Comparación n-way en paralelo.

  • Cache miss.
  • Cache hit.

Presenter Notes

(Q3) ¿Qué bloque reemplazo en un fallo?

Estrategia de reemplazo least-recently used (LRU), o alguna aproximación.

Favorece la localidad temporal.

1 unsigned int i = 0, s = 0;
2 for (i=s=0; i<size; ++i) {
3     s +=a[i];
4 }

Presenter Notes

(Q4) ¿Qué pasa en una escritura?

Dos estrategias:

  • Write through.
  • Write back (dirty bit).

Dos estrategias en write miss:

  • Write allocate.
  • No-write allocate.

Presenter Notes

Localidad Espacial y Temporal - 1

Presenter Notes

Localidad Espacial y Temporal - 2

Presenter Notes

Localidad Espacial y Temporal (real)

Presenter Notes

Optimizaciones avanzadas

  • Way-prediction (predicción del índice).
  • Cache multibanco (acceso simultáneo a 2 o más bancos).
  • Write merging con write buffers.
  • Prefetching.

Presenter Notes

Memoria Virtual

Cada acceso a memoria consulta la tabla de página.

Virtual a física

(Hennessy, Patterson, Computer Architecture ...)

Tabla de página

  • Árbol multinivel.
  • Típicamente 2 o 3 niveles.
  • ¿Recorrer un árbol de 3 niveles en cada acceso a memoria?

Presenter Notes

TLB

Caché completamente asociativo.

Opteron TLB

("Opteron TLB", Hennessy, Patterson, Computer Architecture ...)

Ahora hay TLB multi-niveles, uno en L1 y otro en L2.

Presenter Notes

Cubrimiento de la TLB

Presenter Notes

HugePages

1 nicolasw@zx81:~$ grep Huge /proc/meminfo 
2 AnonHugePages:         0 kB
3 HugePages_Total:       0
4 HugePages_Free:        0
5 HugePages_Rsvd:        0
6 HugePages_Surp:        0
7 Hugepagesize:       2048 kB

Transparent Huge Pages

 1 nicolasw@zx81:~$ cat /sys/kernel/mm/transparent_hugepage/enabled 
 2 always [madvise] never
 3 nicolasw@zx81:~$ sudo echo "always" >  /sys/kernel/mm/transparent_hugepage/enabled
 4 nicolasw@zx81:~$ cat /sys/kernel/mm/transparent_hugepage/enabled 
 5 [always] madvise never
 6 nicolasw@zx81:~$ grep Huge /proc/meminfo 
 7 AnonHugePages:      4096 kB
 8 HugePages_Total:       0
 9 HugePages_Free:        0
10 HugePages_Rsvd:        0
11 HugePages_Surp:        0
12 Hugepagesize:       2048 kB

Corriendo DGEMM

1 root@zx81:~# grep Huge /proc/meminfo 
2 AnonHugePages:    184320 kB
3 HugePages_Total:       0
4 HugePages_Free:        0
5 HugePages_Rsvd:        0
6 HugePages_Surp:        0
7 Hugepagesize:       2048 kB

Presenter Notes

madvise()

 1 NAME
 2     madvise - give advice about use of memory
 3 
 4 SYNOPSIS
 5     #include <sys/mman.h>
 6     int madvise(void *addr, size_t length, int advice);
 7     ...
 8     MADV_HUGEPAGE (since Linux 2.6.38)
 9         Enable Transparent Huge Pages (THP) for pages in the range specified by addr  
10         and length.

Presenter Notes

Memoria virtual en ia32e

4 niveles de indirección, 4 accesos a memoria para 1 acceso real.

Presenter Notes

Bibliografía

Presenter Notes

Bibliografía

Presenter Notes

La clase que viene

Ayudando al compilador:

  • Que cosas NO vale la pena hacer.
  • Que cosas vale la pena hacer.

Presenter Notes