1 Outline Basic memory management Swapping Virtual memory Page replacement algorithms Modeling page replacement algorithms Design issues for paging systems.

Slides:



Advertisements
Similar presentations
I/O Management and Disk Scheduling
Advertisements

Part IV: Memory Management
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
EEE 435 Principles of Operating Systems Principles and Structure of I/O Software (Modern Operating Systems 5.2 & 5.3) 5/22/20151Dr Alain Beaulieu.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Paging Design Input-Output.
Memory Design Example. Selecting Memory Chip Selecting SRAM Memory Chip.
Operating System Support Focus on Architecture
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
1 I/O Devices Controller: physically controls the devices Devices are diverse and complicated Present simpler interface to OS E.g, convert a linear sector.
Memory Management Chapter 5.
Device Management.
Computer Organization and Architecture
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output – 3 I/O Software CS 342 – Operating Systems Ibrahim Korpeoglu.
1 Input/Output Chapter 3 TOPICS Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks Reference: Operating Systems Design.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Computer Organization and Architecture Operating System Support Chapter 8.
1 Input/Output. 2 Principles of I/O Hardware Some typical device, network, and data base rates.
1 I/O and Filesystems. 2 How to provide interfaces Rough reading guide (no exam guarantee): Tanenbaum Ch. 5.1 – 5.5 & Silberschatz Ch. 13 & ,
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
1 I/O Management and Disk Scheduling Chapter Categories of I/O Devices Human readable Used to communicate with the user Printers Video display terminals.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-1: I/O Management Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Chapter 5 Input/Output. 2 Introduction I/O: main function of OS –Drive devices, catch interrupts, handle errors –Provide a device independent interface.
Segmentation & O/S Input/Output Chapter 4 & 5 Tuesday, April 3, 2007.
CSC 322 Operating Systems Concepts Lecture - 25: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
I/O Systems I/O Hardware Application I/O Interface
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS6: Device Management 6.1. Principles of I/O.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Chapter 5 Input/Output 5.1 Principles of I/O hardware
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
I/O Software CS 537 – Introduction to Operating Systems.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Computer Architecture Chapter (8): Operating System Support
1 Chapter 11 I/O Management and Disk Scheduling Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and.
Memory Management Chapter 3
I/O Management.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Module 12: I/O Systems I/O hardware Application I/O Interface
Session 3 Memory Management
Chapter 9: Virtual Memory
Chapter 8: Main Memory.
Chapter 9: Virtual-Memory Management
Operating Systems Chapter 5: Input/Output Management
CS703 - Advanced Operating Systems
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Chapter 5: I/O Systems.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Presentation transcript:

1 Outline Basic memory management Swapping Virtual memory Page replacement algorithms Modeling page replacement algorithms Design issues for paging systems Implementation issues Segmentation

2 When OS Involves Paging? Process creation Process execution Page faults Process termination

3 Paging in Process Creation Determine (initial) size of program and data Assign appropriate page frames Create page table Process is running  page table in memory Create swap area For the pages swapped out Record info about page table and swap area in process table

4 Paging During Process Running When a process is scheduled for execution Reset MMU Flush TLB (translation Lookaside Buffer) Copy or point to new process’ page table Bring some or all of new process’ pages into memory Reduce the number of page faults

5 Paging When Page Faults Read registers to identify virtual address causing the page fault Locate the page needed on disk Find available page frame Evict an old page if necessary Read in the page Execute the faulting instruction again

6 Paging When Process Exits Release page table Release pages and swap area on disk If some pages are shared by other processes, keep them.

7 Swap Area Swap area: reserved for processes’ pages A chunk of pages reserved on disk, same size of # of pages of the process Each process has its own swap area, recorded in process table Initialize swap area before a process runs Copy entire process image, or Load the process in memory and let it be paged out as needed

8 Swap Area for Growing Processes Process may grow after starting Data area and stack may grow Reserve separate swap areas for text (program), data, and stack Reserve nothing in advance Allocate disk space when pages swapped out De-allocate when page swapped in again Have to keep track of pages on disk A disk address per page, costly!

9 Comparison of Two Methods Paging to a static swap areaBacking up pages dynamically

