OSTEP Chapter 18

ECE 3600, Fall 2022


Table of Contents


1. Paging

page = fixed-size unit of virtual memory

page frame = fixed-size unit of physical memory

 

2. Virtual Page Number


3. Virtual Address Translation

PFN = physical frame number


4. Linear Page Table


5. Translation Protocol

PTBR = page-table base register

specify VPN_MASK, SHIFT, OFFSET_MASK, and PFN_SHIFT : ________________


6. Code Example

From the book, Chapter 18 pages 9-10:
int array[1000]; // 1000 = 0x3e8
...
for (i = 0; i < 1000; i++)
  array[i] = 0;

gcc -o array array.c -Wall -O
objdump -d array

1024 movl $0x0,(%edi,%eax,4)
1028 incl %eax
1032 cmpl $0x03e8,%eax
1036 jne  0x1024
Compare using gcc-8.2.0 on Linux x86_64:
int main(void) {
  int array[1000];
  for( int i = 0; i < 1000; ++i) array[i] = 0;
  return array[10];
}

gcc -m32 -S array.c

array.s:
...
	movl	$0, -4(%ebp)
	jmp	.L2
.L3:
	movl	-4(%ebp), %eax
	movl	$0, -4004(%ebp,%eax,4)
	addl	$1, -4(%ebp)
.L2:
	cmpl	$999, -4(%ebp)
	jle	.L3
...

7. Memory Trace

Assume: virtual address space size = 64KB, page size = 1KB
linear (array-based) page table at physical address = 1KB (1024)
Code: VA = 1024 --> VPN = 1 --> PFN = 4
array: VA = 40000 --> VPN = 39, 40, 41, 42 --> PFN = 7, 8, 9, 10

verify PA 7232 = __________


8. Exercises

Exercises from the book using paging-linear-translate.py:
args = -P 1k -a 1m -p 512m -v -n 0
ARG address space size 1m
ARG phys mem size 512m
ARG page size 1k
size =  1024

args = -P 1k -a 2m -p 512m -v -n 0
ARG address space size 2m
ARG phys mem size 512m
ARG page size 1k
size =  2048