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

Similar documents
Last Class: Deadlocks. Where we are in the course

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

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

CS3600 SYSTEMS AND NETWORKS

Chapter 9 Memory Management

Module 8: Memory Management

Memory Management (2)

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

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

Module 8: Memory Management

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

Logical versus Physical Address Space

Introduction to Operating Systems

Memory Management. Dr. Yingwu Zhu

Main Memory (Part II)

Chapter 8: Main Memory

CS307: Operating Systems

Chapter 8: Main Memory

Goals of Memory Management

Chapter 9: Memory Management. Background

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

memory management Vaibhav Bajpai

CS399 New Beginnings. Jonathan Walpole

CS370 Operating Systems

COS 318: Operating Systems. Virtual Memory and Address Translation

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

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

Chapter 8: Memory Management Strategies

Paging & Segmentation

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

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

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

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

16 Sharing Main Memory Segmentation and Paging

Principles of Operating Systems

Chapter 8 Main Memory

Memory Management. Memory Management

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

Operating Systems, Fall

Operating Systems, Fall

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

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

Basic Memory Management

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

Chapter 8: Memory Management

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

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

CS 153 Design of Operating Systems Winter 2016

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

Compile: compiler. Load: loader. compiler linker loader memory. source object load code module module 2

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

Hardware Address Binding Memory Allocation References. Physical Memory. Daniel Bosk 1

Memory and multiprogramming

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

CSE 4/521 Introduction to Operating Systems. Lecture 14 Main Memory III (Paging, Structure of Page Table) Summer 2018

Computer Architecture. R. Poss

Memory Management. Memory

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

Chapter 8: Memory- Management Strategies

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

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

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

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

15 Sharing Main Memory Segmentation and Paging

Chapter 8 Main Memory

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

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

Virtual Memory: Mechanisms. CS439: Principles of Computer Systems February 28, 2018

Chapter 8: Memory-Management Strategies

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

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

Chapter 3 - Memory Management

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

Address Translation. Tore Larsen Material developed by: Kai Li, Princeton University

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

CS307 Operating Systems Main Memory

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

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

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

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

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

CS 3733 Operating Systems:

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

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

Chapter 8: Main Memory

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Lecture 8 Memory Management Strategies (chapter 8)

CS420: Operating Systems. Paging and Page Tables

Frequently asked questions from the previous class survey

The Virtual Memory Abstraction. Memory Management. Address spaces: Physical and Virtual. Address Translation

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

Chapter 8 Memory Management

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

EECS 470. Lecture 16 Virtual Memory. Fall 2018 Jon Beaumont

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

Main Memory CHAPTER. Exercises. 7.9 Explain the difference between internal and external fragmentation. Answer:

CS 134: Operating Systems

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

Memory Management. Dr. Yingwu Zhu

Transcription:

Last Class: Paging Process generates virtual addresses from 0 to Max. OS divides the process onto pages; manages a page table for every process; and manages the pages in memory Hardware maps from virtual addresses to physical addresses. Today: Segmentation Segments take the user's view of the program and gives it to the OS. User views the program in logical segments, e.g., code, global variables, stack, heap (dynamic data structures), not a single linear array of bytes. The compiler generates references that identify the segment and the offset in the segment, e.g., a code segment with offset = 399 Thus processes thus use virtual addresses that are segments and segment offsets. Segments make it easier for the call stack and heap to grow dynamically. Why? Segments make both sharing and protection easier. Why? Lecture 13, page 1 Lecture 13, page 2 The Translation Look-aside Buffer (TLB) Costs of Using The TLB What is the effective memory access cost if the page table is in memory? What is the effective memory access cost with a TLB? A large TLB improves hit ratio, decreases average memory cost. v: valid bit that says the entry is up-to-date Lecture 13, page 3 Lecture 13, page 4

Costs of Using The TLB Initializing Memory when Starting a Process What is the effective memory access cost if the page table is in memory? ema = 2 * ma What is the effective memory access cost with a TLB? ema = (ma + TLB) * p + (2ma + TLB) * (1-p) A large TLB improves hit ratio, decreases average memory cost. 1. Process needing k pages arrives. 2. If k page frames are free, then allocate these frames to pages. Else free frames that are no longer needed. 3. The OS puts each page in a frame and then puts the frame number in the corresponding entry in the page table. 4. OS marks all TLB entries as invalid (flushes the TLB). 5. OS starts process. 6. As process executes, OS loads TLB entries as each page is accessed, replacing an existing entry if the TLB is full. Lecture 13, page 5 Lecture 13, page 6 Saving/Restoring Memory on a Context Switch The Process Control Block (PCB) must be extended to contain: The page table Possibly a copy of the TLB On a context switch: 1. Copy the page table base register value to the PCB. 2. Copy the TLB to the PCB (optionally). 3. Flush the TLB. 4. Restore the page table base register. 5. Restore the TLB if it was saved. Multilevel Paging: If the virtual address space is huge, page tables get too big, and many systems use a multilevel paging scheme (refer OSC for details) Sharing Paging allows sharing of memory across processes, since memory used by a process no longer needs to be contiguous. Shared code must be reentrant, that means the processes that are using it cannot change it (e.g., no data in reentrant code). Sharing of pages is similar to the way threads share text and memory with each other. A shared page may exist in different parts of the virtual address space of each process, but the virtual addresses map to the same physical address. The user program (e.g., emacs) marks text segment of a program as reentrant with a system call. The OS keeps track of available reentrant code in memory and reuses them if a new process requests the same program. Can greatly reduce overall memory requirements for commonly used applications. Lecture 13, page 7 Lecture 13, page 8

