CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.

Slides:



Advertisements
Similar presentations
Part IV: Memory Management
Advertisements

Memory management In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. Memory management is achieved.
Chapter 6: Memory Management
Memory Management Chapter 7.
Fixed/Variable Partitioning
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to.
Allocating Memory.
Chapter 7 Memory Management
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
OS Fall’02 Memory Management Operating Systems Fall 2002.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Understanding Operating Systems1 Operating Systems Virtual Memory Thrashing Single-User Contiguous Scheme Fixed Partitions Dynamic Partitions.
COMP5102/5122 Lecture 4 Operating Systems (OS) Memory Management phones off (please)
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management.
Memory Management Chapter 7 B.Ramamurthy. Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Memory Management Chapter 5.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Memory Allocation CS Introduction to Operating Systems.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Memory Management Chapter 7.
Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Dr.
1. Memory Manager 2 Memory Management In an environment that supports dynamic memory allocation, the memory manager must keep a record of the usage of.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Virtual Memory Virtual Memory is created to solve difficult memory management problems Data fragmentation in physical memory: Reuses blocks of memory.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Memory Management Chapter 5 Advanced Operating System.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
MEMORY MANAGEMENT. memory management  In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. 
Chapter 7 Memory Management
Memory Management Chapter 7.
Chapter 2 Memory and process management
UNIT–IV: Memory Management
Chapter 9 – Real Memory Organization and Management
26 - File Systems.
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
CS Introduction to Operating Systems
CS241 Section: Week 10.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Unit 6: Real Memory organization management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
So far… Text RO …. printf() RW link printf Linking, loading
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
CSE 542: Operating Systems
Presentation transcript:

CS 241 Section Week #9 (11/05/09)

Topics MP6 Overview Memory Management Virtual Memory Page Tables

MP6 Overview

In MP6, you create a virtual memory system with memory mapped IO. – We provide you with two parameters: PAGESIZE: The size (bytes) of each memory page. MEMSIZE: The total number of memory pages. Use these variables and NOT the numbers they correspond with (eg: use PAGESIZE not 1024).

MP6 Overview In MP6, you have a fixed amount of pre- defined memory for storing memory mapped I/O contents. – memory[PAGESIZE * MEMSIZE] This memory will likely not be large enough to store the entire contents of files. You will need to program a page table to manage the paging of data in and out of this memory.

MP6 Overview In MP6, you need to implement four functions: – my_mmap() Initializes the memory mapping structure / space. – my_mread() / my_mwrite() Reads and writes to the memory mapped space. – My_munmap() Destroys the memory mapped structure, flushes any pages still in memory back to disk.

MP6 Overview Besides the functions and storage space defined above, we only require three additional things: – Pages must be replaced by a “Least Recently Used” algorithm – Pages must only be written out to disk when they are paged out if their contents have changed. – When writing out the THIRD page (index 2) to disk, you should print some output.

MP6 Overview Everything else is left for you to decide how to implement. Like MP5, we provide a simple tester. You should program other testers to test fully test the robustness of your library.

Memory Management

Memory Contiguous allocation and compaction Paging and page replacement algorithms

Fragmentation External Fragmentation – Free space becomes divided into many small pieces – Caused over time by allocating and freeing the storage of different sizes Internal Fragmentation – Result of reserving space without ever using its part – Caused by allocating fixed size of storage

Contiguous Allocation Memory is allocated in monolithic segments or blocks Public enemy #1: external fragmentation – We can solve this by periodically rearranging the contents of memory

Storage Placement Algorithms Best Fit – Produces the smallest leftover hole – Creates small holes that cannot be used

Storage Placement Algorithms Best Fit – Produces the smallest leftover hole – Creates small holes that cannot be used First Fit – Creates average size holes

Storage Placement Algorithms Best Fit – Produces the smallest leftover hole – Creates small holes that cannot be used First Fit – Creates average size holes Worst Fit – Produces the largest leftover hole – Difficult to run large programs

Storage Placement Algorithms Best Fit – Produces the smallest leftover hole – Creates small holes that cannot be used First Fit – Creates average size holes Worst Fit – Produces the largest leftover hole – Difficult to run large programs First-Fit and Best-Fit are better than Worst-Fit in terms of SPEED and STORAGE UTILIZATION

Exercise Consider a swapping system in which memory consists of the following hole sizes in memory order: 10KB, 4KB, 20KB, 18KB, 7KB, 9KB, 12KB, and 15KB. Which hole is taken for successive segment requests of (a) 12KB, (b) 10KB, (c) 9KB for – First Fit?

