Memory Management Today Basic memory management Swapping Kernel memory allocation Next Time Virtual memory.

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management Basic memory management Swapping
Advertisements

Part IV: Memory Management
Kernel memory allocation
Chapter 12. Kernel Memory Allocation
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Fixed/Variable Partitioning
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Operating System Support Focus on Architecture
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management 2010.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Computer Organization and Architecture
Avishai Wool lecture Introduction to Systems Programming Lecture 6 Memory Management.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
1 Chapter 3.1 : Memory Management Storage hierarchy Storage hierarchy Important memory terms Important memory terms Earlier memory allocation schemes Earlier.
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Computer Organization and Architecture Operating System Support Chapter 8.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Review of Memory Management, Virtual Memory CS448.
Memory Management By: Omar A. Cruz Salgado ICOM 5007 Sec. 121.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Dynamic Partition Allocation Allocate memory depending on requirements Partitions adjust depending on memory size Requires relocatable code –Works best.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
1 Memory Management Chapter Basic memory management 4.2 Swapping (εναλλαγή) 4.3 Virtual memory (εικονική/ιδεατή μνήμη) 4.4 Page replacement algorithms.
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 – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
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.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
Operating Systems COMP 4850/CISG 5550 Basic Memory Management Swapping Dr. James Money.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
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 Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only storage.
CHAPTER 3-1, 3-2 MEMORY MANAGEMENT. MEMORY HIERARCHY Small amount of expensive, fast, volatile cache Larger amount of still fast, but slower, volatile.
1 Memory Management Adapted From Modern Operating Systems, Andrew S. Tanenbaum.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Memory Management One of the most important OS jobs.
Chapter 2 Memory and process management
From Monoprogramming to multiprogramming with swapping
Chapter 8: Main Memory.
Memory Allocation The main memory must accommodate both:
CSC 322 Operating Systems Concepts Lecture - 12: by
Chapter 9 – Real Memory Organization and Management
William Stallings Computer Organization and Architecture
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Multistep Processing of a User Program
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
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Memory Management (1).
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
Presentation transcript:

Memory Management Today Basic memory management Swapping Kernel memory allocation Next Time Virtual memory

Midterm results Average Median 70.5 Std dev EECS 343 Operating Systems Northwestern University

Schedule for the remaining weeks 11/04 Memory mgmt. –Project 3 out 11/06 Memory mgmt –Homework 3 out 11/11 Virtual mem 11/13 Virtual mem –Homework 3 in 11/17 Project 3 In 11/18 Mass-storage & I/O Systems 11/20 File systems I/F –Homework 4 out –Project 4 out 11/25 File systems impl. 11/27 Thanksgiving 12/02 Protection & security –Project 4 in 12/03 Homework 4 in 12/05 Research in OS & Review –Homework 5 in class 12/09 Final 3 EECS 343 Operating Systems Northwestern University

4 Memory management Ideal memory for a programmer –Large –Fast –Non volatile –Cheap Nothing like that → memory hierarchy –Small amount of fast, expensive memory – cache –Some medium-speed, medium price main memory –Gigabytes of slow, cheap disk storage Memory manager handles the memory hierarchy

Basic memory management Simplest memory abstraction – no abstraction at all –Early mainframes (before ‘60), minicomputers (before ‘70) and PCs (before ‘80) –Only one program running at a time –Some alternatives for organizing memory 5 EECS 343 Operating Systems Northwestern University BIOS MSDOS Mainframes & minicomputers Some palmtops & embedded systems Early PCs

6 Multiprogramming w/ fixed partitions Multiprogramming – when one process is waiting for I/O, another one can use the CPU Two simple approaches –Split memory in n parts (possible != sizes) –Single or separate input queues for each partition –~IBM OS/360 – MFT: Multiprogramming with Fixed number of Tasks EECS 343 Operating Systems Northwestern University

7 Two problems w/ multiprogramming Relocation and protection –Don’t know where program will be loaded in memory Address locations of variables & code routines –Keep a process out of other processes’ partitions IBM OS/MFT - modify instructions on the fly; split memory into 2KB blocks & add key/code combination Use base and limit values (CDC 6600 & Intel 8088) –address locations + base value → physical address EECS 343 Operating Systems Northwestern University

8 Swapping Not enough memory for all processes? –Swapping Simplest Bring each process entirely Move another one to disk Compatible Time Sharing System (CTSS) – a uniprogrammed swapping system –Virtual memory (your other option) Allow processes to be only partially in main memory EECS 343 Operating Systems Northwestern University Operating System User Space Main memoryBacking store Swap out Swap in Process P 1 Process P 2

9 Swapping How is different from MFT? –Much more flexible Size & number of partitions changes dynamically –Higher memory utilization, but harder memory management Swapping in/out creates multiple holes –Fragmentation … Operating System A A B A B C B C B C D C D C D A Space for A is available, but not as a single piece. EECS 343 Operating Systems Northwestern University

10 Fragmentation External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous Reduce external fragmentation by compaction –Shuffle contents to group free memory as one block –Possible only if relocation is dynamic; done at execution time –I/O problem Latch job in memory while it is involved in I/O Do I/O only into OS buffers Too expensive (256MB machine, moving at 4B per 40 nanosec. ~ 2.7sec!) EECS 343 Operating Systems Northwestern University

