CS370 Operating Systems

Similar documents
CS370 Operating Systems

CS370 Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

CS370 Operating Systems

Chapter 9: Virtual Memory

Chapter 9: Virtual-Memory

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

Chapter 8: Main Memory

Chapter 8: Virtual Memory. Operating System Concepts

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 8: Memory-Management Strategies

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

OPERATING SYSTEM. Chapter 9: Virtual Memory

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Chapter 10: Virtual Memory

Operating System Concepts 9 th Edition

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Chapter 8: Main Memory

Chapter 8 Memory Management

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

CS307: Operating Systems

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani

Virtual Memory Outline

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

Chapter 9: Virtual-Memory Management. Operating System Concepts 8 th Edition,

CS370 Operating Systems

현재이이미지를표시할수없습니다. Chapter 9: Virtual Memory

Frequently asked questions from the previous class survey

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Chapter 8: Main Memory. Operating System Concepts 8th Edition

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Chapter 9: Virtual Memory. Chapter 9: Virtual Memory. Objectives. Background. Virtual-address address Space

Chapter 9: Virtual Memory

Virtual Memory - I. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XV. University at Buffalo.

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Basic Memory Management

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - XIV Virtual Memory - I. Louisiana State University.

Virtual Memory - I. Roadmap. Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Operating System Concepts

CS370 Operating Systems

CS370 Operating Systems

Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007

VIRTUAL MEMORY READING: CHAPTER 9

Chapter 8 Main Memory

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

Module 8: Memory Management

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Chapter 9: Virtual Memory

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical Memory

Operating Systems (1DT020 & 1TT802) Lecture 9 Memory Management : Demand paging & page replacement. Léon Mugwaneza

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

Chapter 8: Main Memory Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

CS307: Operating Systems

Operating Systems. Paging... Memory Management 2 Overview. Lecture 6 Memory management 2. Paging (contd.)

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 8: Main Memory

Chapters 9 & 10: Memory Management and Virtual Memory

CS 134: Operating Systems

Chapter 3: Virtual Memory ว ตถ ประสงค. Background สามารถอธ บายข อด ในการท ระบบใช ว ธ การจ ดการหน วยความจ าแบบเสม อนได

Chapter 8: Main Memory

Logical versus Physical Address Space

VII. Memory Management

3/3/2014! Anthony D. Joseph!!CS162! UCB Spring 2014!

Chapter 9: Virtual Memory

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Operating System 1 (ECS-501)

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Chapter 4 Memory Management

6 - Main Memory EECE 315 (101) ECE UBC 2013 W2

Outlook. Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The Intel Pentium

Memory Management. CSCI 315 Operating Systems Design Department of Computer Science

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems

Memory Management. Memory

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Chapter 8: Memory Management Strategies

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

Demand Paging. Valid-Invalid Bit. Steps in Handling a Page Fault. Page Fault. Transfer of a Paged Memory to Contiguous Disk Space

CS307 Operating Systems Main Memory

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

CSE325 Principles of Operating Systems. Virtual Memory. David P. Duggan. March 7, 2013

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

CS 5523 Operating Systems: Memory Management (SGG-8)

Module 8: Memory Management

Chapter 9: Virtual Memory

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Module 9: Memory Management. Background. Binding of Instructions and Data to Memory

Lecture 8 Memory Management Strategies (chapter 8)

Module 9: Virtual Memory

Virtual Memory COMPSCI 386

CS3600 SYSTEMS AND NETWORKS

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure.

Transcription:

CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 21 Main Memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1

FAQ Why not increase page size as address space increases? Allowed in some systems to a limited extent but not dynamically. Page Numbers: Few MSBs of addresses Hashed page table entries: pointers to a linked list Inverted page tables: An entry/frame, frame number is address Search using PID & page number Why multi-level paging? TLB 1-5% TIME & multi-level paging: page tables consulted on TLB miss. Multi level TLB possible Why 64 bit CPU/OS use less than 64 bit addresses? 40-52 lines How to increase hit ratio? 2

Evaluation of Algorithms in Systems In Systems (HW/OS/Net) algorithms are needed for Process scheduling Contiguous allocation policies Cache/TLB policies Page replacement policies Disk scheduling Network protocols etc. 3

