Computer Systems Engineering Department, QUEST, Nawabshah OPERATING SYSTEMS

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

Chapter 7 Memory Management

Chapter 7 Memory Management

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

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

Operating Systems, 6 th ed. Test Bank Chapter 7

OPERATING SYSTEM - MEMORY MANAGEMENT

W4118: segmentation and paging. Instructor: Junfeng Yang

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

OPERATING SYSTEMS MEMORY MANAGEMENT

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

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

Virtual vs Physical Addresses

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

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

Lecture 17: Virtual Memory II. Goals of virtual memory

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

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

COS 318: Operating Systems. Virtual Memory and Address Translation

Segmentation Segmentation: Generalized Base/Bounds

CS5460: Operating Systems

Chapter 2: OS Overview

Record Storage and Primary File Organization

Operating System Tutorial

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

Virtual Memory. Virtual Memory. Paging. CSE 380 Computer Operating Systems. Paging (1)

OPERATING SYSTEM - VIRTUAL MEMORY

Linux Process Scheduling Policy

Chapter 12. Paging an Virtual Memory Systems

Virtual Memory. How is it possible for each process to have contiguous addresses and so many of them? A System Using Virtual Addressing

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

Segmentation and Fragmentation

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.

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

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

Origins of Operating Systems OS/360. Martin Grund HPI

A3 Computer Architecture

Chapter 12 File Management

Chapter 12 File Management. Roadmap

How To Write A Page Table

Board Notes on Virtual Memory

Traditional IBM Mainframe Operating Principles

Binary search tree with SIMD bandwidth optimization using SSE

Virtual Machines. COMP 3361: Operating Systems I Winter

Chapter 12 File Management

Secondary Storage. Any modern computer system will incorporate (at least) two levels of storage: magnetic disk/optical devices/tape systems

COS 318: Operating Systems

File Management. Chapter 12

Chapter 2: Computer-System Structures. Computer System Operation Storage Structure Storage Hierarchy Hardware Protection General System Architecture

Outline: Operating Systems

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 13-1

Disk Space Management Methods

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

COS 318: Operating Systems

Chapter 13 Disk Storage, Basic File Structures, and Hashing.

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

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

Chapter 13. Chapter Outline. Disk Storage, Basic File Structures, and Hashing

Chapter 13. Disk Storage, Basic File Structures, and Hashing

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

CHAPTER 17: File Management

Computer Architecture

Operating Systems. Steven Hand. Michaelmas / Lent Term 2008/ lectures for CST IA. Handout 3. Operating Systems N/H/MWF@12

Operating Systems 4 th Class

1 Organization of Operating Systems

This Unit: Virtual Memory. CIS 501 Computer Architecture. Readings. A Computer System: Hardware

CS0206 OPERATING SYSTEMS Prerequisite CS0201, CS0203

This tutorial will take you through step by step approach while learning Operating System concepts.

Windows Server Performance Monitoring

Resource Allocation Schemes for Gang Scheduling

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

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

Operating System Overview. Otto J. Anshus

x64 Servers: Do you want 64 or 32 bit apps with that server?

Virtual desktops made easy

The Classical Architecture. Storage 1 / 36

INTRODUCTION The collection of data that makes up a computerized database must be stored physically on some computer storage medium.

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Full and Para Virtualization

Chapter 6, The Operating System Machine Level

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 412, University of Maryland. Guest lecturer: David Hovemeyer.

We r e going to play Final (exam) Jeopardy! "Answers:" "Questions:" - 1 -

Contributions to Gang Scheduling

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc()

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

Where is the memory going? Memory usage in the 2.6 kernel

Chapter 3 Operating-System Structures

Dynamic Memory Management for Embedded Real-Time Systems

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Switch Fabric Implementation Using Shared Memory

Symbol Tables. Introduction

Topics in Computer System Performance and Reliability: Storage Systems!

The Xen of Virtualization

Chapter 13 File and Database Systems

