Introduction to Operating Systems

Similar documents
Page 1. Goals for Today" Virtualizing Resources" Important Aspects of Memory Multiplexing" CS162 Operating Systems and Systems Programming Lecture 20

Goals of Memory Management

Page 1. Goals for Today" Important Aspects of Memory Multiplexing" Virtualizing Resources" CS162 Operating Systems and Systems Programming Lecture 9

Principles of Operating Systems

Midterm 1. Administrivia. Virtualizing Resources. CS162 Operating Systems and Systems Programming Lecture 12. Address Translation

CS162 Operating Systems and Systems Programming Lecture 12. Address Translation. Page 1

Memory Management. Memory

CS307 Operating Systems Main Memory

Memory Management. Memory Management

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

8.1 Background. Part Four - Memory Management. Chapter 8: Memory-Management Management Strategies. Chapter 8: Memory Management

Chapter 9: Memory Management. Background

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

Chapter 8: Main Memory

Part Three - Memory Management. Chapter 8: Memory-Management Strategies

Chapter 8: Main Memory

Chapter 8: Memory-Management Strategies

I.-C. Lin, Assistant Professor. Textbook: Operating System Principles 7ed CHAPTER 8: MEMORY

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

CS307: Operating Systems

Module 8: Memory Management

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

Chapter 8: Memory Management Strategies

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 8: MEMORY

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

Chapter 8: Memory- Management Strategies

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

Module 8: Memory Management

memory management Vaibhav Bajpai

Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation

Chapter 8: Memory Management

Memory Management. Contents: Memory Management. How to generate code? Background

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

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

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

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Chapter 8 Main Memory

Chapter 8: Main Memory

Main Memory. CISC3595, Spring 2015 X. Zhang Fordham University

Chapter 8: Main Memory

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

CSE 421/521 - Operating Systems Fall Lecture - XII Main Memory Management. Tevfik Koşar. University at Buffalo. October 18 th, 2012.

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

Roadmap. Tevfik Koşar. CSC Operating Systems Spring Lecture - XII Main Memory - II. Louisiana State University

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Logical versus Physical Address Space

Chapter 8: Memory- Manage g me m nt n S tra r t a e t gie i s

CS 3733 Operating Systems:

Lecture 8 Memory Management Strategies (chapter 8)

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

The Memory Management Unit. Operating Systems. Autumn CS4023

CS3600 SYSTEMS AND NETWORKS

Background. Contiguous Memory Allocation

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

Main Memory Yi Shi Fall 2017 Xi an Jiaotong University

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

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

CS399 New Beginnings. Jonathan Walpole

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

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

Memory Management. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Memory Management Minsoo Ryu Real-Time Computing and Communications Lab. Hanyang University

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

Chapter 8 Memory Management

Frequently asked questions from the previous class survey

Chapter 9 Memory Management

SHANDONG UNIVERSITY 1

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

CS420: Operating Systems

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

CS162 Operating Systems and Systems Programming Lecture 12. Protection (continued) Address Translation

CS370 Operating Systems

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

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

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

Main Memory. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & APPS 1

P r a t t hr h ee e : e M e M m e o m r o y y M a M n a a n g a e g m e e m n e t 8.1/72

Memory Management (1) Memory Management

Memory Management (1) Memory Management. CPU vs. memory. No.8. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

