17

Click here to load reader

HPC Lecture15

Embed Size (px)

Citation preview

Page 1: HPC Lecture15

High Performance Computing

Matthew Jacob

Indian Institute of Science

Page 2: HPC Lecture15

2

Least Recently Used (LRU) Policy Keep track of when each page was last used With a timestamp LRU page: the one with the smallest timestamp Requires a large number of comparisons

Or, keep track of the stack of recently used pages LRU page: at the bottom of the stack Stack must be updated on every memory access

So, LRU might be too expensive in practise

Page 3: HPC Lecture15

3

Alternative Page Replacement Policies1. First in First Out (FIFO) Keep track of the order in which the pages came

into memory Advantage: Does not have to be updated when a

page is re-accessed Problem: Unlike LRU, FIFO does not guarantee

that the number of page faults will decrease if you increase the size of main memory

Page 4: HPC Lecture15

4

Alternative Page Replacement Policies1. First in First Out (FIFO)2. Approximate LRUExample: Maintain 1 bit of status information

with each physical page Initialized all the bits to 0 Set a bit to 1 when that page is referenced Replace a page that has its bit equal to 0 Reset all the bits to 0 every once in a while

Page 5: HPC Lecture15

5

Alternative Page Replacement Policies1. First in First Out (FIFO)2. Approximate LRU3. Random Randomly pick an i which is between 1 and n Replace page Pi

Page 6: HPC Lecture15

6

Keeping Track: Page Table Entry

PPN

VPN

Disk Addr V? LRU bits

Page 7: HPC Lecture15

7

Page Fault Handler1. Identify slot in main memory to be used2. Get page contents from disk3. Update page table entry

Problem: The victim page identified by the page replacement policy might have been modified while it was in main memory

It cannot just be overwritten by the incoming page but must first be copied back to disk

Optimization: Keep track of whether it has been modified while in memory

Page 8: HPC Lecture15

8

Keeping Track: Page Table Entry

PPN

VPN

Disk Addr V? LRU bits

M?Modified bit

Dirty bit

Page 9: HPC Lecture15

9

Implementation of Address Translation Memory Management Unit (MMU): part of CPU;

hardware that does address translation Recall: The Big Problem of page table size

e.g., 32b addresses, 256B page size Page table size: 64MB (per process) Could be stored in memory Probably in a virtual address space To translate a virtual memory address, the MMU has to

read the relevant page table entry out of memory

Page 10: HPC Lecture15

10

Computer Organization: Hardware

Memory

I/O

Bus

I/OI/O

MMU

ALU Registers

CPU

Control

LW R1, -8(R29)

Page 11: HPC Lecture15

11

Inside the Processor

MemIR

+

PC

NPC

RegFile

signextend

A

Imm

B

Inst FetchIF

Inst DecodeID

4

ALUoutALU

Zero?

Mem LMD

ExecutionEX

MemoryMEM

Cond

WB

Address translation comes in here

Page 12: HPC Lecture15

12

Implementation of Address Translation Memory Management Unit (MMU): part of CPU;

hardware that does address translation Recall: The Big Problem of page table size

e.g., 32b addresses, 256B page size Page table size: 64MB (per process) Could be stored in memory Probably in a virtual address space To translate a virtual memory address, the MMU has to

read the relevant page table entry out of memory Hardware must provide page table entries faster than

that (most of the time)

Page 13: HPC Lecture15

13

Implementation of Address Translation Translation Lookaside Buffer (TLB): memory in MMU

that contains some page table entries that are likely to be needed soon

Recall: Cache memory contains data/instructions that the CPU is likely to need soon

If the required page table entry is present in the TLB, then the MMU can do the translation fast

Otherwise: TLB miss Must be handled, possibly like the OS handles a

page fault

Page 14: HPC Lecture15

14

Recall: PageUnit of memory management Translation: There is one translation table entry

per page Data movement: A page of data is copied together

between main memory and disk We used the example of 256B in each page

Question: How big is a page in practice?

Page 15: HPC Lecture15

15

Page Size A tradeoff is involved here: the larger the

page size the smaller the page table, but more potentially unused memory space within a

page (internal fragmentation)

The unit of transfer to hard disks is typically 512B (disk sector)

A typical page size: 4KB

Page 16: HPC Lecture15

16

0x00000000

0x00000100

0xFFFFFFFF

0x00000200

0x000000FF

Virtual Address Space

0x000001FF

0x00000000

0x00000100

0x00000200

0xFFFFFFFF

0x000000FF

0x000001FF

Virtual Page 0

Virtual Page 1

VirtualPage0xFFFFFF

Physical Address Space0x000000

0xFFFFFF

0x0000FFPhysicalPage 0

MAIN MEMORY

Recall: Address SpacePROCESS

Address Space size and Address size

Page 17: HPC Lecture15

17

Virtual address Physical address

Address Space Size, Address Size