Implementing Segmentation Segment table: each entry contains a base address in memory, length of segment, and protection information (can this segment be shared, read, modified, etc.). Hardware support: multiple base/limit registers. Implementing Segmentation Compiler needs to generate virtual addresses whose upper order bits are a segment number. Segmentation can be combined with a dynamic or static relocation system, Each segment is allocated a contiguous piece of physical memory. External fragmentation can be a problem again Similar memory mapping algorithm as paging. We need something like the TLB if programs can have lots of segments Let's combine the ease of sharing we get from segments with efficient memory utilization we get from pages. Lecture 13, page 9 Lecture 13, page 10 Combining Segments and Paging Combining Segments and Paging Treat virtual address space as a collection of segments (logical units) of arbitrary sizes. Treat physical memory as a sequence of fixed size page frames. Segments are typically larger than page frames, Map a logical segment onto multiple page frames by paging the segments Lecture 13, page 11 Lecture 13, page 12

Addresses in Segmented Paging Addresses in Segmented Paging A virtual address becomes a segment number, a page within that segment, and an offset within the page. The segment number indexes into the segment table which yields the base address of the page table for that segment. Check the remainder of the address (page number and offset) against the limit of the segment. Use the page number to index the page table. The entry is the frame. (The rest of this is just like paging.) Add the frame and the offset to get the physical address. Lecture 13, page 13 Lecture 13, page 14 Addresses in Segmented Paging: Example Given a memory size of 256 addressable words, a page table indexing 8 pages, a page size of 32 words, and 8 logical segments How many bits is a physical address? How many bits is a virtual address? How many bits for the seg #, page #, offset? How many segment table entries do we need? How many page table entries do we need? Sharing Pages and Segments Share individual pages by copying page table entries. Share whole segments by sharing segment table entries, which is the same as sharing the page table for that segment. Need protection bits to specify and enforce read/write permission. When would segments containing code be shared? When would segments containing data be shared? Lecture 13, page 15 Lecture 13, page 16

Sharing Pages and Segments: Implementation Issues Where are the segment table and page tables stored? Store segment tables in a small number of associative registers; page tables are in main memory with a TLB (faster but limits the number of segments a program can have) Both the segment tables and page tables can be in main memory with the segment index and page index combined used in the TLB lookup (slower but no restrictions on the number of segments per program) Protection and valid bits can go either on the segment or the page table entries Note: Just like recursion, we can do multiple levels of paging and segmentation when the tables get too big. Segmented Paging: Costs and Benefits Benefits: faster process start times, faster process growth, memory sharing between processes. Costs: somewhat slower context switches, slower address translation. Pure paging system => (virtual address space)/(page size) entries in page table. How many entries in a segmented paging system? What is the performance of address translation of segmented paging compared to contiguous allocation with relocation? Compared to pure paging? How does fragmentation of segmented paging compare with contiguous allocation? With pure paging? Lecture 13, page 17 Lecture 13, page 18 Inverted Page Tables Techniques to scale to very large address spaces Multi-level page tables Inverted index Page table is a hash table with key-value lookups Key=page number, value = frame number Page table lookups are slow Use TLBs for efficiency Putting it all together Relocation using Base and Limit registers simple, but inflexible Segmentation: compiler's view presented to OS segment tables tend to be small memory allocation is expensive and complicated (first fit, worst fit, best fit). compaction is needed to resolve external fragmentation. Lecture 13, page 19 Lecture 13, page 20

Putting it all together Paging: simplifies memory allocation since any page can be allocated to any frame page tables can be very large (especially when virtual address space is large and pages are small) Segmentation & Paging only need to allocate as many page table entries as we need (large virtual address spaces are not a problem). easy memory allocation, any frame can be used sharing at either the page or segment level increased internal fragmentation over paging two lookups per memory reference Lecture 13, page 21