Evaluation of Algorithms in Systems How to formulate an algorithm Examine existing algorithms Formulate a new one that may address some of the limitations Ensure that algorithm is valid Compare performance of the new algorithm with existing ones using suitable figures of merit: time, Will the best algorithm be best memory requirements, for all individual cases? power consumptions etc. If promising, tweak possible options by evaluating them to optimize implementation 4

Evaluation of Algorithms in Systems How to evaluate an algorithm Deterministic evaluation: use one or a few specific examples Pro: Good for understanding the algorithm Con: Examples will not be representative of all possible cases Probabilistic evaluation: take randomness into account Determine probabilistic distribution of inputs Analyze the system performance Mathematical analysis Simulation 5

Probabilistic evaluation Probabilistic evaluation: take randomness into account Determine probabilistic distribution of inputs Analyze the system performance Mathematical analysis Examples: Queueing theory approaches Simulation: Generate inputs that satisfy probability distributions Ex: process arrival time, CPU/IO burst distribution Simulate system action, measure figure of merit Enough inputs so that results are statistically significant Construct and evaluate an actual system This is what researchers do 6

Algorithm evaluation Examples: Performance Evaluation of Cache Replacement Policies for the SPEC CPU2000 Benchmark Suite Fairness and interactive performance of O(1) and CFS Linux kernel schedulers On the Impact of Scheduler Settings on the Performance of Multi-Threaded SIP Servers Page Placement Strategies for GPUs within Heterogeneous Memory Systems Linux Scheduler simulation 7

Segmentation Approach Memory-management scheme that supports user view of memory A program is a collection of segments A segment is a logical unit such as: main program procedure, function, method object local variables, global variables common block stack, arrays, symbol table Segment table Segment-table base register (STBR) Segment-table length register (STLR) segments vary in length, can very dynamically Segments may be paged Used for x86-32 bit Origin of term segmentation fault 8

Examples Intel IA-32 (x386-pentium) x86-64 (AMD, Intel) ARM 9

10 Logical to Physical Address Translation in IA-32

11 Intel IA-32 Paging Architecture

Intel IA-32 Page Address Extensions 32-bit address limits led Intel to create page address extension (PAE), allowing 32-bit apps access to more than 4GB of memory space Paging went to a 3-level scheme Top two bits refer to a page directory pointer table Page-directory and page-table entries moved to 64-bits in size Net effect is increasing address space to 36 bits 64GB of physical memory 12

Intel x86-64 Intel x86 architecture based on AMD 64 bit architecture 64 bits is ginormous (> 16 exabytes) In practice only implement 48 bit addressing or perhaps 52 Page sizes of 4 KB, 2 MB, 1 GB Four levels of paging hierarchy Can also use PAE so virtual addresses are 48 bits and physical addresses are 52 bits 13

Example: ARM Architecture Dominant mobile platform chip (Apple ios and Google Android devices for example) Modern, energy efficient, 32-bit CPU 4 KB and 16 KB pages 1 MB and 16 MB pages (termed sections) One-level paging for sections, twolevel for smaller pages Two levels of TLBs Outer level has two micro TLBs (one data, one instruction) Inner is single main TLB First inner is checked, on miss outers are checked, and on miss page table walk performed by CPU 32 bits outer page inner page offset 4-KB or 16-KB page 1-MB or 16-MB section 14

CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 21 VirtualMemory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 15 15

Virtual Memory: Objectives A virtual memory system Demand paging, pagereplacement algorithms, allocation of page frames to processes Threshing, the working-set model Memory-mapped files and shared memory and Kernel memory allocation 17 17

Fritz-Rudolf Güntsch Fritz-Rudolf Güntsch (1925-2012) at the Technische Universität Berlin in 1956 in his doctoral thesis, Logical Design of a Digital Computer with Multiple Asynchronous Rotating Drums and Automatic High Speed Memory Operation. First used in Atlas, Manchester, 1962 PCs: Windows 95 18

Background Code needs to be in memory to execute, but entire program rarely used Error code, unusual routines, large data structures Entire program code not needed at the same time Consider ability to execute partially-loaded program Program no longer constrained by limits of physical memory Each program uses less memory while running -> more programs run at the same time Increased CPU utilization and throughput with no increase in response time or turnaround time Less I/O needed to load or swap programs into memory -> each user program runs faster 20