COSC Operating Systems Design, Fall 2001, Byunggu Yu. Chapter 9 Memory Management (Lecture Note #8) 1. Background

Basic Memory Management

Today: Segmentation. Last Class: Paging. Costs of Using The TLB. The Translation Look-aside Buffer (TLB)

Last Class: Deadlocks. Where we are in the course

Main Memory (Part I)

16 Sharing Main Memory Segmentation and Paging

Paging! 2/22! Anthony D. Joseph and Ion Stoica CS162 UCB Fall 2012! " (0xE0)" " " " (0x70)" " (0x50)"

Main Memory (Part II)

CS370 Operating Systems

Memory: Overview. CS439: Principles of Computer Systems February 26, 2018

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

CS162 Operating Systems and Systems Programming Lecture 12. Protection (continued) Address Translation

15 Sharing Main Memory Segmentation and Paging

Chapters 9 & 10: Memory Management and Virtual Memory

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

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

VII. Memory Management

Memory Management and Protection

Transcription:

Introduction to Operating Systems Lecture 6: Memory Management MING GAO SE@ecnu (for course related communications) mgao@sei.ecnu.edu.cn Apr. 22, 2015

Outline 1 Issues of main memory 2 Main memory management for uniprogramming 3 Main memory management for multiprogramming Segmentation and its implementation Paging and its implementation MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 2 / 36

issues Process and thread revision Threads encapsulate concurrency Active component of a process Address spaces encapsulate protection Keeps buggy program from trashing the system Passive component of a process MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 3 / 36

issues Issues of main memory Controlled overlap Separate state of threads should not collide in physical memory. Conversely, would like the ability to overlap when desired (for comm.) Translation Ability to translate accesses from virtual address space to the physical one Protection Can be used to avoid overlap Can be used to give uniform view of memory to programs Prevent access to private memory of other processes Different pages of memory can be given special behavior (Read Only, Invisible to user programs, etc). Kernel data protected from user programs Programs protected from themselves MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 4 / 36

issues From source code to a process MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 5 / 36

uniprogramming Uniprogramming Apply to single-user and single-task OS only Require system and user partitions only System partition can be protected by limit address MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 6 / 36

Naive multiprogramming No translation and protection Use Loader/Linker: Adjust addresses while program loaded into memory Everything adjusted to memory location of program Translation done by a linker-loader Was pretty common in early days MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 7 / 36

Protection A pair of base and limit registers define the logical address space CPU must check every memory access generated in user mode to be sure it is between base and limit for that program MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 8 / 36

Protected multiprogramming w/o. translation Use two special registers: base and limit If user tries to access illegal address, cause an error Context switch kernel loads new base/limit from PCB users are not allowed to change base/limit registers MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 9 / 36

Outline multiprogramming segmentation 1 Issues of main memory 2 Main memory management for uniprogramming 3 Main memory management for multiprogramming Segmentation and its implementation Paging and its implementation MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 10 / 36

segmentation Segmentation: Multiprog. w/ translation Dynamic address translation using base/limit User may have multiple segments available (e.g x86) Loads and stores include segment ID in opcode: Operating system moves around segment base pointers as necessary MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 11 / 36

segmentation Logical view of segmentation Logical address consists of a two-tuple: < segmentid, offset > Segment table maps two-dimensional physical addresses: base and limit Segment-table base register (STBR) points to the segment table s location in memory Segment-table length register (STLR) indicates number of segments used by a program MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 12 / 36

segmentation Implementation of segmentation Segments Every segment of physical memory may not be equivalent Memory allocation is a dynamic storage-allocation problem Segment table Resides in physical memory Contains physical addresses and permission for each virtual segment permission include: Valid bits, Read, Write, etc. MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 13 / 36

segmentation Issues of simple segmentation Fragmentation problem Not every process is the same size Over time, memory space becomes fragmented Hard to do inter-process sharing Want to share code segments when possible Want to share memory between processes Helped by providing multiple segments per process Need enough physical memory for every process MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 14 / 36

Contiguous allocation multiprogramming segmentation Hole Block of available memory; holes of various size are scattered throughout memory When a process arrives, it is allocated memory from a hole large enough to accommodate it Operating system maintains information about: allocated partitions free partitions (hole) MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 15 / 36

segmentation Dynamic storage allocation First-fit Allocate the first hole that is big enough Best-fit Allocate the smallest hole that is big enough; must search entire list, unless ordered by size Produces the smallest leftover hole Worst-fit Allocate the largest hole; must also search entire list Produces the largest leftover hole MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 16 / 36

segmentation Fragmentation External Fragmentation total memory space exists to satisfy a request, but it is not contiguous Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used Compaction Shuffle memory contents to place all free memory together in one large block? Relocation must be dynamic, and is done at execution time I/O problem MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 17 / 36

segmentation More on segmentation implementation Logical View multiple separate segments Typical: Code, Data, Stack Others: memory sharing, etc Each segment is given region of contiguous memory Has a base and limit Can reside anywhere in physical memory How to support heap and stack to grow independently? How to do inter-process sharing? How to implement multiple segments? segment table? MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 18 / 36

segmentation Swapping Extreme form of Context Switch: Swapping In order to make room for next process, some or all of the previous process is moved to disk Likely need to send out complete segments This greatly increases the cost of context-switching Desirable alternative? Some way to keep only active portions of a process in memory at any one time Need finer granularity control over physical memory MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 19 / 36

Outline multiprogramming paging 1 Issues of main memory 2 Main memory management for uniprogramming 3 Main memory management for multiprogramming Segmentation and its implementation Paging and its implementation MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 20 / 36

paging Paging: Multiprogramming w/ translation Aims Isolate processes and kernel from one another Allow flexible translation that: Doesn t lead to external fragmentation Allows easy sharing between processes Allows only part of process to be resident in physical memory MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 21 / 36

paging Memory management unit (MMU) Hardware device that maps virtual to physical address In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory The user program deals with logical addresses; it never sees the real physical addresses MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 22 / 36

paging Implementation of paging Every chunk of physical memory is equivalent (1K - 16K) Page table (one per process) Resides in physical memory Contains physical page and permission for each virtual page Permissions include: Valid bits, Read, Write, etc Internal fragmentation Page size = 2,048 bytes, process size = 7,766 bytes How to compute the internal fragmentation So small frame sizes desirable? MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 23 / 36

paging Implementation of paging cont d Virtual address consists of page number and page offset How to map virtual address 7,098 to physical address when page size=1k. MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 24 / 36

Sharing in paging? multiprogramming paging Two entries from different page-table (of two different processes) point to the same shared page MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 25 / 36

paging Discussion on simple paging Pros Simple memory allocation Easy to Share Cons What if address space is sparse? E.g. on UNIX, code starts at 0, stack starts at (2 31 1). With 1K pages, need 2 million page table entries! What if table really big? Not all pages used all the time would be nice to have working set of page table in memory MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 26 / 36

paging Multi-level translation: Segmentation with paging A tree of tables Lowest level page table: memory still allocated with bitmap Higher levels often segmented MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 27 / 36

paging Multi-level translation: Multi-level page table A tree of page tables Tables fixed size (1024 entries) Valid bits on Page Table Entries Don t need every 2nd-level table Even when exist, 2nd-level tables can reside on disk if not in use MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 28 / 36

paging Multi-level translation analysis Pros Only need to allocate as many page table entries as we need for application sparse address spaces are easy Easy memory allocation Easy Sharing Share at segment or page level (need additional reference counting) Cons One pointer per page (typically 4K - 16K pages today) Page tables need to be contiguous However, previous example keeps tables to exactly one page in size Two (or more, if > 2 levels) lookups per reference Seems very expensive! MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 29 / 36

paging More on page-table implementation The problem of forward page tables Size of page table is at least as large as amount of virtual memory allocated to processes Physical memory may be much less Much of process space may be out on disk or not in use Inverted page table Search is expensive Only one page table for the whole system MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 30 / 36

paging More on page-table implementation Hashed page table Size is independent of virtual address space Directly related to amount of physical memory Very attractive option for 64-bit address spaces Complexity of managing hash changes Often in hardware! MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 31 / 36

paging More on paging: TLB Too expensive to translate on every access At least two DRAM accesses per actual DRAM access Or: perhaps I/O if page table partially on disk! Associative memory parallel search of (p, d) If p is in associative register, get frame # out Otherwise get frame # from page table in memory MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 32 / 36

paging TLB: Effective access time (EAT) Associative lookup ɛ (time unit) Hit ratio α (percentage of a page number if found in the associative registers) Memory cycle time 1 (time unit) EAT = (1 + ɛ) α + (2 + ɛ) (1 α) = 2 + ɛ α (time unit) MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 33 / 36

Take-aways Take-aways Observing main memory management from different point-of-views Translation Multiprogramming Protection Sharing Caching MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 34 / 36

Take-aways Terms and their Chinese translations MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 35 / 36

Take-aways Acknowledgement Many slides are copied or adapted from: Slides provided by authors of the textbook (http://codex.cs.yale.edu/avi/os-book/os7/) Prof. Anthony D. Joseph s slides for course CS162 (2006) at EECS@UCBerkeley (http://inst.eecs.berkeley.edu/~cs162) (Copyright @ 2008 UCB) MING GAO (SE@ecnu) Introduction to Operating Systems Apr. 22, 2015 36 / 36