10 Outline Basic memory management Swapping Virtual memory Page replacement algorithms Modeling page replacement algorithms Design issues for paging systems Implementation issues Segmentation

11 A Motivating Example Many tables when compiling a program Symbol table: names and attributes of variables Constant table: integer/floating-point constants Parse tree: syntactic analysis Stack: for procedure calls within the compiler Each table needs contiguous chunks of virtual address space. But tables grow/shrink as compilation proceeds. How to manage space for these tables?

12 With One-Dimensional Address Take space from tables with an excess of room Tedious work Free programmers from managing expanding and contracting tables Segments: many completely independent address spaces Call stack Parse tree Constant table Source text Symbol table Virtual address space

13 Segments Segment: a two dimensional memory Each segment has a linear sequence of address (0 to some maximum) Different segments may have different lengths Segment lengths may change during execution Different segments can grow/shrink independently Address: segment number + address within the segment (offset)

14 Multiple Segments in A Process Segments are logical entities Programmers are aware of them. A segment may contain a procedure, or an array, but not a mixture of different types. Facilitate separate protection. Source text Constants Parse tree Call stack Symbol table

15 Paging Vs. Segmentation ConsiderationPagingSegmentation Aware by programmers?NOYes # of linear address spaces1Many Total address space > physical memory? Yes Distinguish and separately protect procedures and data? NoYes Accommodate fluctuating tables? NoYes Facilitate sharing among procedures? NoYes Why is this technique for? Get larger linear space than that of physical memory 1. Break programs/data into logically independent address space 2. Aid sharing and protection

16 Implementing Pure Segmentation External fragmentation Time 

17 Segmentation With Paging: MULTICS For large segments, only the “working set” should be kept in memory Paging segments: segment has own page table Each program has a segment table One entry (descriptor) per segment Segment table is itself a segment If (part of) a segment is in memory, its page table must be in memory Address: segment # + virtual page # + offset Segment #  page table Page table + virtual page #  page frame address Page frame address + offset  physical address

18 The MULTICS virtual memory …… Segment 2 descriptor Segment 1 descriptor Segment 0 descriptor …… Page 2 entry Page 1 entry Page 0 entry Page table for segment 2 …… Page 2 entry Page 1 entry Page 0 entry Page table for segment 0 Page frame Segment table Segment descriptor contains the memory address of the page table. #segment#pageoffset Virtual Address Page frame

19 Summary Fixed partitions Multiple queues Vs. single queue Degree of multiprogramming Relocation and protection Swapping Virtual memory Vs. physical memory Bitmap and linked list Holes

20 Summary (Cont.) Virtual memory Pages Vs. page frames Page tables Page replacement algorithms (aging and WSClock) Modeling paging systems Stack algorithms Predict page faults using distance string

21 Summary (Cont.) Design issues Local Vs. global allocations Load control to reduce thrashing Shared pages Implementation issues Page fault handling and swap area Segmentation Each segment has its own address space Advantages Pure segmentation and segmentation with paging

CMPT 300: Operating System Chapter 5 Input/Output

23 Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks

24 Block and Character Devices Block devices: store info in fixed-size blocks Examples: disks Each block has its own address Each block can be read/written independently Data are read/write in the units of block Character devices: no block structure, deliver/accept a stream of characters Examples: keyboard, printers, network, mice Not addressable, no seek operation Devices not in the classification: clock

25 Huge Range in Speeds Many orders of magnitude in data rates Keyboard: 10 bytes/sec Mouse: 100 bytes/sec Laser printer: 100Kb/sec IDE disk: 5Mb/sec PCI bus: 528Mb/sec Challenge: how to design a general structure to control various I/O devices? Multi-bus system

26 Structure of I/O Units A mechanical component: the device itself Disk: plates, heads, motors, arm, etc. Monitor: tube, screen, etc. An electronic component: device controller, adaptor Disk: issuing commands to mechanical components, assembling, checking and transferring data Monitor: read characters to be displayed and generate electrical signals to modulate the CRT beam

27 Mechanical / Electronic Components Bus CPUMemory Video controller Keyboard controller Floppy disk controller Hard disk controller Monitor Keyboard Floppy disk Hard disk Mechanical components Electronic components

