LOGICAL AND PHYSICAL ORGANIZATION MEMORY MANAGEMENT TECHNIQUES (CONT D)

Similar documents
Chapter 7 Memory Management

Operating Systems, 6 th ed. Test Bank Chapter 7

Chapter 7 Memory Management

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

OPERATING SYSTEM - VIRTUAL MEMORY

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

OPERATING SYSTEM - MEMORY MANAGEMENT

Operating Systems. Virtual Memory

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

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

Virtual vs Physical Addresses

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

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

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

Lecture 17: Virtual Memory II. Goals of virtual memory

W4118: segmentation and paging. Instructor: Junfeng Yang

COS 318: Operating Systems. Virtual Memory and Address Translation

Computer-System Architecture

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

Chapter 11 I/O Management and Disk Scheduling

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

W4118 Operating Systems. Instructor: Junfeng Yang

Chapter 12. Paging an Virtual Memory Systems

Computer Architecture

Chapter 12 File Management

OPERATING SYSTEMS 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

Chapter 11 I/O Management and Disk Scheduling

CS5460: Operating Systems

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

Chapter 12 File Management

Chapter 12 File Management. Roadmap

Board Notes on Virtual Memory

The Classical Architecture. Storage 1 / 36

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

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

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

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

HY345 Operating Systems

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

OS OBJECTIVE QUESTIONS

CS0206 OPERATING SYSTEMS Prerequisite CS0201, CS0203

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

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

Operating System Tutorial

Chapter 1 13 Essay Question Review

Chapter 1 Computer System Overview

Chapter 2: OS Overview

Computer Organization and Architecture. Characteristics of Memory Systems. Chapter 4 Cache Memory. Location CPU Registers and control unit memory

Outline: Operating Systems

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

Devices and Device Controllers

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

Virtual Memory Behavior in Red Hat Linux Advanced Server 2.1

Chapter 5 Cloud Resource Virtualization

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

Chapter 10: Virtual Memory. Lesson 08: Demand Paging and Page Swapping

Distributed File Systems

General Purpose Operating System Support for Multiple Page Sizes

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

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

High-Performance Processing of Large Data Sets via Memory Mapping A Case Study in R and C++

Operating Systems 4 th Class

Timing of a Disk I/O Transfer

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.

Virtualization in Linux KVM + QEMU

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Virtual Machines. COMP 3361: Operating Systems I Winter

Chapter 6, The Operating System Machine Level

Microkernels, virtualization, exokernels. Tutorial 1 CSC469

Data Storage - I: Memory Hierarchies & Disks

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

INTRODUCTION ADVANTAGES OF RUNNING ORACLE 11G ON WINDOWS. Edward Whalen, Performance Tuning Corporation

COS 318: Operating Systems

Memory Management under Linux: Issues in Linux VM development

COS 318: Operating Systems. Virtual Machine Monitors

Computers: Tools for an Information Age

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

Virtual Memory Paging

CHAPTER 15: Operating Systems: An Overview

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

KVM & Memory Management Updates

Computer Science 4302 Operating Systems. Student Learning Outcomes

Chapter 11: File System Implementation. Operating System Concepts 8 th Edition

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

1. Computer System Structure and Components

Storage in Database Systems. CMPSCI 445 Fall 2010

Virtualization. Explain how today s virtualization movement is actually a reinvention

