Memory virtualization mechanism: paging and tlb


What is paging?

Overview
After allocation
What data structure is needed?
Address translation with paging
New questions!

Page Table

Contents of a page table entry (PTE) for 32-bit x86
Size of page table 32-bit x86
How can we reduce the size of the page table?
Bigger pages
Hybrid

Multi-level page tablescco

Overview
Multi-level page tables
Advantages
Cost

Translation Lookaside Buffer

Overview
What is in TLB?
First issue with TLB
Second issue with TLB
TLB and locality
Hands on: memory access
1
2
3
4
5
6
7
8
9
10
11
#include <stdlib.h>
#define N 50000000

int main(int argc, char *argv[]) {
  int i;
  int *A = (int *)malloc(N*sizeof(int));
  if (!A) return 1;
  for(i = 0; i < 10000; i++)
    A[i] = 0;
  return 0;
}
1
2
3
4
5
6
7
8
9
10
11
#include <stdlib.h>
#define N 50000000

int main(int argc, char *argv[]) {
  int i;
  int *A = (int *)malloc(N*sizeof(int));
  if (!A) return 1;
  for(i = 0; i < N; i += 5000)
    A[i] = 0;
  return 0;
}

Questions

Solution: Details
1
2
gcc -o memory_access_v1 memory_access_v1.c
time ./memory_access_v1
1
2
gcc -o memory_access_v2 memory_access_v2.c
time ./memory_access_v2

Demand paging

Overview
Demand paging
Demand paging control flow
Dirty bit
Replacement algorithms
We predict the future based on patterns …
Example policies

Matrix multiplication

Question: Details
Hands on: matrix multiplication
Questions
1
2
3
4
gcc -o matrix_compare matrix_compare.c
./matrix_compare 1000
./matrix_compare 1500
./matrix_compare 2000