28 Device Controller Registers in I/O controllers CPU writes commands into registers CPU reads states of devices from registers Data buffer for transferring data How CPU distinguishes different registers and data buffers? I/O port number Memory-mapped I/O

29 I/O Port Number Each control register is assigned a unique I/O port number (8- /16-bit integer) Instruction IN and OUT IN REG, PORT OUT PORT, REG Separated address spaces IN R0, 4 and MOV R0, 4 are completely different. 0xFFFF… 0 Memory I/O ports

30 Memory-Mapped I/O Map all control registers into memory space Usually at the top of the address space Each register is assigned a unique memory address, e.g., 0xFF10 Hybrid scheme (used in Pentium) 0xFFFF… 0 0 Memory I/O ports Memory- mapped Hybrid I/O buffered data

31 Pros & Cons of Memory-Mapped I/O Advantages Easier for programming Easier to protect and share I/O devices Save time of accessing control registers Disadvantages Caching a control register is disastrous Disable caching for selected pages I/O devices cannot see the memory addresses with separate buses for memory and I/O devices (see next slide)

CPU Main Memory I/O CPU Main Memory I/O All addresses go here CPU reads/writes of memory go over this high-bandwidth bus Single-bus Dual-bus

33 Interrupts CPU Bus Interrupt controller Disk 1. Device finishes a work Keyboard Clock Printer 2. Controller issues interrupt 3. CPU acks interrupt

34 Interrupt Processing I/O devices raise interrupt by asserting a signal on a bus line assigned Multiple interrupts  the one with high priority goes first Interrupt controller interrupts CPU Put device # on address lines Device #  check interrupt vector table for interrupt handler (a program) Enable interrupts shortly after the handler starts

35 Direct Memory Access (DMA) Request data from I/O without DMA Device controller reads data from device It interrupts CPU when a byte/block of data available CPU reads controller’s buffer into main memory Too many interruptions, expensive DMA: direct memory access A DMA controller with registers read/written by CPU CPU programs the DMA: what to transfer where Source, destination and size DMA interrupts CPU only after all the data are transferred.

Operations of DMA CPU DMA controller Disk controller Main memory Bus Address Count Control Drive 1. CPU programs the DMA and controller Buffer 2. DMA requires transfer to memory 3. Data transferred 4. Ack Interrupt when done

37 Transfer Modes Word-at-a-time (cycle stealing) DMA controller acquires the bus, transfer one word, and releases the bus CPU waits for bus if data is transferring Cycle stealing: steal an occasional bus cycle from CPU once in a while Burst mode DMA holds the bus until a series of transfers complete More efficient since acquiring bus takes time Block the CPU from using bus for a substantial time

38 Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks

39 Issues of The I/O Software Device independence Uniform naming Error handling Buffering Others

40 How to Perform I/O? Programmed I/O (Polling/Busy Waiting) Acquire I/O device (e.g., printer) Blocked if it is being used by another process Copy the buffer from use space to kernel space Step 1: keep checking the state until it is ready. Step 2: send one character to printer. Go to Step 1. Release the I/O. The CPU do all the work Simple Waste a lot of CPU time on busy waiting

41 An Example copy_from_user(buffer, p, count); for (i=0; i<count; i++){ while (*printer_status_reg!=READY); *printer_data_register=p[i]; } return_to_user(); // p is the kernel buffer // loop on every character // loop until ready // output one character Q: Why does OS copy the buffer from user space to kernel space?

42 Interrupt-Driven I/O Print system call copy_from_user(buffer, p, count); enable_interrupts(); while (*printer_status_reg!=READY); *printer_data_register=p[0]; scheduler(); Interrupt service procedure if (count==0){ unblock_user(); } else { *printer_data_register=p[I]; count--; i++; } acknowledge_interrupt(); return_from_interrupt(); Interrupt occurs on every character!

43 I/O Using DMA Too many interrupts in interrupt-driven I/O DMA reduces # of interrupts from 1/char to 1/buffer printed Print system call copy_from_user(buffer, p, count); set_up_DMA_controller(); scheduler(); Interrupt service procedure acknowledge_interrupt(); unblock_user(); return_from_interrupt();

44 Outline Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks

