C06: Memory Management

Similar documents
Preview. Memory Management

Chapter 3 - Memory Management

Memory management: outline

Memory management: outline

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

UNIT III MEMORY MANAGEMENT

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

Operating Systems Lecture 5: Memory Management I

VII. Memory Management

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

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

12: Memory Management

MODERN OPERATING SYSTEMS. Chapter 3 Memory Management

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

CS399 New Beginnings. Jonathan Walpole

In multiprogramming systems, processes share a common store. Processes need space for:

Chapter 8: Memory Management

C13: Files and Directories: System s Perspective

Frequently asked questions from the previous class survey

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

CISC 7310X. C11: Mass Storage. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/19/2018 CUNY Brooklyn College

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

8: Memory Management

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

CS370 Operating Systems

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Operating Systems (2INC0) 2017/18

Memory Management. Frédéric Haziza Spring Department of Computer Systems Uppsala University

Chapter 9 Memory Management

The Memory Management Unit. Operating Systems. Autumn CS4023

Memory Management Basics

Lecture 8 Memory Management Strategies (chapter 8)

Memory Management. Today. Next Time. Basic memory management Swapping Kernel memory allocation. Virtual memory

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

CS420: Operating Systems

MEMORY MANAGEMENT. Jo, Heeseung

Memory Management. Jo, Heeseung

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

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

CS 550 Operating Systems Spring Memory Management: Paging

Chapter 8 Memory Management

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

Memory Management. Memory Management

Last Class: Deadlocks. Where we are in the course

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

CISC 7310X. C03: Process. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 2/15/2018 CUNY Brooklyn College

C09: Process Synchronization

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

C02: Interrupts and I/O

File System Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

CS Operating Systems

CS Operating Systems

Background. Contiguous Memory Allocation

Course: Operating Systems Instructor: M Umair. M Umair

Chapter 8 Main Memory

Memory Management. Memory Management

Operating Systems, Fall

Operating Systems, Fall

4 MEMORY MANAGEMENT 4.1 BASIC MEMORY MANAGEMENT

Goals of Memory Management

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

File System Implementation

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

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

CS 3733 Operating Systems:

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

Memory Management william stallings, maurizio pizzonia - sistemi operativi

Process. Memory Management

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

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

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

Operating Systems. IV. Memory Management

Unit II: Memory Management

Find the physical addresses of virtual addresses: 0, 8192, 20, 4100, : : : : : 24684

Outlook. File-System Interface Allocation-Methods Free Space Management

Memory Management. Dr. Yingwu Zhu

FILE SYSTEM IMPLEMENTATION. Sunu Wibirama

Chapter 8: Memory-Management Strategies

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

Basic Memory Management

CIS Operating Systems Memory Management. Professor Qiang Zeng Fall 2017

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

Segmentation (Apr 5 and 7, 2005)

Operating Systems Unit 6. Memory Management

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

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

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

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

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

Chapter 8: Main Memory

CS307: Operating Systems

Chapter 1 Computer System Overview

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

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

Chapter 8: Main Memory

OPERATING SYSTEM. PREPARED BY : DHAVAL R. PATEL Page 1. Q.1 Explain Memory

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

Transcription:

CISC 7310X C06: Memory Management Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/8/2018 CUNY Brooklyn College 1

Outline Recap & issues Project 1 feedback Memory management: main memory No memory abstraction Memory abstraction: address space Memory segmentation Assignment 3/8/2018 CUNY Brooklyn College 2

Project 1 Feedback Via commenting on git commits at Github 3/8/2018 CUNY Brooklyn College 3

Questions? Project 1? Project 2? 3/8/2018 CUNY Brooklyn College 4

Memory Hierarchy ~1ns ~2ns ~10ns ~10ms Registers Cache Main Memory Secondary Memory (e.g., Magnetic Disk) <KB ~MB ~GB ~TB 2/1/2018 CUNY Brooklyn College 5

Memory Management How does an OS provide an abstraction of the memory hierarchy to make it useful? Main memory Virtual memory Caching 3/8/2018 CUNY Brooklyn College 6

Main Memory Management Without abstraction With abstraction Segmentation 3/8/2018 CUNY Brooklyn College 7

