Chapter 7 Memory Management

Similar documents
Memory Management. Memory Management

Memory Management. Memory Management Requirements

Lecture 7. Memory Management

Memory Management. Memory Management

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

Memory Management william stallings, maurizio pizzonia - sistemi operativi

Operating Systems: Internals and Design Principles. Chapter 7 Memory Management Seventh Edition William Stallings

MEMORY MANAGEMENT/1 CS 409, FALL 2013

General Objective:To understand the basic memory management of operating system. Specific Objectives: At the end of the unit you should be able to:

Requirements, Partitioning, paging, and segmentation

Paging, and segmentation

3. Memory Management

Memory Management. Jo, Heeseung

MEMORY MANAGEMENT. Jo, Heeseung

Requirements, Partitioning, paging, and segmentation

CIS Operating Systems Contiguous Memory Allocation. Professor Qiang Zeng Spring 2018

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

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

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

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

Process. Memory Management

UNIT III MEMORY MANAGEMENT

Process. One or more threads of execution Resources required for execution

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

Background. Contiguous Memory Allocation

CS370 Operating Systems

CIS Operating Systems Memory Management. Professor Qiang Zeng Fall 2017

Main Memory (Part I)

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

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

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

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

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

Objectives and Functions Convenience. William Stallings Computer Organization and Architecture 7 th Edition. Efficiency

Operating Systems Memory Management. Mathieu Delalandre University of Tours, Tours city, France

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

Operating systems. Part 1. Module 11 Main memory introduction. Tami Sorgente 1

Chapter 9 Real Memory Organization and Management

Chapter 9 Real Memory Organization and Management

6. Which of the following operating systems was the predecessor of Microsoft MS-DOS? a. Dynix b. Minix c. CP/M

Chapters 9 & 10: Memory Management and Virtual Memory

Memory management. Knut Omang Ifi/Oracle 10 Oct, 2012

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

CSCI 4500 / 8506 Sample Questions for Quiz 5

CS399 New Beginnings. Jonathan Walpole

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

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

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

Operating Systems Unit 6. Memory Management

Chapter 8 Virtual Memory

Chapter 8: Memory Management

12: Memory Management

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

The Memory Management Unit. Operating Systems. Autumn CS4023


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

CS418 Operating Systems

Goals of Memory Management

Chapter 8. Operating System Support. Yonsei University

Operating System Support

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

CS420: Operating Systems

Chapter 9: Memory Management. Background

Memory Management. Goals of Memory Management. Mechanism. Policies

Administrivia. Deadlock Prevention Techniques. Handling Deadlock. Deadlock Avoidance

Operating Systems 2230

Module 8: Memory Management

Chapter 8: Main Memory

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

Part II: Memory Management. Chapter 7: Physical Memory Chapter 8: Virtual Memory Chapter 9: Sharing Data and Code in Main Memory

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

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

Chapter 8: Main Memory

Memory Management (Chaper 4, Tanenbaum)

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

Chapter 8: Main Memory

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

Preview. Memory Management

Memory Management. CSE 2431: Introduction to Operating Systems Reading: , [OSC]

Operating Systems Lecture 6: Memory Management II

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

Chapter 8: Memory-Management Strategies

Chapter 9 Memory Management

Operating Systems (2INC0) 2017/18

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

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

Last class: Today: Deadlocks. Memory Management

Memory Management Virtual Memory

Module 8: Memory Management

CS Operating Systems

CS Operating Systems

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Memory Management. Memory Management

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

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

Logical versus Physical Address Space

Chapter 8: Main Memory

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

Chapter 8: Memory- Management Strategies

Transcription:

Operating Systems: Internals and Design Principles Chapter 7 Memory Management Ninth Edition William Stallings

Frame Page Segment A fixed-length block of main memory. A fixed-length block of data that resides in secondary memory (such as disk). A page of data may temporarily be copied into a frame of main memory. A variable-length block of data that resides in secondary memory. An entire segment may temporarily be copied into an available region of main memory (segmentation) or the segment may be divided into pages which can be individually copied into main memory (combined segmentation and paging). Table 7.1 Memory Management Terms