Chapter 13 File and Database Systems

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

Transcription:

OPERATING SYSTEMS Memory Management Introduction Fixed Partitioning Variable Partitioning Memory Hole/Allocation management Problems

Introduction Techniques to manage Main memory efficiently Provides multitasking facility Responsible for memory allocation, de-allocation and keep track for each location Basic techniques: Fixed/Static Partitioning Variable/Dynamic Partitioning 2

Fixed Partitioning Partition of main memory into a set of non-overlapping memory regions called partitions Fixed partitions can be of equal or unequal sizes Leftover space in partition after program assignment is called internal fragmentation Uses overlaying technique 3

Types of Fixed Partitions Equal-size partitions If there is an available partition, a process can be loaded into that partition because all partitions are of equal size, it does not matter which partition is used. Doesn t require any allocation policy Fast and easy Result internal fragmentation 4

Types of Fixed Partitions Unequal-size partitions (Multiple queues) assign each process to the smallest partition within which it will fit. a queue exists for each partition size. tries to minimize internal fragmentation. Some queues might be free while other might be loaded 5 Continued

Types of Fixed Partitions Unequal-size partitions (single queue) The smallest available partition that will hold the process is selected. increases the level of multiprogramming at the expense of internal fragmentation. 6 Continued

Problems in Fixed Partitioning Main memory use is inefficient. A program occupies an entire partition which can cause internal fragmentation. Unequal-size partitions reduces the problem little bit Equal-size partitions was used in early IBM s OS/MFT (Multiprogramming with a Fixed number of Tasks). 7 Continued

Variable Partitioning When a process arrives, it is allocated memory from a hole large enough to accommodate it. Hole block of available memory; holes of various sizes are scattered throughout memory. Operating system maintains information about: a) allocated partitions b) free partitions (holes) OS OS OS OS process 5 process 5 process 5 process 5 process 9 process 9 process 8 process 10 process 2 process 2 process 2 process 2 8

Internal/External Fragmentation There are really two types of fragmentation: 1. Internal Fragmentation Allocated memory may be slightly larger than requested memory The size difference in memory internal to a partition, but not being used. 1. External Fragmentation Memory space left between two or more allocated processes External fragmentation exist in dynamic memory divisions 9

Reducing External Fragmentation Compaction Shuffle memory contents to place all free memory together in one large block (or possibly a few large ones). Only if relocation is dynamic and is done at execution time. Problem: Disturbs processes those are communicating with I/O Addresses should be resolved after the compaction 10

Memory Hole/Allocation Management It is required to keep track of used and unused memory spaces Techniques: Bit-map: It uses a table where 0 represent empty spaces & 1 represents used spaces. Linked List: Every node contains 4 fields, 1st to show Process (P) or Memory-Hole (H), 2 nd to show starting address of P/H, 3 rd to present length of P/H and 4 th field contains address of next node Figure a shows the used/unused memory spaces Figure b shows swapping management using Bit-map Figure c shows swapping management using Linked List 11

Placement Algorithms Methods for process allocation in fixed (unequal) and dynamic memory management techniques: First-fit: It favors allocation near the beginning where a process can accommodate. Next-fit: It works like first fit, but it starts searching of memory-hole from last point it has used. Best-fit: It searches whole list & find the smallest memoryhole where process can fit. Worst-fit: It searches whole list & fine the largest memoryhole to allocate a process. Buddy System: dynamic memory allocation w.r.t requested memory size 12

Placement Algorithms Used to decide which free block to allocate to a process of 16MB. Goal: reduce usage of compaction procedure (its time consuming). Example algorithms: First-fit Next-fit Best-fit Worst-fit 13 Continued

Buddy System Allocation 14

Example of Buddy System 15