How To Write To A Linux Memory Map On A Microsoft Zseries (Amd64) On A Linux (Amd32) (

Record Storage and Primary File Organization

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

Operating Systems: Basic Concepts and History

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

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

Segmentation Segmentation: Generalized Base/Bounds

Intel P6 Systemprogrammering 2007 Föreläsning 5 P6/Linux Memory System

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

Transcription:

MEMORY MANAGEMENT Requirements: Relocation (to different memory areas) Protection (run time, usually implemented together with relocation) Sharing (and also protection) Logical organization Physical organization Key terms: Frame a fixed-size block of the main memory Page a fixed-size block of data (secondary memory) A page may temporarily be copied into a frame Segment a variable-size block of data (secondary memory) An entire segment may temporarily be copied into the main memory (segmentation) or the segment may be divided into pages which can be individually copied into the main memory (combined segmentation and paging) LOGICAL AND PHYSICAL ORGANIZATION Logical organization is linear Different parts of the memory can have different permissions (read-write, read-only, etc.) Best implemented using segmentation Physical organization cannot be linear Cannot leave the responsibility of managing memory to the programmer Memory requirements may exceed physical memory, are unknown at build time anyway MEMORY MANAGEMENT/1 MEMORY MANAGEMENT/2 MEMORY MANAGEMENT TECHNIQUES MEMORY MANAGEMENT TECHNIQUES (CONT D) External fragmentation = memory exists to satisfy a request, but is not contiguous Internal fragmentation = allocated memory may be slightly larger than requested memory; difference not used Fixed Partitioning: Main memory is divided into a number of static partitions; a process may be loaded into a partition of equal or greater size Simple to implement, but inefficient (internal fragmentation) Maximum number of active processes is fixed Dynamic Partitioning: Partitions are created dynamically, so that each process is loaded into a partition of exactly the same size as that process No internal fragmentation, more efficient use of main memory Need for compaction to counter external fragmentation (increased CPU load) Simple Paging: Main memory divided into a number of equal-size frames; each process is divided into a number of equal-size pages (same size as frames); a process is loaded by loading all of its pages into available, not necessarily contiguous, frames No external fragmentation; some (small) internal fragmentation Simple Segmentation: Process divided into a number of segments; process is loaded by loading all of its segments into dynamic partitions (need not be contiguous) No internal fragmentation, improved memory utilization, reduced overhead vs. dynamic partitioning External fragmentation Virtual Memory Paging: As with simple paging, except that it is not necessary to load all of the pages of a process; nonresident pages are brought in later, as needed No external fragmentation, higher degree of multiprogramming, large virtual address space Overhead of complex memory management Virtual Memory Segmentation: As with simple segmentation, but is not necessary to load all of the segments; nonresident segments are brought in later, as needed No internal fragmentation, higher degree of multiprogramming, large virtual address space, protection and sharing support Overhead of complex memory management MEMORY MANAGEMENT/3 MEMORY MANAGEMENT/4

PARTITIONING Same-size partitions All programs occupy the same amount of space no matter their size = inefficient, internal fragmentation (whenever program data smaller than partition size) Unequal size partitions Existence of smaller partitions reduce the internal fragmentation Memory assignment: queues of processes waiting to be brought into main memory A single queue or one queue per partition size The fixed number of partitions limits the number of active processes in the system Small jobs will not utilize partition space efficiently Programs larger than any partition loaded via overlays OS can only swap out whole processes if needed DYNAMIC PARTITIONING Process is allocated exactly as much memory as it requires = partitions of variable length and number Used by IBM s mainframe operating system OS/MVT Placement algorithms: Best-fit: chooses the block that is closest in size to the request First-fit: first block that is large enough Next-fit: next large enough block since the last allocation Main disadvantage: external fragmentation Memory utilization declines as memory becomes more and more fragmented Solution: compacting = OS shifts processes in memory so that they are contiguous and free memory is in one block; costly MEMORY MANAGEMENT/5 MEMORY MANAGEMENT/6 DYNAMIC PARTITIONING DYNAMIC PARTITIONING (CONT D) Process is allocated exactly as much memory as it requires = partitions of variable length and number Used by IBM s mainframe operating system OS/MVT Placement algorithms: Best-fit: chooses the block that is closest in size to the request First-fit: first block that is large enough Next-fit: next large enough block since the last allocation Main disadvantage: external fragmentation Memory utilization declines as memory becomes more and more fragmented Solution: compacting = OS shifts processes in memory so that they are contiguous and free memory is in one block; costly MEMORY MANAGEMENT/6 MEMORY MANAGEMENT/7

RELOCATION PAGING Logical address = reference to memory location independent on the assignment of data to memory Relative address = address expressed as a location relative to some known point Physical/Absolute address: actual location in main memory Relocation: Logical address relative (to the beginning of the process) address physical address Needs hardware support = Memory Management Unit (MMU) Partition memory into equal fixed-size chunks that are relatively small (pages) Process is also divided into small fixed-size chunks of the same size (frames) Key data structure: 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 MEMORY MANAGEMENT/8 MEMORY MANAGEMENT/9 LOGICAL ADDRESS AND PAGING/SEGMENTATION LOGICAL ADDRESS AND PAGING MEMORY MANAGEMENT/10 MEMORY MANAGEMENT/11

SEGMENTATION LOGICAL ADDRESS AND SEGMENTATION A program can be subdivided into segments May vary in length Maximum length usually given Addressing consists of two parts: Segment number Offset Similar to dynamic partitioning Eliminates internal fragmentation MEMORY MANAGEMENT/12 MEMORY MANAGEMENT/13 VIRTUAL MEMORY PRINCIPLE OF LOCALITY Not necessary that all the process is in memory as long as all references are logical addresses and address space can be split into pages OS brings into main memory a few pieces of the program = resident set An interrupt is generated when an address is needed but is in the virtual memory (usually on disk) instead of the main memory OS places the process in a Blocked state while the missing piece is brought into the main memory Operating system issues a disk I/O Read request (usually) Another process is dispatched to run while the disk I/O takes place When disk I/O is complete (interrupt), the affected process is placed back in the Ready state More processes can be maintained in the main memory Only some of the pieces of each process are loaded With so many processes in main memory it is very likely a process will be in the Ready state at any particular time A process can even be larger than all of the main memory! Main problem: Thrashing = the system spends most of its time swapping process pieces rather than executing instructions To avoid this, the OS tries to guess based on recent history which pieces are least likely to be used in the near future Guess is based on the principle of locality Program and data references within a process tend to cluster Only a few pieces of a process will be needed over a short period of time Therefore it is possible to make intelligent guesses about which pieces will be needed in the future MEMORY MANAGEMENT/14 MEMORY MANAGEMENT/15

HARDWARE SUPPORT FOR VIRTUAL MEMORY MEMORY MANAGEMENT FORMATS Hardware must support paging and segmentation OS must include software for managing the movement of pages and/or segments between secondary memory and main memory Virtual memory is usually associated with systems that employ paging Each process has its own page table Each page table entry contains the frame number of the corresponding page in main memory MEMORY MANAGEMENT/16 MEMORY MANAGEMENT/17 ADDRESS TRANSLATION TWO-LEVEL HIERARCHICAL PAGE TABLE MEMORY MANAGEMENT/18 MEMORY MANAGEMENT/19

ADDRESS TRANSLATION IN A TWO-LEVEL PAGING SYSTEM INVERTED PAGE TABLE Page number portion of a virtual address is mapped into a hash value Hash value points to inverted page table Fixed proportion of real memory is required for the tables regardless of the number of processes or virtual pages supported Structure is called inverted because it indexes page table entries by frame number rather than by virtual page number MEMORY MANAGEMENT/20 MEMORY MANAGEMENT/21 TRANSLATION LOOKASIDE BUFFER (TLB) TLB ALGORITHM Problem: Each virtual memory reference can cause two physical memory accesses: one to fetch the page table entry one to fetch the data Solution: use a special highspeed cache called a translation lookaside buffer MEMORY MANAGEMENT/22 MEMORY MANAGEMENT/23

ASSOCIATIVE MAPPING TLB AND CACHE TLB cannot be indexed on page number (it contains only some page table entries) TLB entry must include the page number as well as the complete page table entry Hardware that allows simultaneously interrogation of a number of TLB entries to determine if there is a match on page number = associative mapping MEMORY MANAGEMENT/24 MEMORY MANAGEMENT/25 PAGE SIZE COMBINED PAGING AND SEGMENTATION The smaller the page size, the lesser the amount of internal fragmentation However, more pages are required per process More pages per process means larger page tables For large programs in a heavily multiprogrammed environment some portion of the page tables of active processes must be in virtual memory instead of main memory The physical characteristics of most secondary-memory devices favor a larger page size for more efficient block transfer of data Computer Atlas Honeywell-Multics IBM 370/XA IBM 370/ESA VAX family IBM AS/400 DEC Alpha MIPS UltraSPARC Pentium IBM POWER Itanium Page Size 512 48-bit words 1024 36-bit words 4 KB 512 bytes 512 bytes 8 KB 4 KB to 16 MB 8 KB to 4 MB 4 KB or 4 MB 4 KB 4 KB to 256 MB Segmentation allows programmer to view memory as consisting of multiple address spaces (or segments) Simplifies handling of large data structures Facilitates sharing data among processes Facilitates protection Each segment table entry contains the starting address of the corresponding segment in main memory and the length of the segment A bit is needed to determine if the segment is already in main memory Another bit is needed to determine if the segment has been modified since it was loaded in main memory In a combined paging/segmentation system a user s address space is broken up into a number of segments Each segment is broken up into a number of fixed-sized pages which are equal in length to a main memory frame Segmentation is visible to the programmer, paging is transparent MEMORY MANAGEMENT/26 MEMORY MANAGEMENT/27

ADDRESS TRANSLATION PROTECTION RELATIONSHIP Segmentation lends itself to the implementation of protection and sharing policies Each entry has a base address and length so inadvertent memory access can be controlled Sharing can be achieved by segments referencing multiple processes Each entry in segment table features: Validation bit (0 = illegal segment) Read/write/execute privileges MEMORY MANAGEMENT/28 MEMORY MANAGEMENT/29 OS MEMORY MANAGEMENT SOFTWARE VIRTUAL MEMORY FETCH POLICIES The design of the memory management portion of an operating system depends on three fundamental areas of choice: Whether or not to use virtual memory techniques The use of paging or segmentation or both The algorithms employed for various aspects of memory management Fetch policy: Determines when a page should be brought into memory Demand paging only brings pages into main memory when a reference is made to a location on the page Many page faults when process is first started But drops as more and more pages are brought in (principle of locality most future references will be to pages that have recently been brought in) Prepaging once a page is demanded, more are brought in Exploits the characteristics of most secondary memory devices If pages of a process are stored contiguously in secondary memory it is more efficient to bring in a number of pages at one time Ineffective if extra pages are not referenced MEMORY MANAGEMENT/30 MEMORY MANAGEMENT/31

VIRTUAL MEMORY PLACEMENT AND REPLACEMENT POLICIES Placement determines where in real memory a process piece is to reside Important design issue in a segmentation system But irrelevant to paging or combined paging with segmentation (hardware performs functions with equal efficiency) Replacement deals with the selection of a page in main memory to be replaced when a new page must be brought in Objective: the page that is removed is the page least likely to be referenced in the near future The more elaborate the better at guessing, but at the cost of greater hardware and software overhead Frame Locking: When a frame is locked the page currently stored in that frame may not be replaced The kernel as well as key control structures are held in locked frames I/O buffers and time-critical areas may be locked into main memory frames Achieved by associating a lock bit with each frame BASIC PAGE REPLACEMENT ALGORITHMS Optimal: Selects page for which the time to the next reference is the longest (ideal) Least Recently Used (LRU): Replaces the page that has not been referenced for the longest time Principle of locality LRU = page least likely to be referenced in the near future Difficult to implement, substantial overhead One approach is to tag each page with the time of last reference MEMORY MANAGEMENT/32 MEMORY MANAGEMENT/33 BASIC PAGE REPLACEMENT ALGORITHMS (CONT D) THE CLOCK REPLACEMENT ALGORITHM (CONT D) First-in-First-out (FIFO): Treats page frames allocated to a process as a circular buffer; pages are removed in round-robin style Simple to implement, page that has been in memory the longest is replaced Clock: Associates a use bit with each frame, initialized with 1 on load Any frame with a use bit of 1 is passed over by the algorithm (but the bit is reset) Page frames visualized as laid out in a circle MEMORY MANAGEMENT/34 MEMORY MANAGEMENT/35

COMPARISON OF PAGE REPLACEMENT ALGORITHMS ADDITIONAL REPLACEMENT POLICIES Page buffering: A replaced page is assigned to the free page list or modified page list (as the case might be) Pages are written to disk in clusters to improve efficiency Replacement Policy and Cache Size: With large caches replacement of pages can have a performance impact; if the page frame to be replaced is in the cache then that cache block is lost as well Resident Set Management: The OS must decide how many pages to bring into main memory The smaller the amount of memory allocated to each process, the more processes can reside in memory But small number of pages loaded increases page faults But beyond a certain size further allocation of pages will not effect page fault rate Fixed-allocation gives a process a fixed number of frames in main memory within which to execute (page fault one of the pages of that process is replaced) Variable-allocation allows the number of frames allocated to a process to vary MEMORY MANAGEMENT/36 MEMORY MANAGEMENT/37 ADDITIONAL REPLACEMENT POLICIES (CONT D) LOAD CONTROL Replacement Scope Local: chooses only among the resident pages of the process that generated the page fault Global: considers all unlocked pages in main memory (not possible for fixed allocation) Most used policy: variable allocation, global scope Cleaning policy: determine when a modified page should be written out to secondary memory Demand Cleaning: a page is written out only when it has been selected for replacement Precleaning: allows the writing of pages in batches Determines the number of processes that will be resident in main memory Critical in effective memory management Too few processes, many occasions when all processes will be blocked and much time will be spent in swapping Too many processes will lead to thrashing If the degree of multiprogramming is to be reduced, one or of the currently resident processes must be swapped out; six possibilities exist: Lowest-priority process Faulting process Last process activated Process with the smallest resident set Largest process Process with the largest remaining execution window Do not confuse swapping with page replacement! MEMORY MANAGEMENT/38 MEMORY MANAGEMENT/39

LINUX MEMORY MANAGEMENT Two main aspects: process virtual memory and kernel memory allocation Three-level page table structure for the virtual memory KERNEL MEMORY ALLOCATION IN LINUX Page allocator inefficient because the kernel usually requires small chunks in odd sizes A buddy algorithm (power-of-two allocator) and slab allocation are used so that memory for the kernel can be allocated and deallocated in units of one or more pages Page replacement based on the clock algorithm, with an 8-bit age variable (incremented each time a page is accessed, decremented periodically) An age of 0 not accessed in a long time, best candidate for replacement (LRU) MEMORY MANAGEMENT/40 MEMORY MANAGEMENT/41 OTHER ADVANTAGES OF VIRTUAL MEMORY COPY ON WRITE Process creation: Copy-on-write (COW) Allows both parent and child processes to initially share the same pages If either process modifies a shared page, only then is the page copied Allows more efficient process creation as only modified pages are copied Memory-mapped files Memory-mapped file I/O allows file I/O to be treated as routine memory access by mapping a disk block to a page in memory A file is initially read using demand paging. A page-sized portion of the file is read from the file system into a physical page. Subsequent reads/writes to/from the file are treated as ordinary memory accesses. Simplifies file access by treating file I/O through memory rather than read() and write() system calls Also allows several processes to map the same file allowing the pages in memory to be shared Mapping of shared libraries Before any writing takes place: MEMORY MANAGEMENT/42 MEMORY MANAGEMENT/43

COPY ON WRITE (CONT D) SHARED LIBRARIES As soon as Process 1 modifies Page C: MEMORY MANAGEMENT/44 MEMORY MANAGEMENT/45 MEMORY MAPPED FILES MEMORY MANAGEMENT/46