Memory Management Requirements Memory management is intended to satisfy the following requirements: Relocation Protection Sharing Logical organization Physical organization

Relocation Programmers typically do not know in advance which other programs will be resident in main memory at the time of execution of their program Active processes need to be able to be swapped in and out of main memory in order to maximize processor utilization Specifying that a process must be placed in the same memory region when it is swapped back in would be limiting May need to relocate the process to a different area of memory

Process control information Entry point to program Process Control Block Program Branch instruction Increasing address values Reference to data Data Current top of stack Stack Figure 7.1 Addressing Requirements for a Process

Protection Processes need to acquire permission to reference memory locations for reading or writing purposes Location of a program in main memory is unpredictable Memory references generated by a process must be checked at run time Mechanisms that support relocation also support protection

Sharing Advantageous to allow each process access to the same copy of the program rather than have their own separate copy Memory management must allow controlled access to shared areas of memory without compromising protection Mechanisms used to support relocation support sharing capabilities

Logical Organization Memory is organized as linear Programs are written in modules Modules can be written and compiled independently Different degrees of protection given to modules (read-only, execute-only) Sharing on a module level corresponds to the user s way of viewing the problem Segmentation is the tool that most readily satisfies requirements

Physical Organization Cannot leave the programmer with the responsibility to manage memory Memory available for a program plus its data may be insufficient Programmer does not know how much space will be available Overlaying allows various modules to be assigned the same region of memory but is time consuming to program

Memory Partitioning Memory management brings processes into main memory for execution by the processor Involves virtual memory Based on segmentation and paging Partitioning Used in several variations in some now-obsolete operating systems Does not involve virtual memory

Technique Description Strengths Weaknesses Fixed Partitioning Dynamic Partitioning Simple Paging Simple Segmentation Main memory is divided into a number of static partitions at system generation time. A process may be loaded into a partition of equal or greater size. Partitions are created dynamically, so that each process is loaded into a partition of exactly the same size as that process. Main memory is divided into a number of equal-size frames. Each process is divided into a number of equal-size pages of the same length as frames. A process is loaded by loading all of its pages into available, not necessarily contiguous, frames. Each process is divided into a number of segments. A process is loaded by loading all of its segments into dynamic partitions that need not be contiguous. Simple to implement; little operating system overhead. No internal fragmentation; more efficient use of main memory. No external fragmentation. No internal fragmentation; improved memory utilization and reduced overhead compared to dynamic partitioning. Inefficient use of memory due to internal fragmentation; maximum number of active processes is fixed. Inefficient use of processor due to the need for compaction to counter external fragmentation. A small amount of internal fragmentation. External fragmentation. Table 7.2 Memory Management Techniques Virtual Memory Paging As with simple paging, except that it is not necessary to load all of the pages of a process. Nonresident pages that are needed are brought in later automatically. No external fragmentation; higher degree of multiprogramming; large virtual address space. Overhead of complex memory management. Virtual Memory Segmentation As with simple segmentation, except that it is not necessary to load all of the segments of a process. Nonresident segments that are needed are brought in later automatically. No internal fragmentation, higher degree of multiprogramming; large virtual address space; protection and sharing support. Overhead of complex memory management. (Table is on page 317 in textbook)

Operating System 8M 8M Operating System 8M 2M 4M 8M 6M 8M 8M 8M 8M 8M 12M 8M 16M 8M (a) Equal-size partitions (b) Unequal-size partitions Figure 7.2 Example of Fixed Partitioning of a 64-Mbyte Memory

A program may be too big to fit in a partition Program needs to be designed with the use of overlays Main memory utilization is inefficient Any program, regardless of size, occupies an entire partition Internal fragmentation Wasted space due to the block of data loaded being smaller than the partition

Operating System Operating System New Processes New Processes (a) One process queue per partition (b) Single queue Figure 7.3 Memory Assignment for Fixed Partitioning