No Abstraction Directly address physical memory three variations Simple memory organization [Figure 3-1 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 8

What would happen if Three variations Simple memory organization [Figure 3-1 in Tanenbaum & Bos, 2014] int *p = malloc( ) while (1) { } *p = value; p ++; 3/8/2018 CUNY Brooklyn College 9

Protection and Parallelism When without abstraction, How to provide protection: prevent a program overwrite another program or the OS? How to run multiple programs? Need additional hardware for protection 3/8/2018 CUNY Brooklyn College 10

Example: IBM 360 Allow access only when PSW key matches RAM block key PSW KEY 1101 KEY 0000 0001 0010 0011 2KB Block 2KB Block 2KB Block 2KB Block Yes PWS Key == RAM Block Key? No Stop ill-behaved program 3/8/2018 CUNY Brooklyn College 11

Example: Running Multiple Programs Naively loading two programs to run Loading two programs [Figure 3-2 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 12

Example: Static Relocation OS adds an offset to every address when loading If the program is to load to 16384, then add 16380 to every address JMP 28 JMP 28 + 16384 JMP 16412 Needs to know which is an address, which is not MOV REGISTER1, 28 Is 28 an address or a constant? 3/8/2018 CUNY Brooklyn College 13

Directly Addressing of Physical Memory Simple embedded devices Examples: radios, washing machines, microwave ovens, coffee machines A library on ROM loads a program to run and the program addresses physical memory without abstraction Example: the ecos system (http://ecos.sourceware.org/) ecos is a single process, multiple thread operating environment. As such, memory management is not required. There is no notion of separate address "spaces" in ecos like there would be in a system like Linux. All threads share the same address space and access capabilities. https://sourceware.org/viewvc/ecos/ 3/8/2018 CUNY Brooklyn College 14

Questions? No abstraction: directly addressing physical memory How to run multiple programs? How to provide protection? How to provide relocation (static relocation)? Where is it commonly used? 3/8/2018 CUNY Brooklyn College 15

Memory Abstraction Notion of address space Base and limit registers Swapping Managing free memory 3/8/2018 CUNY Brooklyn College 16

Address Space Two problems Protection and relocation A logical concept A process has its own independent address space, a set of addresses the process can use to address memory How do we establish the correspondence between the logical address and the address of the physical memory? Dynamic relocation 3/8/2018 CUNY Brooklyn College 17

Dynamic Relocation Example: using base and limit registers Map each process s address space onto a different part of physical memory Processor has two registers Base register loaded with beginning physical address Limit register loaded with length of the program 3/8/2018 CUNY Brooklyn College 18

Base and Limit Registers Hardware support, when reference to a memory, CPU does the following, Base register Address in address space in process Yes Within length of the limit register No Fault 3/8/2018 CUNY Brooklyn College 19

Running Multiple Programs Base and limit registers realize a simple dynamic relocation and protection Base register: dynamic relocation done by CPU Limit register: protection done by CPU Dynamic relocation via base and limit registers [Figure 3-3 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 20

Base and Limit Registers: Examples Implementation vary Whether base and limit registers are protected? Who can modify these registers? CDC 6600 provides protection; Intel 8088 does not Whether a processor has different base and limit registers to protect for programs (instructions) and data, respectively 3/8/2018 CUNY Brooklyn College 21

Swapping A corollary to Parkinson s law: Programs expands to fill the memory available to hold them Running many programs may require more memory than is available Two solutions Swapping Virtual memory 3/8/2018 CUNY Brooklyn College 22

Swapping & Virtual Memory Swapping Brining in a process in entirety from the disk, run the process, and putting it back on the disk Idle processes are mostly stored on disk Virtual memory Allow a process to run even if it is only partially in main memory To be discussed next 3/8/2018 CUNY Brooklyn College 23

Swapping: Example Swapping of a few processes Swapping of multiple processes [Figure 3-4 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 24

Memory Compaction Swapping creates multiple holes in memory Sometimes it is necessary to combine multiple holes into big one 3/8/2018 CUNY Brooklyn College 25

Growing Program Data Segment In many programming languages, program data can grow in size Example: int *a = malloc( ) Object o = new Object() What if memory hole is not big enough to accommodate the growing program data? Move process Compact memory Swap out one or more processes Suspend the process until more memory is available Killed 3/8/2018 CUNY Brooklyn College 26

Proactive Approach Process growing in size expected, allocate extra memory when a process is swapped in or moved Growing data segment Growing stack segment 3/8/2018 CUNY Brooklyn College 27

Proactive Approach: Examples For data segment; and for data & stack segments Growing program data [Figure 3-5 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 28

Managing Free Memory Keep track of memory usage Data structures & algorithms Bitmaps Linked lists 3/8/2018 CUNY Brooklyn College 29

Bitmaps A data structure keep tracks memory allocation Specify an allocation unit, have many allocation units Example: 4 KB A bit in a bitmap indicate an allocation unit is free or allocated Example Free: 1 Allocated: 0 3/8/2018 CUNY Brooklyn College 30

Bitmap: Example An example allocation and its bitmap Linked list of memory allocation [Figure 3-6 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 31

Design of Bitmap What should be the size of the allocation unit? Two competing factors When allocation unit become smaller, bitmap larger How big is a bitmap? When allocation unit becomes larger, memory waste larger How much waste is there? How about search the bitmap to locate free memory? 3/8/2018 CUNY Brooklyn College 32

Linked List Maintain a linked list of allocated memory and free memory segments Linked list of memory allocation [Figure 3-6 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 33

Linked List: Example Allocation and deallocation scenarios Linked list of memory allocation [Figure 3-7 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 34

Design of Linked List Single-linked list or double-linked list? Separate list of processes or holes? A few algorithms First fit: starting from beginning Next fit: starting from last time Best fit: takes the smallest hole Worst fit: takes the largest hole Quick fit: based on allocation pattern Additional data structure? Example: Holes can be sorted in size (any data structure for ordered list) 3/8/2018 CUNY Brooklyn College 35

Questions? Address space Concept? Simple mechanism for dynamic allocation and protection Swapping 3/8/2018 CUNY Brooklyn College 36

Address Space and Process One process one address space? 3/8/2018 CUNY Brooklyn College 37

Compiled Tables A compiler typically builds many tables when processing a program 1. The source text being saved for the printed listing 2. The symbol table, names and attributes of variables. 3. The table containing integer and floating-point constants used. 4. The parse tree, syntactic analysis of the program. 5. The stack used for procedure calls within compiler. Each of these grows continuously as compilation proceeds 3/8/2018 CUNY Brooklyn College 38

Growing Tables: Example One address space for all? One address space for all [Figure 3-30 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 39

Segmentation Provide many completely independent address spaces, called segments Each segment consists of a linear sequence of address Different segments can have different lengths Segments can grow or shrink independently without affection others 3/8/2018 CUNY Brooklyn College 40

Segmentation: Example Segments can grow or shrink independently without affection others Multiple segments [Figure 3-31 in Tanenbaum & Bos, 2014] 3/8/2018 CUNY Brooklyn College 41

Questions Concept of segmentation 3/8/2018 CUNY Brooklyn College 42

Assignment Practice assignment Review Guide #1 and Take-Home Test #1 3/8/2018 CUNY Brooklyn College 43