Problems Question # 1 Consider a swapping system in which memory consists of the following hole sizes in memory order: 10K, 4K, 20K, 18K, 7K, 9K, 12K and 15K. Which hole is taken for successive segment requests of (a) 12K, (b) 10K, (c) 9K for first fit? Repeat the question for best fit, worst fit and next fit. (a) 1 st fit 12K, 10K and 9K will be allocated in Block # 5, 4, 3 respectively (b) Best fit 12K, 10K and 9K will be allocated in Block # 5, 4, 3 respectively (c) Worst fit 12K, 10K and 9K will be allocated in Block # 8, 7, 6 respectively (d) Next fit 12K, 10K and 9K will be allocated in Block # 5, 6, 7 respectively 4K Block 1 7K Block 2 9K Block 3 10K Block 4 12K Block 5 15K Block 6 18K Block 7 20K Block 8 16

Problems Question # 2 A computer uses the buddy system for memory management. Initially it has one block of 256K at address 0. After successive requests for 5K, 25K, 35K and 20K come in, how many blocks are left and what are their sizes and addresses? 5K 29K unused 8K 16K 25K 7K unused 35K 29K unused 20K 12K unused 32K 64K 8K 32K 64K 32K 0 8 16 32 64 128 160 256 192 17 Continued

Problems Question # 3 Given memory partitions of 100K, 500K, 200K, 300K and 600K (in order), how would each of the First-fit, Best-fit, and Worst-fit algorithms place processes of 212K, 417K, 112K and 624K (in order)? Which algorithm makes the most efficient use of memory? First fit 212K, 417K 112 and 624K will be allocated in Block # 2, 5, 3 and 5&1(last process will be allotted after completion of process 2 and it will be allotted by using overlaying technique) respectively 100K Block 1 500K Block 2 18 Best fit 212K, 417K 112 and 624K will be allocated in Block # 4, 2, 3, and 5&1(last process will be allotted by using overlaying technique) respectively Worst fit 212K, 417K 112 and 624K will be allocated in Block # 5, 2, 4 and 5&2(last process will be allotted after completion of process 1 & 2 and it will be allotted by using overlaying technique) respectively According to this example, best fit technique is better than others. 200K Block 3 300K Block 4 600K Block 5 Continued

Questions

OPERATING SYSTEMS Simple/Basic Paging Introduction Paging mechanism Translation Look-aside buffer Sharing & Protection

Simple/Basic Paging Divide physical memory into fixed-sized chunks/blocks called frames. Divide logical memory into blocks of same size pages. The process pages can be assigned to any free frames in main memory. Pages can be allocated in noncontiguous frames 2

Simple/Basic Paging Requirements Need to keep track of all free frames. To run a program of size n pages, need to find n free frames and load program. Need to set up a page table to translate logical to physical pages/addresses. Internal fragmentation possible only for the last page No external fragmentation possible 3

Page-Table & Free-Frame list 4 Before allocation After allocation

Logical address in paging The logical address becomes a relative address. If16 bits addresses are used with page size = 1K, then 10 bits for offset and 6 bits available for page number. Address translation from logical to physical is done with help of page table page table helps to obtain the physical address (frame number, offset). 5

Address Translation Scheme Logical address generated by CPU is divided into two parts: Page number (p) used as an index into a page table which contains the base address of each page in physical memory. Page offset/displacement (d) combined with base address to define the physical memory address By using a page size of a power of 2, the pages are invisible to the programmer, compiler/assembler, and the linker. Address translation at run-time is then easy to implement in hardware 6

Address Translation Architecture 7

Logical-to-Physical Address Translation in Paging 8

Paging Example 9

Implementing Page Table 1. Keep Page Table in main memory: Page-table base register (PTBR) points to the page table. Page-table length register (PTLR) indicates size of the page table. Every data/instruction access requires two memory accesses one for the page table one for the data/instruction. 2. Keep Page Table in hardware (in MMU) Expensive if page table is large Faster but costly 10

