CSC 539: Operating Systems Structure and Design. Spring 2005

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

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

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

OPERATING SYSTEM - MEMORY MANAGEMENT

Lecture 17: Virtual Memory II. Goals of virtual memory

W4118: segmentation and paging. Instructor: Junfeng Yang

OPERATING SYSTEMS MEMORY MANAGEMENT

COS 318: Operating Systems. Virtual Memory and Address Translation

Operating Systems, 6 th ed. Test Bank Chapter 7

Virtual vs Physical Addresses

Chapter 7 Memory Management

Chapter 7 Memory Management

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

OPERATING SYSTEM - VIRTUAL MEMORY

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

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

Memory Management CS 217. Two programs can t control all of memory simultaneously

Operating Systems. Virtual Memory

Outline: Operating Systems

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

Chapter 12. Paging an Virtual Memory Systems

CS5460: Operating Systems

361 Computer Architecture Lecture 14: Cache Memory

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

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

COS 318: Operating Systems. File Layout and Directories. Topics. File System Components. Steps to Open A File

File-System Implementation

Operating System Tutorial

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

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

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

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

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

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

Operating System Overview. Otto J. Anshus

Computer-System Architecture

Operating Systems Lab Exercises: WINDOWS 2000/XP Task Manager

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

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

Chapter 11 I/O Management and Disk Scheduling

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

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

Computer Architecture

Chapter 12 File Management. Roadmap

Chapter 12 File Management

Computer Systems Structure Input/Output

W4118 Operating Systems. Instructor: Junfeng Yang

How To Write A Page Table

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

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

An Implementation Of Multiprocessor Linux

Computer Organization. and Instruction Execution. August 22

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

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

OS OBJECTIVE QUESTIONS

The Linux Virtual Filesystem

Name: 1. CS372H: Spring 2009 Final Exam

Microkernels, virtualization, exokernels. Tutorial 1 CSC469

Virtual Machines. COMP 3361: Operating Systems I Winter

COS 318: Operating Systems

File System Management

Overview. CISC Developments. RISC Designs. CISC Designs. VAX: Addressing Modes. Digital VAX

SAP HANA - Main Memory Technology: A Challenge for Development of Business Applications. Jürgen Primsch, SAP AG July 2011

Traditional IBM Mainframe Operating Principles


COS 318: Operating Systems. I/O Device and Drivers. Input and Output. Definitions and General Method. Revisit Hardware

CSC 2405: Computer Systems II

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

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

Hardware Assisted Virtualization

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

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

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

ELEC 377. Operating Systems. Week 1 Class 3

CHAPTER 6 TASK MANAGEMENT

Instruction Set Architecture (ISA)

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

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Board Notes on Virtual Memory

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

Solid State Drive Architecture

A3 Computer Architecture

CHAPTER 17: File Management

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

Intel DPDK Boosts Server Appliance Performance White Paper

Maximizing VMware ESX Performance Through Defragmentation of Guest Systems. Presented by

MS SQL Performance (Tuning) Best Practices:

6.033 Computer System Engineering

Sawmill Log Analyzer Best Practices!! Page 1 of 6. Sawmill Log Analyzer Best Practices

Network Attached Storage. Jinfeng Yang Oct/19/2015

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

Chapter 11 I/O Management and Disk Scheduling

Putting it all together: Intel Nehalem.

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Kernel Optimizations for KVM. Rik van Riel Senior Software Engineer, Red Hat June

CPU Organization and Assembly Language

Central Processing Unit (CPU)

Agenda. Enterprise Application Performance Factors. Current form of Enterprise Applications. Factors to Application Performance.

Transcription:

CSC 539: Operating Systems Structure and Design Spring 25 Memory management swapping contiguous allocation paging segmentation segmentation with paging 1 Memory management memory management and CPU scheduling are perhaps the two most central tasks of an memory consists of a large array of words, each with its own address both program and data are stored in memory recall: CPU fetch-execute cycle 1. fetch next instruction from memory (based on program counter) 2. decode the instruction 3. possibly fetch operands from memory 4. execute the instruction 5. store the result in memory note: memory is given an address and it returns a value it does not distinguish between instructions and data it does not care how the address was arrived at 2

