Memory management basics (1) Requirements (1) Objectives. Operating Systems Part of E1.9 - Principles of Computers and Software Engineering



Similar documents
Chapter 7 Memory Management

Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

OPERATING SYSTEM - MEMORY MANAGEMENT

Chapter 7 Memory Management

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

OPERATING SYSTEMS MEMORY MANAGEMENT

Operating Systems, 6 th ed. Test Bank Chapter 7

Memory unit sees only the addresses, and not how they are generated (instruction counter, indexing, direct)

CS5460: Operating Systems

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

Virtual vs Physical Addresses

W4118: segmentation and paging. Instructor: Junfeng Yang

Disk Space Management Methods

Memory Management 1. Memory Management. Multitasking without memory management is like having a party in a closet.

Outline: Operating Systems

CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.

Chapter 12. Paging an Virtual Memory Systems

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Peter J. Denning, Naval Postgraduate School, Monterey, California

COS 318: Operating Systems. Virtual Memory and Address Translation

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

Example of Standard API

Lecture 17: Virtual Memory II. Goals of virtual memory

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Segmentation Segmentation: Generalized Base/Bounds

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Operating System Components

& Data Processing 2. Exercise 3: Memory Management. Dipl.-Ing. Bogdan Marin. Universität Duisburg-Essen

1 File Management. 1.1 Naming. COMP 242 Class Notes Section 6: File Management

Chapter 2: OS Overview

2) Write in detail the issues in the design of code generator.

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

CHAPTER 17: File Management

Board Notes on Virtual Memory

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Record Storage and Primary File Organization

Chapter 3 Operating-System Structures

Chapter 6, The Operating System Machine Level

Operating Systems 4 th Class

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

CS3600 SYSTEMS AND NETWORKS

Memory management. Chapter 4: Memory Management. Memory hierarchy. In an ideal world. Basic memory management. Fixed partitions: multiple programs

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Motorola 8- and 16-bit Embedded Application Binary Interface (M8/16EABI)

OPERATING SYSTEM - VIRTUAL MEMORY

Operating System Structures

How To Write A Page Table

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

System Structures. Services Interface Structure

Two Parts. Filesystem Interface. Filesystem design. Interface the user sees. Implementing the interface

Operating Systems. Virtual Memory

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

An Introduction to Computer Science and Computer Organization Comp 150 Fall 2008

Operating Systems CSE 410, Spring File Management. Stephen Wagner Michigan State University

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Chapter 13 File and Database Systems

Chapter 13 File and Database Systems

Overview and History of Operating Systems

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Chapter 12 File Management

Operating System Overview. Otto J. Anshus

Chapter 2 System Structures

Chapter 12 File Management. Roadmap

361 Computer Architecture Lecture 14: Cache Memory

Operating Systems. Design and Implementation. Andrew S. Tanenbaum Melanie Rieback Arno Bakker. Vrije Universiteit Amsterdam

Outline. Operating Systems Design and Implementation. Chap 1 - Overview. What is an OS? 28/10/2014. Introduction

File-System Implementation

University of Dublin Trinity College. Storage Hardware.

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

MS SQL Performance (Tuning) Best Practices:

Chapter 3: Operating-System Structures. Common System Components

A3 Computer Architecture

Introduction. What is an Operating System?

Chapter 16: Distributed Operating Systems

Uses for Virtual Machines. Virtual Machines. There are several uses for virtual machines:

Chapter 12. Development Tools for Microcontroller Applications

Operating Systems. Rafael Ramirez (T, S)

Chapter 1 Computer System Overview

Virtual Machines. COMP 3361: Operating Systems I Winter

Convenience: An OS makes a computer more convenient to use. Efficiency: An OS allows the computer system resources to be used in an efficient manner.

Fourth generation techniques (4GT)

Embedded Software development Process and Tools: Lesson-4 Linking and Locating Software

Computer Architecture

Chapter 14: Distributed Operating Systems

ATSBA: Advanced Technologies Supporting Business Areas. Programming with Java. 1 Overview and Introduction

Memory Management under Linux: Issues in Linux VM development

System Virtual Machines

ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001

CTE214 Operating Systems Syllabus

Operating System Tutorial