Implementing Page Table 3. Combination: Special fast-lookup hardware cache called Associative Memory (Registers) or Translation Lookaside Buffer (TLB) enables fast parallel search: Page # Frame # Address translation (p, d) If p is in associative register, get frame # else., get frame # from page table in memory. 11 Continued

Paging Hardware With TLB 12

Importance of TLB TLB takes advantage of the Locality Principle. Associative mapping hardware to simultaneously interrogate all TLB entries to find a match/hit on page number. TLB hit rates are 90+%. TLB must be flushed each time a new process enters the running state. Requires to keep/load TLB information in/from process context. 13

Memory Protection Memory protection implemented by associating a protection bit with each frame. Valid-invalid bit attached to each entry in the page table: valid indicates that the associated page is in the process logical address space, and is thus a legal page. invalid indicates that the page is not in the process logical address space. 14

Valid (v) or Invalid (i) Bit in a Page Table 15

Shared Pages Shared code: One copy of read-only code shared among processes (i.e., text editors, compilers, window systems). Shared code must appear in same location in the logical address space of all processes. Private code and data: Each process keeps separate copy of code and data. The pages for the private code and data can in the logical address space. 16

Shared Pages Example 17 Continued

Questions

. OPERATING SYSTEMS Simple/Basic Segmentation Introduction Segmentation mechanism Sharing & Protection Comparison with paging

. Simple/Basic Segmentation Paging division is arbitrary; no natural/logical boundaries for protection/sharing. Segmentation supports user s view of a program. A program is a collection of segments (logical units) A compiler has many tables that are built up as compilation proceeds, possibly including: The source text (Code segment) The symbol table the names and attributes of variables. The table containing integer, floating-point constants used. The parse tree, the syntactic analysis of the program. The stack used for procedure calls within the compiler. 2

. Segmentation Feature Segmentation allows each table to grow or shrink independently of the other tables. 3

. Segmentation solution In a one-dimensional address space with growing tables, one table may bump into another. 4

. Simple Segmentation properties Each program is subdivided into blocks of non-equal size called segments. When a process gets loaded into main memory, its different segments can be located anywhere. Each segment is fully packed with instructions/data; no internal fragmentation. There is external fragmentation; it is reduced when using small segments. In contrast with paging, segmentation is visible to the programmer: provided as a convenience to organize logically programs (example: data in one segment, code in another segment). must be aware of segment size limit. The OS maintains a segment table for each process. Each entry contains: the starting physical addresses of that segment. the length of that segment (for protection). 5

. Example of Segmentation 6

. Implementing Segmentation Logical address consists of a two fields: <segment-number, offset>, Segment table maps two-dimensional physical addresses; each table entry has: base contains the starting physical address where the segments reside in memory. limit specifies the length of the segment. Segment-table base register (STBR) points to the segment table s location in memory. Segment-table length register (STLR) indicates number of segments used by a program; segment-number s is legal if s < STLR. 7

. Logical address in segmentation 8

. Address Translation Architecture 9

. Logical-to-Physical Address Translation in segmentation 10

. Protection in Segmentation Protection with each entry in segment table associate: validation bit = 0 illegal segment read/write/execute privileges Protection bits associated with segments; code sharing occurs at segment level. Since segments vary in length, memory allocation is a dynamic storage-allocation problem. 11

. Sharing in Segmentation Systems Segments are shared when entries in the segment tables of 2 different processes point to the same physical locations. Example: the same code of a text editor can be shared by many users: Only one copy is kept in main memory. But each user would still need to have its own private data segment. 12

. Shared Segments Example 13

. Simple segmentation/paging comparison Segmentation is visible to the programmer whereas paging is transparent. Naturally supports protection/sharing. Supports logical organization of program into segments while using different kinds of protection (example: execute-only for code but read-write for data). Segments are variable-size; Pages are fixed-size. Segmentation requires more complicated hardware for address translation than paging. Segmentation suffers from external fragmentation. Paging only yields a small internal fragmentation. Combine Segmentation and Paging for suitable outcome 14

. Questions