Exercise Consider a swapping system in which memory consists of the following hole sizes in memory order: 10KB, 4KB, 20KB, 18KB, 7KB, 9KB, 12KB, and 15KB. Which hole is taken for successive segment requests of (a) 12KB, (b) 10KB, (c) 9KB for – First Fit? 20KB, 10KB and 18KB

Exercise Consider a swapping system in which memory consists of the following hole sizes in memory order: 10KB, 4KB, 20KB, 18KB, 7KB, 9KB, 12KB, and 15KB. Which hole is taken for successive segment requests of (a) 12KB, (b) 10KB, (c) 9KB for – First Fit? 20KB, 10KB and 18KB – Best Fit?

Exercise Consider a swapping system in which memory consists of the following hole sizes in memory order: 10KB, 4KB, 20KB, 18KB, 7KB, 9KB, 12KB, and 15KB. Which hole is taken for successive segment requests of (a) 12KB, (b) 10KB, (c) 9KB for – First Fit? 20KB, 10KB and 18KB – Best Fit? 12KB, 10KB and 9KB

Exercise Consider a swapping system in which memory consists of the following hole sizes in memory order: 10KB, 4KB, 20KB, 18KB, 7KB, 9KB, 12KB, and 15KB. Which hole is taken for successive segment requests of (a) 12KB, (b) 10KB, (c) 9KB for – First Fit? 20KB, 10KB and 18KB – Best Fit? 12KB, 10KB and 9KB – Worst Fit?

Exercise Consider a swapping system in which memory consists of the following hole sizes in memory order: 10KB, 4KB, 20KB, 18KB, 7KB, 9KB, 12KB, and 15KB. Which hole is taken for successive segment requests of (a) 12KB, (b) 10KB, (c) 9KB for – First Fit? 20KB, 10KB and 18KB – Best Fit? 12KB, 10KB and 9KB – Worst Fit? 20KB, 18KB and 15KB

malloc Revisited Free storage is kept as a list of free blocks – Each block contains a size, a pointer to the next block, and the space itself

malloc Revisited Free storage is kept as a list of free blocks – Each block contains a size, a pointer to the next block, and the space itself When a request for space is made, the free list is scanned until a big-enough block can be found – Which storage placement algorithm is used?

malloc Revisited Free storage is kept as a list of free blocks – Each block contains a size, a pointer to the next block, and the space itself When a request for space is made, the free list is scanned until a big-enough block can be found – Which storage placement algorithm is used? If the block is found, return it and adjust the free list. Otherwise, another large chunk is obtained from the OS and linked into the free list

malloc Revisited (continued) typedef long Align;/* for alignment to long */ union header {/* block header */ struct { union header *ptr;/* next block if on free list */ unsigned size;/* size of this block */ } s; Align x;/* force alignment of blocks */ }; typedef union header Header; size points to next free block

Compaction After numerous malloc() and free() calls, our memory will have many holes – Total free memory is much greater than that of any contiguous chunk We can compact our allocated memory – Shift all allocations to one end of memory, and all holes to the other end Temporarily eliminates of external fragmentation

Compaction (example) Lucky that A fit in there! To be sure that there is enough space, we may want to compact at (d), (e), or (f) Unfortunately, compaction is problematic – It is very costly. How much, exactly? – How else can we eliminate external fragmentation?

Paging Divide memory into pages of equal size – We don’t need to assign contiguous chunks – Internal fragmentation can only occur on the last page assigned to a process – External fragmentation cannot occur at all – Need to map contiguous logical memory addresses to disjoint pages

Page Replacement We may not have enough space in physical memory for all pages of every process at the same time. But which pages shall we keep? – Use the history of page accesses to decide – Also useful to know the dirty pages

Page Replacement Strategies It takes two disk operations to replace a dirty page, so: – Keep track of dirty bits, attempt to replace clean pages first – Write dirty pages to disk during idle disk time We try to approximate the optimal strategy but can seldom achieve it, because we don’t know what order a process will use its pages. – Best we can do is run a program multiple times, and track which pages it accesses

Page Replacement Algorithms Optimal: last page to be used in the future is removed first FIFO: First in First Out – Based on time the page has spent in main memory LRU: Least Recently Used – Locality of reference principle again MRU: most recently used = removed first – When would this be useful? LFU: Least Frequently Used – Replace the page that is used least often

Example Physical memory size: 4 pages Pages are loaded on demand Access history: … – Which algorithm does best here? Access history: … – And here?