Operating Systems Lecture 14 Segments Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software Engineering.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Operating Systems Lecture 10 Issues in Paging and Virtual Memory Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing.
Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
1 A Real Problem  What if you wanted to run a program that needs more memory than you have?
CS 153 Design of Operating Systems Spring 2015
CS 153 Design of Operating Systems Spring 2015
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Memory Management 2010.
Memory Management (continued) CS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Memory Management Chapter 5.
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.
Memory ManagementCS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System Concepts,
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Memory Management CSE451 Andrew Whitaker. Big Picture Up till now, we’ve focused on how multiple programs share the CPU Now: how do multiple programs.
Operating Systems Lecture 11 MIPS TLB Structure Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
CS333 Intro to Operating Systems Jonathan Walpole.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Review of Memory Management, Virtual Memory CS448.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
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.
Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.
CE Operating Systems Lecture 14 Memory management.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
1 Some Real Problem  What if a program needs more memory than the machine has? —even if individual programs fit in memory, how can we run multiple programs?
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Processes and Virtual Memory
NETW3005 Memory Management. Reading For this lecture, you should have read Chapter 8 (Sections 1-6). NETW3005 (Operating Systems) Lecture 07 – Memory.
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
Virtual Memory Pranav Shah CS147 - Sin Min Lee. Concept of Virtual Memory Purpose of Virtual Memory - to use hard disk as an extension of RAM. Personal.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
Operating Systems Lecture 9 Introduction to Paging Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Memory Management.
Non Contiguous Memory Allocation
Virtualization Virtualize hardware resources through abstraction CPU
Chapter 2 Memory and process management
Segmentation COMP 755.
Outline Paging Swapping and demand paging Virtual memory.
Chien-Chung Shen CIS/UD
Main Memory Management
Chapter 8: Main Memory.
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
CSE 451: Operating Systems Autumn 2005 Memory Management
Operating System Chapter 7. Memory Management
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Page Main Memory.
Presentation transcript:

Operating Systems Lecture 14 Segments Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software Engineering Beijing Univ. of Posts and Telcomm.

Why segments?  Programs need to share data on a controlled basis. Examples: all processes should use same compiler. Two processes may wish to share part of their data.  Program needs to treat different pieces of its memory differently. Examples: process should be able to execute its code, but not its data. Process should be able to write its data, but not its code. Process should share part of memory with other processes, but not all of memory. Some memory may need to be exported read-only, other memory exported read/write.

Segment mechanism  Mechanism to support treating different pieces of address space separately: segments.  Program's memory is structured as a set of segments. Each segment is a variable-sized chunk of memory. An address is a segment,offset pair. Each segment has protection bits that specify which kind of accesses can be performed. Typically will have something like read, write and execute bits.

Where are segments stored in physical memory?  One alternative: each segment is stored contiguously in physical memory. Each segment has a base and a bound. So, each process has a segment table giving the base, bounds and protection bits for each segment.

How does program generate an segment address?  There are several ways: Top bits of address specify segment, low bits specify offset. Instruction implicitly specifies segment. I.E. code vs. data vs. stack. Current data segment stored in a register. Store several segment ids in registers; instruction specifies which one.

What does address translation mechanism look like now?  Find base and bound for segment id.  Add base to offset.  Check that offset < bound.  Check that access permissions match actual access.  Reference the generated physical address.

How can this address translation be fast enough?  Several parts of strategy: Segment table cache stored in fast memory. Typically fully associative. Full segment table stored in physical memory. If the segment id misses in the cache, get from physical memory and reload the cache.

OS reference to any process  OS may need to reference data from any process. How is this done?  One way: OS runs with address translation turned off. Reserve certain parts of physical memory to hold OS data structures (buffers, PCB's, etc.).

How do user and OS communicate?  Via shared memory.  But, OS must manually apply translation any time user program gives it a pointer to data. Example: Exec(file) system call in nachos.

What must OS do to manage segments?  Keep copy of segment table in PCB.  When create process, allocate space for segments, fill in base and bounds registers.  When switch contexts, switch segment information state in hardware. Examples: may invalidate segment id cache.

Segment memory management  Segments come in variable sized chunks, so must allocate physical memory in variable sized chunks.  Can use a variety of heuristics: first fit, best fit, etc. All suffer from fragmentation (external fragmentation).

Segment allocation  What to do when must allocate a segment and it doesn't fit given segments that are already resident? Have several options: Can compact segments. Copy segments to contiguous physical memory locations so that small holes are collected into one big hole. Notice that this changes the physical memory locations of segment's data. What must OS do to implement new translation? Can push segments out to disk. But, must provide a mechanism to detect a reference to the swapped segment. When the reference happens, will then reload from disk.

What happens when must enlarge a segment?  What happens when must enlarge a segment? (This can happen if user needs to dynamically allocate more memory).  If lucky, there is a hole above the segment and can just increment bound for that segment.  If not, maybe can move to a larger hole where the new size fits. If not, may have to compact or swap out segments.

Segment Protection  How does one process ensure that no other process can access its memory?  Make sure OS never creates a segment table entry that points to same physical memory.

Segment sharing  How do processes share memory?  Typically at segment level.  Segment tables of the two processes point to the same physical memory.

Protection of shared segments  What about protection for a shared segment?  What if one process only wants other processes to read segment?  Typically have access bits in segment table and OS can make segment read only in one process.

Segment Naming  Processes must name segments created and manipulated by other processes.  Typically have a name space for segments; processes export segments for other processes to use under given names.  In Multics, had a tree structured segment name space, and segments were persistent across process invocations.

Segment Efficiency  It is efficient.  The segment table lookup typically does not impose too much time overhead, and segment tables tend to be small with not much memory overhead.

Segment Granularity  allows processes to specify which memory they share with other processes.  But if whole segment is either resident or not, limits the flexibility of OS memory allocation.

Advantages of segmentation  Can share data in a controlled way with appropriate protection mechanisms.  Can move segments independently.  Can put segments on disk independently.  Is a nice abstraction for sharing data. In fact, abstraction is often preserved as a software concept in systems that use other hardware mechanisms to share data.

Problems with segmentation  Fragmentation and complicated memory management.  Whole segment must be resident or not. Allocation granularity may be too large for efficient memory utilization. Example: have a big segment but only access a small part of it for a long time. Waste memory used to hold the rest.  Potentially bad address space utilization if have fixed size segment id field in addresses. If have few segments, waste bits in segment field. If have small segments, waste bits in offset field.  Must be sure to make offset field large enough. See 8086.