Presentation is loading. Please wait.

Presentation is loading. Please wait.

SE-292: High Performance Computing Memory Organization R. Govindarajan

Similar presentations


Presentation on theme: "SE-292: High Performance Computing Memory Organization R. Govindarajan"— Presentation transcript:

1 SE-292: High Performance Computing Memory Organization R. Govindarajan

2 2 Use of Main Memory by a Program Instructions (code, text) Data used in different ways Stack allocated Heap allocated Statically allocated text data Heap Stack Use of memory addresses

3 3 Stack Allocated Variables Space allocated on function call, reclaimed on return Addresses calculated and used by compiler, relative to the top of stack, or some other base register associated with the stack Growth of stack area is thus managed by the program, as generated by the compiler

4 4 Heap Allocated Variables Managed by a memory allocation library Functions like malloc, realloc,free Get `linked (joined) to your program if they are called Executed just like other program functions What about growth of the heap area? Managed by the library functions

5 5 Memory Management: Protection There could be many programs running on the same machine concurrently Sharing the resources of the computer Processor time, Main memory Must be protected from each other: one program should not be able to access the variables of another Typically done through Memory management schemes – paged memory, segmentation, … Involves Address Translation

6 6 Idea of Virtual Memory Each executing program uses addresses in the range 0.. MaxAddress These addresses are not real, but only Virtual Addresses They are translated into real main memory addresses Many programs in execution can safely share main memory Terminology virtual address, physical address

7 7 Example: Main Memory Management Example: Paged Virtual Memory To translate a virtual address to the corresponding physical address, a table of translation information is needed Minimize size of table by not managing translations on byte basis but larger granularity Page: fixed size unit of memory (contiguous memory locations) for which a single piece of translation information is maintained

8 8 Paged Virtual Memory 0x x xFFFFFFFF 0x x000000FF 256 Bytes Virtual Address Space Virtual Page 0 Virtual Page 1 Virtual Page 0xFFFFFF … … Physical Address Space 0x xFFFFFF 0x0000FF 256 Bytes Physical Page 0 … 0x000001FF PROGRAM/PROCESS MAIN MEMORY Text Data Stack Heap 0x x x xFFFFFFFF 0x000000FF 0x000001FF 0x : 0x000024:

9 9 Address Translation Virtual address Translation table Physical address Virtual page number (VPN) Offset VPN PPN Physical Page Number (PPN) Offset PAGE TABLE

10 10 Whats happening… Disk P1P2Pn … Virtual page contents Main Memory Page Tables P1 P2 Pn … Processes

11 11 Page Fault Situation where virtual address generated by processor is not available in main memory Detected on attempt to translate address Page Table entry is invalid Must be `handled by operating system Identify slot in main memory to be used Get page contents from secondary memory Part of disk can be used for this purpose Update page table entry Data can now be provided to the processor

12 12 Page Replacement Policies Question: How does the page fault handler decide which main memory page to replace when there is a page fault? Principle of Locality of Reference A commonly seen program property If memory address A is referenced at time t, then it and its neigbhouring memory locations are likely to be referenced in the near future Suggests that a Least Recently Used (LRU) replacement policy would be advantageous temporal spatial

13 13 Locality of Reference Based on your experience, why do you expect that programs will display locality of reference? Program Data Same address (temporal) Neighbours (spatial) Loop Function Sequential code Loop Local Loop index Stepping through array

14 14 Page Replacement Policies LRU might be too expensive to implement Alternatives Approximation to LRU First in First Out (FIFO) Random

15 15 Implementation of Address Translation Easy, But cant be done by OS, which is software Memory Management Unit (MMU): part of CPU; hardware that does address translation 1. Problems: Big Page Table size Example: 32b virtual address, 16KB page size 256K virtual pages => MB page table size per process Has to be stored in memory, probably virtual address space Need multiple memory accesses for each memory access Translation Lookaside Buffer (TLB): memory in MMU that contains some page table entries that are likely to be needed soon TLB Miss: required entry not available = 2 18


Download ppt "SE-292: High Performance Computing Memory Organization R. Govindarajan"

Similar presentations


Ads by Google