Address binding users do not (cannot?) think about real addresses user processes go through several steps before execution (e.g., compilation, loading, linking, ) addresses may be represented in different ways during these steps (symbol, relocatable addr, ) instructions/data may be bound to real addresses: at compile time: compiler substitutes actual addresses in executable used in MS-D (why?) at load time: compiler generates relocatable code, final binding is delayed until load time once loaded in memory and process starts, bindings are locked in not generally used (why?) at execution time: if process can be moved during its execution, then binding must be delayed until run time requires special hardware support used in most general-purpose 's (why?) 3 Logical vs. physical addresses the concept of a logical address space that is mapped to a physical address space is central to memory management CPU works in a logical (virtual) address space users, processes, instruction operands, program counter refer to logical addresses memory is a physical address space real memory accesses require real addresses Memory Management Unit (MMU) maps logical addresses to physical addresses implemented in hardware for example, might have a relocation register that provides the base address for a process' block of physical memory 4

Swapping a process needs to be in memory to be executed however, it may be temporarily swapped out of memory into a backing store the process can later be restarted by swapping it back into memory backing store is generally a fast disk speed is important! swapping example: when a process blocks or timeouts, swap it out to disk swap in a new (ready) process from disk to memory dispatch the new process another example: roll out, roll in in a priority-based system, lowerpriority process may be swapped out so higher-priority process can be loaded and executed 5 To swap or not to swap few operating systems use standard swapping the context-switch time is generally too costly special care must be taken, e.g., can't swap out a process waiting on I/O some operating systems use variations on swapping Windows 3.1: if new process is loaded but insufficient memory, swap out old however, user decides when to swap out & swap in processes some versions of UNIX will use paging if system load is very high swapping may be used in combination with other approaches (e.g., segmentation later) 6

Contiguous memory allocation main memory must accommodate both the and user processes usually divided into two partitions: & interrupt vector in low memory, user processes in high memory contiguous memory allocation places each process in a single, contiguous section of memory OPTION 1: single partition (all processes share same memory space) relocation-register scheme used to protect user processes from each other, and from changing code and data relocation register contains smallest physical address; limit register contains range of logical addresses each logical address must be less than the limit register 7 Contiguous memory allocation (cont.) OPTION 2: multiple partitions (each process has its own partition) a hole is a block of available memory when a process arrives, it is allocated memory from a sufficiently large hole maintains info about allocated and free partitions (holes) process P 2 P 4 P 5 memory 6K 3K 7K 5K P 4 2K P 2 2K 17K 2K 23K 23K 23K 256K 256K 256K 256K 8

Dynamic storage allocation problem as processes free up holes in memory and new processes request memory, how do you allocate partitions? first-fit: best-fit: worst-fit: allocate the first hole that is big enough allocate the smallest hole that is big enough must search the entire list of holes unless ordered by size produces the smallest leftover hole allocate the largest hole available also must search the entire list of holes produces the largest leftover hole process P 2 P 4 P 5 memory 6K 3K 2K 1K 2K 23K first-fit is fast best-fit tends to work better w.r.t. storage utilization 256K 9 Fragmentation with dynamic storage allocation, (external) fragmentation can be a problem there may be many small holes, none big enough to fit a process 5% rule: in practice, given N allocated blocks, expect N/2 blocks lost to fragmentation compaction is needed to coalesce holes (similar to defragging a hard drive) note: compaction is possible only if bindings are done at execution time process P 2 P 4 memory 6K 3K 12K 2K 13K 23K 256K 256K internal fragmentation can occur as well allocated memory may be slightly larger than requested memory e.g., suppose memory is allocated in blocks of 4K a 1K process will waste 3K of space in its partition, as will a 5K process 1

Paging paging is one solution to the external fragmentation problem noncontiguous storage allocation a process is allocated physical memory wherever it is available divide the physical memory into fixed-size blocks called frames (size is a power of 2, generally between 512 and 8K bytes) divide logical memory into blocks of the same size called pages to run a process of size n pages, need to find n free frames and load every logical address generated by the CPU is divided into: page number (p): used as an index into a page table containing the base address of each page in physical memory page offset (d): combined with base address to determine the physical memory address 11 Paging examples abstract example: 4 pages in logical address space page table maps to physical frames tiny (but concrete) example: page size = 4 bytes physical memory = 32 bytes 12