Background (Cont.) Virtual memory separation of user logical memory from physical memory Virtual address space logical view of how process views memory Usually start at address 0, contiguous addresses until end of space Meanwhile, physical memory organized in page frames MMU must map logical to physical Virtual memory can be implemented via: Demand paging Demand segmentation 21

22 Virtual Memory That is Larger Than Physical Memory

Virtual-address Space: advantages Usually design logical address space for stack to start at Max logical address and grow down while heap grows up Maximizes address space use Unused address space between the two is hole No physical memory needed until heap or stack grows to a given new page Enables sparse address spaces with holes left for growth, dynamically linked libraries, etc. System libraries shared via mapping into virtual address space Shared memory by mapping pages readwrite into virtual address space Pages can be shared during fork(), speeding process creation 23

24 Shared Library Using Virtual Memory

Demand Paging Could bring entire process into memory at load time Or bring a page into memory only when it is needed: Demand paging Less I/O needed, no unnecessary I/O Less memory needed Faster response More users Similar to paging system with swapping (diagram on right) Page is needed reference to it invalid reference abort not-in-memory bring to memory Lazy swapper never swaps a page into memory unless page will be needed Swapper that deals with pages is a pager 25

Demand paging: Basic Concepts Demand paging: pager brings in only those pages into memory what are needed How to determine that set of pages? Need new MMU functionality to implement demand paging If pages needed are already memory resident No difference from non-demand-paging If page needed and not memory resident Need to detect and load the page into memory from storage Without changing program behavior Without programmer needing to change code 26

Valid-Invalid Bit With each page table entry a valid invalid bit is associated (v in-memory memory resident, i not-in-memory) Initially valid invalid bit is set to i on all entries Example of a page table snapshot: During MMU address translation, if valid invalid bit in page table entry is i page fault 27

Page Table When Some Pages Are Not in Main Memory Page 0 in Frame 4 (and disk) Page 1 in Disk 28

Page Fault If there is a reference to a page, first reference to that page will trap to operating system: Page fault Page fault 1. Operating system looks at a table to decide: Invalid reference abort Just not in memory, but in backing storage, ->2 2. Find free frame 3. Get page into frame via scheduled disk operation 4. Reset tables to indicate page now in memory Set validation bit = v 5. Restart the instruction that caused the page fault Page fault: context switch because disk access is needed 29

Questions for you What is disk space is full, physical memory is full, and the user launches a process? If physical memory (RAM) gets to be very big, do accesses to disk reduce? Is there ever a case where adding more memory does not help? 30

Technical Perspective: Multiprogramming Solving a problem gives rise to a new class of problem: Contiguous allocation. Problem: external fragmentation Non-contiguous, but entire process in memory: Problem: Memory occupied by stuff needed only occasionally. Low degree of Multiprogramming. Demand Paging: Problem: page faults How to minimize page faults? 31

32 Steps in Handling a Page Fault

Performance of Demand Paging Stages in Demand Paging (worse case) 1. Trap to the operating system 2. Save the user registers and process state 3. Determine that the interrupt was a page fault 4. Check that the page reference was legal and determine the location of the page on the disk 5. Issue a read from the disk to a free frame: 1. Wait in a queue for this device until the read request is serviced 2. Wait for the device seek and/or latency time 3. Begin the transfer of the page to a free frame 6. While waiting, allocate the CPU to some other user 7. Receive an interrupt from the disk I/O subsystem (I/O completed) 8. Save the registers and process state for the other user 9. Determine that the interrupt was from the disk 10. Correct the page table and other tables to show page is now in memory 11. Wait for the CPU to be allocated to this process again 12. Restore the user registers, process state, and new page table, and then resume the interrupted instruction 33

Performance of Demand Paging (Cont.) Three major activities Service the interrupt careful coding means just several hundred instructions needed Read the page lots of time Restart the process again just a small amount of time Page Fault Rate 0 p 1 if p = 0 no page faults if p = 1, every reference is a fault Effective Access Time (EAT) Hopefully p <<1 EAT = (1 p) x memory access time + p (page fault overhead + swap page out + swap page in ) Page swap time = seek time + latency time 34

