PFN: 20 bits for physical page frame number (page size 4K)P: present bit, whether this page is on memory or on disk (swapped)R/W: read/write bit, whether writes are allowed to this pageU/S: user/supervisor bit, whether user-mode processes can access this pageA: access bit, whether this page has been accessedD: dirty bit, whether this page has been modifiedPWT, PCD, PAT, G: how hardware caching works for this page
getconf PAGESIZE in your VM to observe this)
Space versus Time: To reduce space, increased access translation steps are needed: one for the page directory and one for the PTE itself.
memory_access_v1.c with the following contents:
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;
}
memory_access_v2.c with the following contents:
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
memory_access_v1.c:
1
2
gcc -o memory_access_v1 memory_access_v1.c
time ./memory_access_v1
memory_access_v2.c.
1
2
gcc -o memory_access_v2 memory_access_v2.c
time ./memory_access_v2
pagefile.sys P) indicates whether the page is in memory or on disk.P = 0 (on disk), then the remaining bits in PTE store the disk address of the page.
P to 0, moves the page to swap space, and stores the location of the page in the swap space in the PTE.page_fault_handler, which locates the page in the swap file.dirty == 0) since it was loaded from swap, nothing will need to be written to disk when the page is evicted again.Locality: the patterns in computer programs’ behaviors.Spatial locality: If an address A is accessed, then addresses A - 1 and A + 1 are also likely to be accessed.Temporal locality: if an address is accessed at time T, then it is also likely to be accessed again in the future T + Δt.
matrix_compare.c with the following contents:matrix_mul_v1 or matrix_mul_v2) represents which multiplication approach from the question?matrix_compare.c:
1
2
3
4
gcc -o matrix_compare matrix_compare.c
./matrix_compare 1000
./matrix_compare 1500
./matrix_compare 2000