The number of partitions specified at system generation time limits the number of active processes in the system Small jobs will not utilize partition space efficiently

Partitions are of variable length and number Process is allocated exactly as much memory as it requires This technique was used by IBM s mainframe operating system, OS/MVT

Operating System 8M Operating System Operating System Operating System Process 1 20M Process 1 20M Process 1 20M 56M Process 2 14M Process 2 14M 36M 22M Process 3 18M 4M (a) (b) (c) (d) Operating System Operating System Operating System Operating System Process 1 20M Process 1 20M 20M Process 2 14M 6M 14M Process 4 8M 6M Process 4 8M 6M Process 4 8M 6M Process 3 18M Process 3 18M Process 3 18M Process 3 18M 4M 4M 4M 4M (e) (f) (g) (h) Figure 7.4 The Effect of Dynamic Partitioning

Dynamic Partitioning External Fragmentation Memory becomes more and more fragmented Memory utilization declines Compaction Technique for overcoming external fragmentation OS shifts processes so that they are contiguous Free memory is together in one block Time consuming and wastes CPU time

Placement Algorithms Best-fit Chooses the block that is closest in size to the request First-fit Begins to scan memory from the beginning and chooses the first available block that is large enough Next-fit Begins to scan memory from the location of the last placement and chooses the next available block that is large enough

8M 8M 12M First Fit 12M Last allocated block (14M) 22M 18M Best Fit 6M 2M 8M 6M Allocated block 8M 6M Free block 14M Possible new allocation 14M Next Fit 36M 20 M (a) Before (b) After Figure 7.5 Example Memory Configuration befor e and after Allocation of 16-Mbyte Block

Buddy System Comprised of fixed and dynamic partitioning schemes Space available for allocation is treated as a single block Memory blocks are available of size 2 K words, L K U, where 2 L = smallest size block that is allocated 2 U = largest size block that is allocated; generally 2 U is the size of the entire memory available for allocation

1 Mbyte block 1 M Request 100 K A = 128K 128K 256K 512K Request 240 K A = 128K 128K B = 256K 512K Request 64 K A = 128K C = 64K 64K B = 256K 512K Request 256 K A = 128K C = 64K 64K B = 256K D = 256K 256K Release B A = 128K C = 64K 64K 256K D = 256K 256K Release A 128K C = 64K 64K 256K D = 256K 256K Request 75 K E = 128K C = 64K 64K 256K D = 256K 256K Release C E = 128K 128K 256K D = 256K 256K Release E 512K D = 256K 256K Release D 1M Figure 7.6 Example of Buddy System

1M 512K 256K 128K 64K A = 128K C =64 K 64K 256K D =256 K 256K Leaf node for allocated block Leaf node for unallocated block Non-leaf node Figure 7.7 Tree Representation of Buddy System

Relocation When the fixed partition scheme is used, we can expect a process will always be assigned to the same partition Whichever partition is selected when a new process is loaded will always be used to swap that process back into memory after it has been swapped out In that case, a simple relocating loader can be used When the process is first loaded, all relative memory references in the code are replaced by absolute main memory addresses, determined by the base address of the loaded process In the case of equal-size partitions and in the case of a single process queue for unequal-size partitions, a process may occupy different partitions during the course of its life When a process image is first created, it is loaded into some partition in main memory; Later, the process may be swapped out When it is subsequently swapped back in, it may be assigned to a different partition than the last time The same is true for dynamic partitioning When compaction is used, processes are shifted while they are in main memory Thus, the locations referenced by a process are not fixed They will change each time a process is swapped in or shifted

Addresses Logical Reference to a memory location independent of the current assignment of data to memory Relative A particular example of logical address, in which the address is expressed as a location relative to some known point Physical or Absolute Actual location in main memory

Relative address Base Register Process Control Block Adder Program Absolute address Bounds Register Comparator Interrupt to operating system Data Stack Process image in main memory Figure 7.8 Hardware Support for Relocation