11 How much memory to allocate? If process’ memory doesn’t grow – easy In real world, memory needs change dynamically: –Swapping to make space? –Allocate more space to start with Internal Fragmentation – leftover memory is internal to a partition –Remember what you used when swapping More than one growing area per processes –Stack & data segment –If need more, same as before EECS 343 Operating Systems Northwestern University

12 Memory management With dynamically allocated memory –OS must keep track of allocated/free memory –Two general approaches - bit maps and linked lists Bit maps –Divide memory into allocation units –For each unit, a bit in the bitmap –Design issues - Size of allocation unit The smaller the size, the larger the bitmap The larger the size, the bigger the waste –Simple, but slow – find a big enough chunk? EECS 343 Operating Systems Northwestern University

13 Memory management with lists Linked list of allocated/free space List ordered by address Double link will make your life easier –Updating when a process is swapped out or terminates Keeping track of processes and holes in the same list PXPPHP PXHPHH PXHPHH XHHHHH EECS 343 Operating Systems Northwestern University

14 Picking a place – different algorithms First fit – simple and fast Next fit - ~ First fit but start where it left off –Worst performance than First fit Best fit – try to waste the least –More waste in tiny holes! Worst fit – try to “waste” the most –Not too good either Speeding things up –Two lists (free and allocated) – slows down deallocation –Order the hole list – first fit ~ best fit –Use the same holes to keep the list –Quick fit – list of commonly used hole sizes N lists for N different common sizes (4KB, 8KB, …) Allocation is quick, merging is expensive EECS 343 Operating Systems Northwestern University

15 Kernel memory allocation Most OS manage memory as set of fixed-size pages Kernel maintains a list of free pages Page-level allocator has –Two main routines: e.g get_page() & freepage() in SVR4 –Two main clients: Paging system & KMA Network Buffers Proc strutcures inodes, file descriptors User processes Block buffer cache Page-level allocator Kernel memory allocator Paging system Physical memory Paging system Provides odd-size buffers to various kernel subsystems EECS 343 Operating Systems Northwestern University

16 Kernel memory allocation KMA’s common users –The pathname translation routine –Proc structures, vnodes, file descriptor blocks, … Since requests << page → page-level allocator is inappropriate KMA & the page-level allocator –Pre-allocates part of memory for the KMA –Allow KMA to request memory –Allow two-way exchange with the paging system Evaluation criteria –Utilization memory – physical memory is limited after all –Speed – it is used by various kernel subsystems –Simple API –Allow a two-way exchange with page-level allocator EECS 343 Operating Systems Northwestern University

17 KMA – Resource map allocator Resource map – a set of pairs Initially the pool is described by a single pair … after a few exchanges … a list of entries per contiguous free regions Allocate requests based on –First fit, Best fit, Worst fit A simple interface offset_t rmalloc(size); void rmfree(base, size); 0, 1024 rmalloc(256) 256, 768 rmalloc(320) 576,448 rmfree(256,128) 256,128 EECS 343 Operating Systems Northwestern University

18 Resource map allocator Pros –Easy to implement –Not restricted to memory allocation –It avoid waste (although normally rounds up requests sizes for simplicity) –Client can release any part of the region –Allocator coalesces adjacent free regions Cons –After a while maps ended up fragmented – low utilization –Higher fragmentation, longer map –Map may need an allocator for its own entries How would you implement it? –To coalesce regions, keep map sorted – expensive –Linear search to find a free region large enough EECS 343 Operating Systems Northwestern University

19 KMA – Simple power-of-two free list A set of free lists Each list keeps free buffers of a particular size (2 x ) Each buffer has one word header –Pointer to next free buffer, if free or to –Pointer to free list (or size), if allocated EECS 343 Operating Systems Northwestern University

20 KMA – Simple power-of-two free list Allocating(size) –allocating (size + header) rounded up to next power of two –Return pointer to first byte after header Freeing doesn’t require size as argument –Move pointer back header-size to access header –Put buffer in list Initialize allocator by preallocating buffers or get pages on demand; if it needs a buffer from an empty list … –Block request until a buffer is released –Satisfy request with a bigger buffer if available –Get a new page from page allocator

21 Power-of-two free lists Pros –Simple and pretty fast (avoids linear search) –Familiar programming interface (malloc, free) –Free does not require size; easier to program with Cons –Rounding means internal fragmentation –As many requests are power of two and we loose header; a lot of waste –No way to coalesce free buffers to get a bigger one –Rounding up may be a costly operation EECS 343 Operating Systems Northwestern University

22 Coming up … The nitty-gritty details of virtual memory … EECS 343 Operating Systems Northwestern University

23 Modeling multiprogramming CPU utilization & multiprogramming –Utilization as a function of # of processes in memory –If process spends p% waiting for I/O Probability all processes waiting for I/O at once: p n CPU Utilization 1- p n Degree of multiprogramming EECS 343 Operating Systems Northwestern University

Degree of multiprogramming Performance of a MP system Computer w/ 32MB 16MB for OS & 4 processes 4MB per process) With 80% avg. waiting time CPU Utilization – 1 – = 1 – 0.41 = 0.6 : 60% Add 16MB – 4 more user processes CPU Utilization – 1 – = 0.83 : 83% … 38% increase Add 16MB – 4 more user processes CPU Utilization – 1 – = 0.93 : 93% … 12% increase EECS 343 Operating Systems Northwestern University