1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Basic Memory Management Monoprogramming Protection Swapping Overlaying OS space User space.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Virtual Memory. Hierarchy Cache Memory : Provide invisible speedup to main memory.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
4/14/2017 Discussed Earlier segmentation - the process address space is divided into logical pieces called segments. The following are the example of types.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Memory Management.
Memory Management (continued) CS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System.
Chapter 3 Memory Management
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.
CS 333 Introduction to Operating Systems Class 9 - Memory Management
Thrashing and Memory Management
Chapter 7: Main Memory CS 170, Fall Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Memory Management April 28, 2000 Instructor: Gary Kimura.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Memory Allocation CS Introduction to Operating Systems.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
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.
COS 598: Advanced Operating System. Operating System Review What are the two purposes of an OS? What are the two modes of execution? Why do we have two.
1 Memory Management Chapter Basic memory management 4.2 Swapping (εναλλαγή) 4.3 Virtual memory (εικονική/ιδεατή μνήμη) 4.4 Page replacement algorithms.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Operating Systems Memory management. Memory Management List of Topics 1. Memory Management 2. Memory In Systems Design 3. Binding Times 4. Introduction.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
Subject: Operating System.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Operating Systems CMPSC 473 Virtual Memory Management (4) November – Lecture 22 Instructor: Bhuvan Urgaonkar.
Chapter 4 Memory Management Virtual Memory.
1 Memory Management Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
1 Some Real Problem  What if a program needs more memory than the machine has? —even if individual programs fit in memory, how can we run multiple programs?
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Memory Management & Virtual Memory. Hierarchy Cache Memory : Provide invisible speedup to main memory.
Memory Management One of the most important OS jobs.
Virtual Memory Chapter 7.4.
CS703 - Advanced Operating Systems
Chapter 8: Main Memory.
CS Introduction to Operating Systems
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
CS399 New Beginnings Jonathan Walpole.
CPSC 457 Operating Systems
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
Lecture 3: Main Memory.
CSE451 Memory Management Introduction Autumn 2002
CSE 451: Operating Systems Autumn 2005 Memory Management
Operating System Chapter 7. Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Chapter 8: Memory Management strategies
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSCI 380: Operating Systems William Killian
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Memory Management CSE451 Andrew Whitaker.
Paging and Segmentation
Presentation transcript:

1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof. Mark Corner and Prof. Emery Berger’s OS course at Umass Amherst Assistant Professor, University of Maryland Baltimore County

2 Announcements Project 2 progress report due on Nov. 9th Homework 3 will be out soon (hopefully before the end of this week)

Quick Activity How much mem does a page table need? –4kB pages, 32 bit address space –page table entry (PTE) uses 4 bytes 2^32/2^12*4=2^22 bytes=4MB –Is this a problem? –Isn’t this per process? –What about a 64 bit address space? Any ideas how to fix this?

4 A B A B Locality Most programs obey 90/10 “rule” –90% of time spent accessing 10% of memory Exploit this rule: –Only keep “live” parts of process in memory

Multi-Level Page Tables Use a multi-level page table AA A Level 0 Table Level 1 Table

Quick Activity How much mem does a page table need? –4kB pages, 32 bit address space –Two level page table –20bits = 10 bits each level –page table entry (PTE) uses 4 bytes –Only first page of program is valid 2^10*4+2^10*4=2^13 bytes=8kB Isn’t this slow?

7 Translation Lookaside Buffer (TLB) TLB: fast, fully associative memory –Caches page table entries –Stores page numbers (key) and frame (value) in which they are stored Assumption: locality of reference –Locality in memory accesses = locality in address translation TLB sizes: 8 to 2048 entries –Powers of 2 simplifies translation of virtual to physical addresses

Linear Address in Linux Uses a three-level paging strategy that works well for 32-bit and 64-bit systems Linear address broken into four parts:

Three-level Paging in Linux

Inverted Page Tables Maintain one global page table for all processes

Swap Space

12 Page table entry and page faults

13 User-space memory allocation in the heap (malloc) What happens int *arg = (int *)malloc(sizeof(int))  Programs ask memory manager –to allocate/free objects (or multiple pages)  Memory manager asks OS –to allocate/free pages (or multiple pages) User Program Allocator(libc) OS Pages (mmap,brk) malloc, free

14 User-space memory allocation in the heap (malloc) kernel Text region stack sbrk(0) sbrk(100)brk sbrk(100) brk sbrk(100) brk sbrk(0) allocated A demo?

15 User-space memory allocation in the heap (malloc) kernel Text region stack sbrk(0) brk free allocated free Memory allocator keeps track of the free blocks

16 Few Scenarios kernel Text region stack sbrk(0) free allocated malloc(200) Waste of resources brk allocated

17 Coalescing kernel Text region stack sbrk(0) free allocated malloc(200) Waste of resources brk

18 Jobs of a memory allocator like malloc  Manage heap space in virtual memory –Use sbrk to ask for more memory from OS  Coalescing  Keep track of free blocks  Merge them together when adjacent blocks are free  Malloc needs to be really fast  Decide which free block to allocate  Lets take a look at the data structure that is used for implementing malloc and free

19 Memory layout of the heap this linked list can be ordered in different ways

20 Selecting the free block to allocate: Fragmentation Intuitively, fragmentation stems from “breaking” up heap into unusable spaces –More fragmentation = worse utilization External fragmentation –Wasted space outside allocated objects Internal fragmentation –Wasted space inside an object

21 Classical Algorithms First-fit –find first chunk of desired size

22 Classical Algorithms Best-fit –find chunk that fits best Minimizes wasted space

23 Classical Algorithms Worst-fit –find chunk that fits worst –name is a misnomer! –keeps large holes around Reclaim space: coalesce free adjacent objects into one big object

24 In-class Discussion