Partition memory into equal fixed-size chunks that are relatively small Process is also divided into small fixed-size chunks of the same size Pages Chunks of a process Frames Available chunks of memory

Frame number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Main memory 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Main memory A.0 A.1 A.2 A.3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Main memory A.0 A.1 A.2 A.3 B.0 B.1 B.2 (a) Fifteen Available Frames (b) Load Process A (c) Load Process B 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Main memory A.0 A.1 A.2 A.3 B.0 B.1 B.2 C.0 C.1 C.2 C.3 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Main memory Main memory A.0 0 A.0 A.1 1 A.1 A.2 2 A.2 A.3 3 A.3 4 D.0 5 D.1 6 D.2 C.0 7 C.0 C.1 8 C.1 C.2 9 C.2 C.3 10 C.3 11 D.3 12 D.4 13 14 (d) Load Process C (e) Swap out B (f) Load Process D Figure 7.9 Assignment of Process Pages to Free Frames

Page Table Maintained by operating system for each process Contains the frame location for each page in the process Processor must know how to access for the current process Used by processor to produce a physical address

0 0 1 1 2 2 3 3 Process A page table 0 1 2 Process B page table 0 7 1 8 2 9 3 10 Process C page table 0 4 1 5 2 6 3 11 4 12 Process D page table 13 14 Free frame list Figure 7.10 Data Structures for the Example of Figure 7.9 at Time Epoch (f)

Page 2 Internal fragmentation User process (2700 bytes) Page 1 Segment 1 1950 bytes 478 752 Page 0 Segment 0 750 bytes Relative address = 1502 0000010111011110 Logical address = Page# = 1, Offset = 478 0000010111011110 Logical address = Segment# = 1, Offset = 752 0001001011110000 (a) Partitioning (b) Paging (page size = 1K) (c) Segmentation Figure 7.11 Logical Addresses

16-bit logical address 6-bit page # 10-bit offset 0 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 16-bit logical address 0 6-bit page # 0 000101 10-bit offset 1 000110 2 011001 Process 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 page table 0 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0 (a) Paging 16-bit physical address 4-bit segment # 0 000101 12-bit offset 1 000110 0 0 0 12 011001 0 1 0 1 1 1 1 0 0 0 0 4-bit segment # 16-bit logical address Process page table 16-bit logical address 0 1 Length Base 001011101110 0000010000000000 011110011110 0010000000100000 + Process segment table 0 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0 (a) Paging 16-bit physical address 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 (b) Segmentation 16-bit physical address Figure 7.12 Examples of Logical-to-Physical Address Translation

Segmentation A program can be subdivided into segments May vary in length There is a maximum length Addressing consists of two parts: Segment number An offset Similar to dynamic partitioning Eliminates internal fragmentation

Segmentation Usually visible Provided as a convenience for organizing programs and data Typically the programmer will assign programs and data to different segments For purposes of modular programming the program or data may be further broken down into multiple segments The principal inconvenience of this service is that the programmer must be aware of the maximum segment size limitation

Address Translation Another consequence of unequal size segments is that there is no simple relationship between logical addresses and physical addresses The following steps are needed for address translation: Extract the segment number as the leftmost n bits of the logical address Use the segment number as an index into the process segment table to find the starting physical address of the segment Compare the offset, expressed in the rightmost m bits, to the length of the segment. If the offset is greater than or equal to the length, the address is invalid The desired physical address is the sum of the starting physical address of the segment plus the offset

(a) Paging 16-bit physical address 4-bit segment # 16-bit logical address 12-bit offset 0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0 0 1 Length Base 001011101110 0000010000000000 011110011110 0010000000100000 + Process segment table 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 (b) Segmentation 16-bit physical address Figure 7.12 Examples of Logical-to-Physical Address Translation

Summary Memory management requirements Relocation Protection Sharing Logical organization Physical organization Memory partitioning Fixed partitioning Dynamic partitioning Buddy system Relocation Segmentation Paging