CS5460: Operating Systems. Lecture: Virtualization 2. Anton Burtsev March, 2013

Operating Systems Lab Exercises: WINDOWS 2000/XP Task Manager

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Decomposition into Parts. Software Engineering, Lecture 4. Data and Function Cohesion. Allocation of Functions and Data. Component Interfaces

Transcription:

Memory management basics (1) Requirements (1) Operating Systems Part of E1.9 - Principles of Computers and Software Engineering Lecture 7: Memory Management I Memory management intends to satisfy the following requirements: Relocation Memory is shared among several processes; exact number and memory location of each cannot be known in advance to programmer Processes might need to be swapped in and out of main memory A process might need be relocated address binding an important issue. Protection Processes should not be able to access (memory) resources held by other processes Hardware is crucial for providing this. E1.9 - Operating systems (Lect 7) 3 Objectives To present the fundamentals of memory management Address binding Memory allocation Fixed Partitioning Dynamic Partitioning Paging Segmentation Memory management basics (1) Requirements (2) Sharing If needed, processes should be able to access the same portion of main memory for communication Multiple processes executing the same program: keep only one copy of the program in memory Logical organization Ability to handle modularity in the construction of programs: ability to link libraries and resolve symbolic references Physical organization Memory hierarchies (from limited, expensive, fast-access memory to extensive, cheap, slow access memory) discussed earlier in E1.9 Ability to move data through the hierarchy. E1.9 - Operating systems (Lect 7) 2 E1.9 - Operating systems (Lect 7) 4

Address binding (1) From program to process the tools Compiler: translates a high-level language (Pascal, C ) into machine instructions Assembler: translates humanreadable machine instructions into machine-readable instructions that can be executed by the processor Linker: combines different modules of machine instructions (e.g. libraries) into a single sequence of machine instructions Loader: loads machine instructions from file into memory [Silberschatz et al 2001] E1.9 - Operating systems (Lect 7) 5 Address binding (3) At execution time Logical- vs. Physical address space Logical addresses (as generated by CPU) vs. physical addresses (as seen by the memory unit) Execution-time address binding requires hardware support, in particular a relocation register Value of relocation register is added to every address generated by the user process CPU Logical address 122 Relocation register 1000 physical address 1122 The concept of binding a logical-address space to a separate physical address space is central to memory management Memory E1.9 - Operating systems (Lect 7) 7 Address binding (2) When Binding of instructions and data to memory addresses can be done at any step of the previous sequence: Address binding (4) Memory protection Use of a limit register to protect the OS from user processes and user processes from each other Compile time: Absolute code can be generated at this stage, if it is known in advance where will the process reside in memory (e.g. MSDOS.com programs) Load time: Relocatable code can be generated if it not known in advance where will the code reside. Memory addresses are relative (to the beginning of the program), replaced by absolute ones during loading. Execution time: performed if a process can be moved during its execution from one memory segment to another (e.g. swapping) --- requires special hardware CPU Logical address 122 Trap: addressing error No < + Relocation register 1000 physical address 1122 Memory E1.9 - Operating systems (Lect 7) 6 E1.9 - Operating systems (Lect 7) 8

Memory allocation (1) Fixed Partitioning (1) One of the simplest methods for memory allocation is to divide the available memory (after allocating space for the OS) into several fixed-sized partitions Simplest case: one partition; only one process is allowed in memory (along with the OS). Simple but inefficient Degree of multiprogramming bound by the number of partitions OS keeps track of free partitions When a process is created, OS allocates a partition large enough to accommodate it When a process is terminated, OS frees the partition that was allocated to the process Memory allocation (2) Dynamic Partitioning (1) Partitioning can also be dynamic Can divide into variable number of partitions with variable size At the start, entire memory forms a single partition, a hole. When a process is created, OS allocates it the exact memory it requested (if it is available). As processes are created and deleted, corresponding partitions are deleted and created dynamically. Free memory space is broken into several pieces Suffers from external fragmentation E1.9 - Operating systems (Lect 7) 9 E1.9 - Operating systems (Lect 7) 11 Memory allocation (1) Fixed Partitioning (2) Partitions can be equal- or unequal-sized A process occupies exactly one partition If process is smaller than the allocated partition, remaining memory of the partition is wasted This is known as internal fragmentation If process is larger, it cannot run Two partitions Process B Wasted Space (internal fragmentation) Memory allocation (2) Dynamic Partitioning (2) Process D Process K Process E External fragmentation example: there is sufficient memory (in total) for process F, but it is scattered in unusable little parts Process F (waiting for available memory) Free memory holes E1.9 - Operating systems (Lect 7) 10 E1.9 - Operating systems (Lect 7) 12