Demand Paging Example Memory access time = 200 nanoseconds Average page-fault service time = 8 milliseconds EAT = (1 p) x 200 + p (8 milliseconds) = (1 p) x 200 + p x 8,000,000 nanosec. = 200 + p x 7,999,800 ns Linear with page fault rate If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds. This is a slowdown by a factor of 40!! If want performance degradation < 10 percent, p =? 220 > 200 + 7,999,800 x p 20 > 7,999,800 x p p <.0000025 < one page fault in every 400,000 memory accesses 35

Issues: Allocation of physical memory to I/O and programs Memory used for holding program pages I/O buffers also consume a big chunk of memory Solutions: Fixed percentage set aside for I/O buffers Processes and the I/O subsystem compete 36

Demand paging and the limits of logical memory Without demand paging All pages of process must be in physical memory Logical memory limited to size of physical memory With demand paging All pages of process need not be in physical memory Size of logical address space is no longer constrained by physical memory Example 40 pages of physical memory 6 processes each of which is 10 pages in size Each process only needs 5 pages as of now Run 6 processes with 10 pages to spare Higher degree of multiprogramming 37

Coping with over-allocation of memory Example Physical memory = 40 pages 6 processes each of which is of size 10 pages But are using 5 pages each as of now What happens if each process needs all 10 pages? 60 physical frames needed Terminate a user process But paging should be transparent to the user Swap out a process Reduces the degree of multiprogramming Page replacement: selected pages. Policy? soon 38

What Happens if there is no Free Frame? Could be all used up by process pages or kernel, I/O buffers, etc How much to allocate to each? Page replacement find some page in memory, but not really in use, page it out Algorithm terminate? swap out? replace the page? Performance want an algorithm which will result in minimum number of page faults Same page may be brought into memory several times Continued to Page replacement etc... 42

Page Replacement Prevent over-allocation of memory by modifying page-fault service routine to include page replacement Use modify (dirty) bit to reduce overhead of page transfers only modified pages are written to disk Page replacement completes separation between logical memory and physical memory large virtual memory can be provided on a smaller physical memory 43

Basic Page Replacement 1. Find the location of the desired page on disk 2. Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame - Write victim frame to disk if dirty 3. Bring the desired page into the (newly) free frame; update the page and frame tables 4. Continue the process by restarting the instruction that caused the trap Note now potentially 2 page transfers for page fault increasing EAT 45

46 Page Replacement

FAQ How does the virtual memory respond when the stack or heap grows? Or is the hole between them always there? Hole is always there in virtual memory. Frames in memory allocated as needed. How is the TLB affected when a page is moved from Memory to Disk, and is replaced by a page brought in from Disk? TLB is cache, has mechanism for removing and adding info to it. When does a TLB need to be flushed completely? Context switch Can more than one page loaded into memory when a process starts? prefetching Why are disk addresses of non-resident pages not stored in the page table? Generally contains only information used on page hits. 47

Page Replacement Algorithms Page-replacement algorithm Which frames to replace Want lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string String is just page numbers, not full addresses Repeated access to the same page does not cause a page fault Results depend on number of frames available In all our examples, we use 3 frames and the reference string of referenced page numbers is 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 48

49 Graph of Page Faults Versus The Number of Frames

FIFO page replacement algorithm: Out with the old; in with the new When a page must be replaced Replace the oldest one OS maintains list of all pages currently in memory Page at head of the list: Oldest one Page at the tail: Recent arrival During a page fault Page at the head is removed New page added to the tail 50

First-In-First-Out (FIFO) Algorithm Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 3 frames (3 pages can be in memory at a time per process) 15 page faults Sometimes a page is needed soon after replacement 7,0,1,2,0,3,0,.. 51

Belady s Anomaly Consider Page reference string 1,2,3,4,1,2,5,1,2,3,4,5 3 frames, 9 faults, 4 frames 10 faults! Adding more frames can cause more page faults! Belady s Anomaly Belady was here at CSU. Guest in my CS530! 3 frames: 9 page faults 4 frames: 10 page faults 52

FAQ Does Belady s Anomaly affect all page replacement algorithms? When Belady s Anomaly is present in an algorithm, will adding an additional frame always cause more page faults? Paging algorithms seem to assume both temporal and spatial locality how true is this? 53