45 Layers Overview User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

46 Interrupt Handlers Hide I/O interrupts deep in OS Device driver starts I/O and blocks (e.g., down a mutex) Interrupt wakes up driver Process an interrupt Save registers ( which to where?) Set up context (TLB, MMU, page table) Run the handler (usually the handler will be blocked) Choose a process to run next Load the context for the newly selected process Run the process Take considerable number of CPU instructions

47 Device Drivers Device-specific code for controlling I/O devices Written by manufacture, delivered along with device One driver for one (class) device(s) Position: part of OS kernel, below the rest of OS Interfaces for rest of OS Block device and character device have different interfaces

48 Logical Position of Device Drivers User program Rest of the OS Printer driver Printer controller printer User space Kernel space Hardware Devices

49 How to Install a Driver? Re-compile and re-link the kernel Drivers and OS are in a single binary program UNIX systems Often run by computer centers, devices rarely change Dynamically loaded during OS initialization Windows system Devices often change Difficult to obtain source code Users don’t know how to compile OS

50 Functions of Device Drivers Accept abstract read/write requests Error checking, parameter converting Check status, initialize device, if necessary Issue a sequence of commands May block and wait for interrupt Check error, return data Other issues: re-entrant, up-call, etc.

51 Device-Independent I/O Software Why device- independent I/O software? Perform I/O functions common to all devices Provide a uniform interface to user- level software Functions in device- independent software Uniform interfacing for devices drivers Buffering Error reporting Allocating and releasing dedicated devices Providing a device- independent block size User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

52 Uniform Interfacing for Device Drivers New device  modify OS, no good Provide the same interface for all drivers Easy to plug a new driver In reality, not absolutely identical, but most functions are common Name I/O devices in a uniform way Mapping symbolic device names onto the proper driver Treat device name as file name in UNIX E.g., hard disk /dev/disk0 is a special file. Its i-node contains the major device number, which is used to locate the appropriate driver, and minor device number.

53 Buffering for Input Motivation: consider a process that wants to read data from a modem User process handles one character at a time. It blocks if a character is not available Each arriving character causes an interrupt User process is unblocked and reads the character. Try to read another character and block again. Many short runs in a process: inefficient! Overhead of context switching

54 Buffering in User Space User space Kernel space Buffering in user space Set a buffer in user process’ space User process is waked up only if the buffer is filled up by interrupt service procedure. More efficient. Can the buffer be paged out? Yes: where to put the next character? No: the pool of available pages shrink

55 Buffering in Kernel Two buffers: one in kernel and one in user Interrupt handler puts characters into the buffer in kernel space This buffer is locked When full, copy the kernel buffer to user buffer Bring in the user buffer if necessary Where to store the new arrived characters during page loading? User space Kernel space Buffering in kernel

56 Double Buffering in Kernel Two kernel buffers When the first one fills up, but before it has been emptied, the second one is used. Buffers are used in turn: while one is being copied to user space, the other is accumulating new input User space Kernel space Double buffering

57 Downside of Data Buffering Many sequential buffering slow down transmission Process A 1 2 Network controller Network User space Kernel space Process B What’s it for?

58 Handling I/O Errors Programming errors: ask for something impossible E.g. writing a keyboard, reading a printer Invalid parameters, like buffer address Report an error code to caller Actual I/O error E.g. write a damaged disk block Handled by device driver and/or device-independent software System error E.g. root directory or free block list is destroyed display message, terminate system

59 Allocating Dedicated Devices Before using a device, make the system call open When the device is unavailable The call fails, or The caller is blocked and put on a queue Release the device by making the close system call

60 User-Space I/O Software Libraries: interface between user programs and system calls E.g., write(fd, buffer, nbytes), printf/scanf Spooling User-level, controlled by a daemon Eliminated unnecessarily waiting/deadlock User-level I/O software Device-independent I/O software Device drivers Interrupt handlers Hardware

61 Summary: I/O Software User-level I/O software Make I/O call; format I/O; spooling Device-independent OS software Naming, protection, blocking, buffering, allocation Device drivers Setup device registers; check status Interrupt handlers Wake up driver when I/O completed Hardware Perform I/O operation I/O request I/O reply