Memory allocation (2) Dynamic Partitioning (3) The following methods are used to allocate memory to processes First-fit: allocate the first hole that is big enough fast allocation method Best-fit: allocate the smallest hole that is big enough. Requires a search through the entire list of holes. Tends to produce lots of remaining tiny fragments. Worst-fit: allocate the largest hole that is available. (rationale: after allocating the request, the remainder of that hole might still be usable). Also requires search through entire list of holes E1.9 - Operating systems (Lect 7) 13 Paging (1) Paging permits the physical address space of a process to be non-contiguous Physical memory is broken into fixed-sized blocks called frames Logical memory is broken into blocks (of the same size as frames) called pages. Addresses generated by the CPU are now divided into two parts: a page number (p) and a page offset (d) Page number is used as an index into a page table E1.9 - Operating systems (Lect 7) 15 Memory allocation (2) Fragmentation and compaction (4) A solution to the problem of external fragmentation is compaction. Involves reshuffling of the memory contents to place all free memory together in one large block Requires OS to be capable of dynamic relocation Paging (2) Page table contains the base address of each page in physical memory Base address is combined with the page offset to define the physical memory address Process B Compaction Process B Process G Process G Free space E1.9 - Operating systems (Lect 7) 14 E1.9 - Operating systems (Lect 7) [Silberschatz, 2001] 16

Paging (3) When a process is to be executed, its size expressed in pages is examined Frames are allocated (one page per frame) by examining the frame table (a data structure maintained by the OS with the details of the memory available, allocated etc). First page of process is placed into one of the allocated frames; frame number is placed in the page table entry that corresponds to the page number Next page is loaded in the next allocated frame, and so on Paging hardware support Page table lookup can be speeded up through the provision of small, fast-lookup, hardware cache: translation look-aside buffer (TLB) that stores part of the page table Note: user views memory as one single contiguous space but the user s program might be scattered throughout physical memory E1.9 - Operating systems (Lect 7) 17 [Silberschatz, 2001] E1.9 - Operating systems (Lect 7) 19 Paging (4) Advantages: We have no external fragmentation Any free frame can be allocated to a process that needs it Paging shared pages Two or more processes can execute the same code (kept in shared pages) keeping separate data pages Disadvantages: Internal fragmentation still possible frames are allocated as units E1.9 - Operating systems (Lect 7) 18 E1.9 - Operating systems (Lect 7) [Silberschatz, 2001] 20

Memory allocation (4) Segmentation (1) Instead of partitioning the logical address space into pages (paging), we can divide it into logical segments Each segment has a name and a length associated with it. Different segments can have different lengths User specifies addresses as pairs: <logical segment offset>. E.g arrays of data Memory allocation (4) Segmentation (3) Advantages: Supports user s view of memory segments are constructed according to user semantics Protection and sharing easily implementable Note difference with paging: user is now aware of segments in paging, user specified a single address which was then partitioned by the hardware into a page number and an offset Disadvantages: External fragmentation possible E1.9 - Operating systems (Lect 7) 21 E1.9 - Operating systems (Lect 7) 23 Memory allocation (4) Segmentation (2) Segment table is used to translate logical address into physical address Summary Memory management fundamentals Flexible memory management requires dynamic relocation capabilities Simple memory allocation techniques include fixed and dynamic partitioning; susceptible to internal/external fragmentation Paging allows for non-contiguous allocation of memory Segmentation allows for a user s view of memory partitioning [Silberschatz, 2001] E1.9 - Operating systems (Lect 7) 22 E1.9 - Operating systems (Lect 7) 24

Recommended Reading Read chapter 9 of Silberschatz s book Read chapter 4, sections 4.1 & 4.2 of Tanenbaum s book Read chapter 7 of Stalling s book E1.9 - Operating systems (Lect 7) 25