Hardware defines page/frame size EXAMPLE: logical address is 32 bits (address space 2 32 = 4 GB) 1 bits are used for page number 2 1 = 124 pages 22 bits are used for offset 2 22 = 4 MB of addresses per page 111 111111111111 p d more, smaller pages are obtained by increasing p & decreasing d 12 bits are used for page number 2 12 = 4K pages 2 bits are used for offset 2 2 = 1 MB of addresses per page 11111 1111111111 p d 13 What paging gives us there is no external fragmentation internal fragmentation is minimized all but the last frame allocated to a process will be full (on avg, will waste ½ a frame) the page table is used to dynamically convert logical addresses into physical addresses small frames reduce fragmentation, but increase the size of the page table 14

Frame table needs to keep track of allocated and free frames in memory system-wide frame table keeps this information when a new process arrives, it is allocated frames that are free (if there are not enough then the process must wait) Frame number Alloc/free Owner Page in process alloc 6 23 1 free - - 2 free - - 3 alloc 3 6 15 Structure of a page table each process has its own page table, stored in main memory (PCB) Page Table Base Register (PTBR) points to the page table for that process PTBR changed by the whenever a process is dispatched, or context-switch note: every data/instruction access now requires 2 memory accesses 1. one access to get the page table entry, so can construct physical address 2. one more to get the data/instruction stored at that address 16

Translation look-aside buffer can reduce to a single memory access using an associative array Translation Look-aside Buffer (TLB) provides constant-time access to frame number given page number (using a parallel search) TLB retains the most recent references to the page table MMU first checks to see if the page in the logical address is in the TLB, if not then must access page table note similarity to caching suppose memory access = 1ns, TLB access = 1 ns if 8% of references are in TLB, then effective memory reference time is (21 *.2 + 11 *.8) = 13 ns 17 Memory protection with paging can associate a protection bit with each frame valid indicates that the page in that frame is in the process' logical address space legal to access invalid indicates that the page is not in the process' logical address space not legal to access 18

Handling large address spaces suppose page size is 4KB, address space uses 32 bits (references 4 G) requires a page table with 1 M entries, each entry is 4 bytes 4 MB of main memory multi-level paging: break the table into pieces, have another table tell where the pieces are page number(s) page offset p 1 p 2 d p 1 is an index into the outer page table, and p 2 is the displacement within the page of the outer page table. hashed page table: store page table info in hash table for faster access & less waste hash key is page number; entry stores the frame number 19 Shared pages pages can be shared among processes read-only reentrant code can be shared without fear of interference a frame in main memory can be referenced by several different page tables must ensure that a frame cannot be removed from memory is any active processes are referencing it 2

Segmentation segmentation is similar to paging, except that partitioning is based on the user's view of memory user sees a program as a collection of segments e.g., main program, function, object, global variables, stack, symbol table, 21 Segmentation architecture the compiler creates segments for main, functions, globals, each segment is stored separately in memory must have hardware support to map logical address (segment number + offset) to physical address segment table maps segment number to base address of segment in memory 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 program 22

Advantages of segmentation view of memory is the user's view segments are protected from one another each segment contains one type of information (e.g., instructions, stack, ) sharing segments is logical and easy if all the instructions are in one segment and all data in another, the instruction segment can be shared freely by different processes (each with own data) as with paging, can implement protection using a valid/invalid bit DISADVANTAGE: unlike paging, external fragmentation can be a problem 23 Segmentation with paging modern computers use a combination of segmentation and paging solve the external fragmentation problem by paging the segments segment-table entry contains not the base address of the segment, but rather the base address of a page table for the segment example: Intel Pentium utilizes both pure segmentation and segmentation with paging the segmentation and paging units act in sequence to map a logical address to physical memory 24

Pentium segmentation & paging segmentation max segment size = 4 GB max # of segments per process = 16 KB logical address is 48 bits long 16-bit selector identifies the segment 32-bit offset specifies location in segment paging page size = 4 KB or 4MB utilizes 2-level paging scheme first 1 bits index a page directory next 1 bits index corresponding page table remaining 12 bits specify offset in page 25 Linux on Pentium Systems Linux is designed to work on a variety of processors since some processors don't support segmentation, Linux doesn't rely on it on the Pentium, Linux uses only 6 segments kernel code, kernel data, user code, user data, task-state, local-descriptor table since some processors support 64-bit addresses, 2-level paging is not sufficient in general, Linux uses 3-level paging but uses bits for middle table if only 32-bits are supported (as with Pentium) 26