






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







CIS 371 (Roth/Martin): Virtual Memory & I/O 1
-! Virtual memory -! Disks & I/O -! Power & energy -! Reliability -! Data-level parallelism (SIMD, Vectors, and GPUs) -! XBox 360 case study
-! Only three lectures remaining⦠-! By design (weāre actually āon scheduleā) -! Will try to hit the highlights, give some context -! Try not to be overwhelmed CIS 371 (Roth/Martin): Virtual Memory & I/O 2
-! A super-application -! Hardware support for an OS
-! Page tables and address translation -! TLBs and memory hierarchy issues
-! Magnetic storage (disks) -! Solid-state storage (flash memory) Mem CPU I/O System software App App App
-! Virtual Memory: 5. -! I/O & Disks: 6.1-6.5, 6.
CIS 371 (Roth/Martin): Virtual Memory & I/O 5
-! Connected by memory bus
-! With separate or built-in DMA -! Connected by system bus (which is connected to memory bus) Memory Disk kbd
display (^) NIC I/O ctrl Memory bus System (I/O) bus CPU/$ bridge CPU/$ CIS 371 (Roth/Martin): Virtual Memory & I/O 6
Memory Disk kbd
display (^) NIC I/O ctrl Memory bus System (I/O) bus CPU/$ bridge CPU/$ Application sofware
-! Abstraction : provides services (e.g., threads, files, etc.) +!Simplifies app programming model, raw hardware is nasty -! Isolation : gives each app illusion of private CPU, memory, I/O +!Simplifies app programming model +!Increases hardware resource utilization Memory Disk kbd
display (^) NIC I/O ctrl Memory bus System (I/O) bus CPU/$ bridge CPU/$ OS Application Application Application Application
-! Hardware itself facilitates/enforces this split
-! Manages hardware resource allocation/revocation for all processes -! Has direct access to resource allocation features -! Aware of many nasty hardware details -! Aware of other processes -! Talks directly to input/output devices (device driver software)
-! Unaware of most nasty hardware details -! Unaware of other apps (and OS) -! Explicitly denied access to resource allocation features
CIS 371 (Roth/Martin): Virtual Memory & I/O 13
-! Goal: each application thinks it has infinite memory
-! Appās insn/data footprint may be larger than main memory -! Requires main memory to act like a cache -! With disk as next level in memory hierarchy (slow) -! Write-back, write-allocate, large blocks or āpagesā -! No notion of āprogram not fittingā in registers or caches (why?)
-! Part #1: treat memory as a ācacheā -! Store the overflowed blocks in āswapā space on disk -! Part #2: add a level of indirection (address translation) CIS 371 (Roth/Martin): Virtual Memory & I/O 14
-! VA size also referred to as machine size -! E.g., 32-bit (embedded) or 64-bit (server)
-! 0ā¦2Mā1 (typically M<N, especially if N=64) -! 2 M^ is most physical memory machine supports
-! By āsystemā -! Mapping need not preserve contiguity -! VP need not be mapped to any PP -! Unmapped VPs live on disk (swap)
Disk Program Main Memory code heap stack
-! Level of indirection (like register renaming) -! Application generated addresses are virtual addresses (VAs) -! Each process thinks it has its own 2N^ bytes of address space -! Memory accessed using physical addresses (PAs) -! VAs translated to PAs at some coarse granularity -! OS controls VA to PA mapping for itself and all other processes -! Logically: translation performed before every insn fetch, load, store -! Physically: hardware acceleration removes translation overhead ā¦
App ⦠App VAs PAs (physical memory) OS controlled VA!PA mappings
-! IBM System 370: a family of computers with one software suite +! Same program could run on machines with different memory sizes -! Prior, programmers explicitly accounted for memory size
-! Memory tmiss is high: extremely important to reduce %miss Parameter I$/D$ L2 Main Memory thit 2ns 10ns 30ns tmiss 10ns 30ns 10ms (10M ns) Capacity 8ā64KB 128KBā2MB 64MBā64GB Block size 16ā32B 32ā256B 4+KB Assoc./Repl. 1ā4, NMRU 4ā16, NMRU Full, āworking setā
CIS 371 (Roth/Martin): Virtual Memory & I/O 17
-! Each app thinks it has 2N^ B of memory, its stack starts 0xFFFFFFFF,⦠-! Apps prevented from reading/writing each otherās memory -! Canāt even address the other programās memory!
-! Each page with a read/write/execute permission set by OS -! Enforced by hardware
-! Map same physical pages into multiple virtual address spaces -! Or share files via the UNIX mmap() call ā¦
App ⦠App CIS 371 (Roth/Martin): Virtual Memory & I/O 18 Disk
-! VA size (N) aka machine size (e.g., Core 2 Duo: 48-bit)
-! PA size (M) typically M<N, especially if N= -! 2 M^ is most physical memory machine supports
-! Mapping need not preserve contiguity -! VP need not be mapped to any PP -! Unmapped VPs live on disk (swap) or nowhere (if not yet touched) ā¦
App ⦠App
-! Split VA into virtual page number (VPN) & page offset (POFS) -! Translate VPN into physical page number (PPN) -! POFS is not translated -! VA!PA = [VPN, POFS]! [PPN, POFS]
-! 64KB pages! 16-bit POFS -! 32-bit machine! 32-bit VA! 16-bit VPN -! Maximum 256MB memory! 28-bit PA! 12-bit PPN virtual address[31:0] VPN[31:16] POFS[15:0] physical address[25:0] PPN[27:16] POFS[15:0] translate donāt touch
-! In software (for now) but with hardware acceleration (a little later)
-! Software data structure constructed by OS -! Maps VPs to PPs or to disk (swap) addresses -! VP entries empty if page never referenced -! Translation is table lookup struct { int ppn; int is_valid, is_dirty, is_swapped; } PTE; struct PTE page_table[NUM_VIRTUAL_PAGES]; int translate(int vpn) { if (page_table[vpn].is_valid) return page_table[vpn].ppn; } PT vpn Disk(swap)
CIS 371 (Roth/Martin): Virtual Memory & I/O 25
-! Piggy-back page-table mechanism -! Map VPN to PPN + Read/Write/Execute permission bits -! Attempt to execute data, to write read-only data? -! Exception! OS terminates program -! Useful (for OS itself actually) struct { int ppn; int is_valid, is_dirty, is_swapped, permissions; } PTE; struct PTE page_table[NUM_VIRTUAL_PAGES]; int translate(int vpn, int action) { if (page_table[vpn].is_valid && !(page_table [vpn].permissions & action)) kill; ⦠} (^) CIS 371 (Roth/Martin): Virtual Memory & I/O 26
-! Translate VA to PA before every cache access -! Walk the page table before every load/store/insn-fetch -! Would be terribly inefficient (even in hardware)
-! Translation Lookaside Buffer (TLB) : cache translations -! Only walk page table on TLB miss
-! Functionality problem? Add indirection (e.g., VM) -! Performance problem? Add cache (e.g., TLB)
-! Small cache: 16ā64 entries -! Associative (4+ way or fully associative) +! Exploits temporal locality in page table -! What if an entry isnāt found in the TLB? -! Invoke TLB miss handler VPN PPN VPN PPN VPN PPN ātagā ādataā
Main Memory
VA PA
-! Indexed and tagged by physical addresses +! Natural, ālazyā sharing of caches between apps/OS
+! Cached inter-process communication works
-! Single copy indexed by physical address -! Slow: adds at least one cycle to thit
-! Indexed and tagged by virtual addresses -! Flush across context switches -! Or extend with process id tags
Main Memory
VA PA
CIS 371 (Roth/Martin): Virtual Memory & I/O 29
-! What if (cache size) / (associativity)! page size -! Index bits same in virt. and physical addresses!
-! Cache access needs tag only at very end +! Fast: no additional thit cycles +! No context-switching/aliasing problems -! Dominant organization used today
-! Implication: associativity allows bigger caches
Main Memory
VA TLB PA tag [31:12] index [11:5] [4:0] VPN [31:16] page offset [15:0] ? PPN[27:16] page offset [15:0] CIS 371 (Roth/Martin): Virtual Memory & I/O 30
-! Capacity -! Associativity (At least 4-way associative, fully-associative common) -! What does it mean for a TLB to have a block size of two? -! Two consecutive VPs share a single tag -! Like caches : there can be L2 TLBs
-! 32-entry fully-assoc. TLBs, 512-entry 4-way L2 TLB (insn & data) -! 4KB pages, 48-bit virtual addresses, four-level page table
-! In other words: (#PTEs in TLB) * page size! L2 size -! Why? Think about relative miss latency in eachā¦
-! Two ways to āfillā it, both relatively fast
-! Short (~10 insn) OS routine walks page table, updates TLB +! Keeps page table format flexible -! Latency: one or two memory accesses + OS call (pipeline flush)
-! Page table root in hardware register, hardware āwalksā table +! Latency: saves cost of OS call (pipeline flush) -! Page table format is hard-coded
-!! page not in memory -! Starts out as a TLB miss, detected by OS/hardware handler
-! Choose a physical page to replace -! āWorking setā : refined LRU, tracks active page usage -! If dirty, write to disk -! Read missing page from disk -! Takes so long (~10ms), OS schedules another task -! Requires yet another data structure: frame map (why?) -! Treat like a normal TLB miss from here
CIS 371 (Roth/Martin): Virtual Memory & I/O 37
-! Seek delay (tseek) : head seeks to right track -! Average of ~5ms - 15ms -! Less in practice because of shorter seeks) -! Rotational delay (trotation) : right sector rotates under head -! On average: time to go halfway around disk -! Based on rotation speed (RPM) -! 10,000 to 15,000 RPMs -! ~3ms -! Transfer time (ttransfer) : data actually being transferred -! Fast for small blocks -! Controller delay (tcontroller) : controller overhead (on either side) -! Fast (no moving parts)
CIS 371 (Roth/Martin): Virtual Memory & I/O 38
-! 128 sectors/track, 512 B/sector, 6000 RPM, 10 ms tseek, 1 ms tcontroller -! 6000 RPM! 100 R/s! 10 ms/R! trotation = 10 ms / 2 = 5 ms -! 4 KB page! 8 sectors! ttransfer = 10 ms * 8/128 = 0.6 ms -! tdisk = tseek + trotation + ttransfer + tcontroller = 16.6 ms -! tdisk = 10 + 5 + 0.6 + 1 = 16.6 ms
-! Sequential vs random accesses
-! One read each disk access latency (~10ms) -! Randomly reading 4KB pages -! 10ms is 0.01 seconds! 100 access per second -! 4KB * 100 access/sec! 400KB/second bandwidth
-! Stream data from disk (no seeks) -! 128 sectors/track, 512 B/sector, 6000 RPM -! 64KB per rotation, 100 rotation/per sec -! 6400KB/sec! 6.4MB/sec
-! Still no where near the 1GB/sec to 10GB/sec of memory
-! The ānew diskā: replacing disk in many Ultrastar Travelstar Microdrive Diameter 3.5ā 2.5ā 1.0ā Capacity 300 GB 40 GB 4 GB Cache 8 MB 2 MB 128KB RPM 10,000 RPM 4200 RPM 3600 RPM Seek 4.5 ms 12 ms 12 ms Sustained Data Rate 100 MB/s 40 MB/s 10 MB/s Cost $450 $120 $ Use Desktop Notebook some iPods
CIS 371 (Roth/Martin): Virtual Memory & I/O 41
-! More sequential seeks (layout files on disk intelligently)
-! Mechanical disks (~5ms seek time), rotation time -! Higher RPMs help bandwidth (but not really latency)
-! āYou can always buy bandwidthā -! Disk arrays : buy more disks, stripe data across multiple disks -! Increases both sequential and random access bandwidth -! Use the extra resources in parallel -! Yet another example of parallelism CIS 371 (Roth/Martin): Virtual Memory & I/O 42
-! Find bandwidths of individual components -! Configure components you can change⦠-! To match bandwidth of bottleneck component you canāt -! Caveat: real I/O systems modeled with simulation
-! 300 MIPS CPU, 150K insns per I/O operation, random reads -! I/O bus: 200 MB/s Disk controllers: 30 MB/s, up to 7 disks each -! Workload has multiple tasks to keep CPUs busy during I/O
-! What is the access time for the random access of a specific size? -! 4KB, 64KB, 256KB -! What is the maximum sustainable I/O rate for random accesses? -! How many disk controllers and disks does it require?
-! 1024 sectors/track, 512 B/sector, 12000 RPM -! tseek is 6.5 ms, tcontroller is 0.375 ms
-! 12000 RPM! 200 R/s! 5 ms/R! trotation = 5 ms / 2 = 2.5 ms
-! 4KB read! 8 sectors! ttransfer = 5 ms * 8/1024 = 0.039 ms -! 64KB read! 128 sectors! ttransfer = 5 ms * 128/1024 = 0.625 ms -! 256KB read! 512 sectors! ttransfer = 5 ms * 512/1024 = 2.5 ms
-! tdisk for 4KB = 6.5 + 2.5 + 0.039 + 0.375 = 9.4 ms -! tdisk for 64KB = 6.5 + 2.5 + 0.625 + 0.375 = 10 ms -! tdisk for 256KB = 6.5 + 2.5 + 2.5 + 0.375 = 11.9 ms
-! CPU: (300M insn/s) / (150K Insns/IO) = 2000 IO/s -! I/O bus: (200MB/s) / ( 4K B/IO) = 51200 IO/s -! Peak I/O rate determined by cpu: 2000 IO/s -! 2000 IO/s * 4KB per IO = 7.8MB/s
-! Disk: 9.4 ms is 0.0094 sec, so each disk is 106 IO/s & 0.41MB/sec -! How many disks? -! (2000 IO/s) / (106 IO/s) = 19 disks -! How many controllers? -! At 0.4 MB/sec per disk, 75 disks max for each 30MB/s controller -! But each controller can only support 7 disks⦠-! Thus, for 19 disks, we need 3 controllers