PA0 due 60 hours. Lecture 4 Memory Management OSTEP Virtualization CPU: illusion of private CPU RAM: illusion of private memory Concurrency Persistence.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

PA0 due today Anyone tried to submit?. Scheduling Workload assumptions Arrive time, run time, I/O, etc. Policies: FIFO, SJF, STCF, RR, MLFQ, and lottery.
Chapter 15 Address Translation Chien-Chung Shen CIS, UD
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 Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
OS Memory Addressing.
CS 311 – Lecture 21 Outline Memory management in UNIX
Memory Management.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Friday, June 30, 2006 "Man's mind, once stretched by a new idea, never regains its original dimensions." - Oliver Wendell Holmes, Jr.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory Management Chapter 5.
Memory Management Five Requirements for Memory Management to satisfy: –Relocation Users generally don’t know where they will be placed in main memory May.
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
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 Lecture 8: Memory Mangement Operating System I Spring 2008.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Example of a Resource Allocation Graph CS1252-OPERATING SYSTEM UNIT III1.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Memory Management Chapter 7.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CE Operating Systems Lecture 14 Memory management.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
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 Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.
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.
Lecture 7 TLB. Virtual Memory Approaches Time Sharing Static Relocation Base Base+Bounds Segmentation Paging.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
CSC 360, Instructor Kui Wu Memory Management I: Main Memory.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Chapter 15 Address Translation Chien-Chung Shen CIS/UD
Virtualization Virtualize hardware resources through abstraction CPU
Chien-Chung Shen CIS/UD
PA1 is out Best by Feb , 10:00 pm Enjoy early
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Lecture 6 Memory Management
The Operating System Memory Manager
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
PA0 is due in 12 hours PA1 will be out in 12 hours
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
CS399 New Beginnings Jonathan Walpole.
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 Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
EECE.4810/EECE.5730 Operating Systems
Presentation transcript:

PA0 due 60 hours

Lecture 4 Memory Management

OSTEP Virtualization CPU: illusion of private CPU RAM: illusion of private memory Concurrency Persistence

Early Systems Operating System (code, data, etc.) Current Program (code, data, etc.) 0KB 64KB max

Multiprogramming and Time Sharing We give the illusion of many virtual CPUs by saving CPU registers to memory when a process isn’t running We give the illusion of many virtual memories by saving memory to disk when a process isn’t running

Space Sharing Memory Operating System (code, data, etc.) (free) Process C (code, data, etc.) Process B (code, data, etc.) (free) Process A (code, data, etc.) (free)

The Abstraction The process address space Process’s view of memory in the system a set of addresses that map to RAM cell private int x; int main(int argc, char *argv[]) { int y; int *z = malloc(1); } Code Data Heap (free) Stack 0KB 1KB 2KB 15KB 16KB

What is the virtualization? Every address generated by a user program is a virtual address The program really isn’t in memory at physical addresses 0 through 16KB

Goals and Mechanism Transparency Efficiency Protection and isolation Hardware-based address translation

Memory Accesses _main: pushq %rbp … movl -0x14(%rbp), %r8d addl $0x1, %r8d movl %r8d, -0x14(%rbp) … x = x + 1; …

Memory Accesses %rip starts with 0x10 %rbp starts with 0x200 0x10 movl -0x14(%rbp), %r8d 0x14 addl $0x1, %r8d 0x17 movl %r8d, -0x14(%rbp) Fetch inst at 0x10 Exec inst, load from 0x186 Fetch inst at 0x14 Exec inst, no memory access Fetch inst at 0x17 Exec inst, store to 0x186

How to Run Multiple Processes Time Sharing Static Relocation Base Base+Bounds Segmentation

Static Relocation 0x10 movl -0x14(%rbp), %r8d 0x14 addl $0x1, %r8d 0x17 movl %r8d, -0x14(%rbp) Rewrite each program before loading it as a process 0x1010 movl -0x14(%rbp), %r8d 0x1014 addl $0x1, %r8d 0x1017 movl %r8d, -0x14(%rbp) 0x3010 movl -0x14(%rbp), %r8d 0x3014 addl $0x1, %r8d 0x3017 movl %r8d, -0x14(%rbp)

(free) code, data heap (free) stack (free) code, data heap (free) stack (free) 0KB 4KB 8KB 12KB 16KB 0x1010 movl -0x14(%rbp), %r8d 0x1014 addl $0x1, %r8d 0x1017 movl %r8d, -0x14(%rbp) 0x3010 movl -0x14(%rbp), %r8d 0x3014 addl $0x1, %r8d 0x3017 movl %r8d, -0x14(%rbp)

How to Run Multiple Processes Time Sharing Static Relocation Base Base+Bounds Segmentation

Base Idea: translate virtual addresses to physical by adding a fixed offset each time. Store offset in a base register. Each process has a different value in the base register when running. This is a “dynamic relocation” technique

(free) code, data heap (free) stack (free) code, data heap (free) stack (free) 0KB 1KB P1 2KB 4KB P2 5KB physical address = virtual address + base P1: load 100, R1 -> load 1124, R1 P2: load 100, R1 -> load 4196, R1 P2: load 1000, R1 -> load 5096, R1

Memory Accesses %rip starts with 0x10 %rbp starts with 0x200 0x10 movl -0x14(%rbp), %r8d 0x14 addl $0x1, %r8d 0x17 movl %r8d, -0x14(%rbp) Fetch inst at 0x10 Exec inst, load from 0x186 Fetch inst at 0x14 Exec inst, no memory access Fetch inst at 0x17 Exec inst, store to 0x186

(free) code, data heap (free) stack (free) code, data heap (free) stack (free) 0KB 1KB P1 2KB 4KB P2 5KB physical address = virtual address + base P1: load 100, R1 -> load 1124, R1 P2: load 100, R1 -> load 4196, R1 P2: load 1000, R1 -> load 5096, R1 P1: store R1, > store R1, 4096

Base+Bounds Memory Management Unit (MMU) Now with base and bounds registers Will add more into it Who should do translation with base register? (1) process, (2) OS, or (3) HW Who should modify the base register? (1) process, (2) OS, or (3) HW

(free) code, data heap (free) stack (free) code, data heap (free) stack (free) 0KB 1KB P1 2KB 4KB P2 5KB P1: load 100, R1 -> load 1124, R1 P2: load 100, R1 -> load 4196, R1 P2: load 1000, R1 -> load 5096, R1 P1: store R1, > store R1, 4096 an exception, interrupt OS!

Hardware Requirements Privileged mode Base/bounds registers Ability to translate virtual addresses and check if within bounds Privileged instruction(s) to update base/bounds Privileged instruction(s) to register exception handlers Ability to raise exceptions

Operating System Issues Memory management Generally manage memory via free list Base/bounds management Exception handling

(free) code, data heap (free) stack (free) code, data heap (free) stack (free) 0KB 1KB P1 2KB 4KB P2 5KB P1: load 100, R1 -> load 1124, R1 P2: load 100, R1 -> load 4196, R1 P2: load 1000, R1 -> load 5096, R1 P1: store R1, > store R1, 4096 an exception, interrupt OS! Problems? Internal fragmentation Virtual space size constraint

How to Run Multiple Processes Time Sharing Static Relocation Base Base+Bounds Segmentation

Idea: generalize base+bounds One base+bounds pair for each segment Requires more registers! Resize segments as needed

Virtual Address Break virtual addresses into two parts one part indicates segment one part indicates offset within segment If an address has 14 bits, 2 for segment, 12 for offset 0: code+data 1: heap 2: stack

1 // get top 2 bits of 14-bit VA 2 Segment = (VirtualAddress & SEG_MASK) >> SEG_SHIFT 3 // now get offset 4 Offset = VirtualAddress & OFFSET_MASK 5 if (Offset >= Bounds[Segment]) 6 RaiseException(PROTECTION_FAULT) 7 else 8 PhysAddr = Base[Segment] + Offset 9 Register = AccessMemory(PhysAddr)

(free) heap (free) stack (free) 0KB 1KB 2KB 3KB 4KB 5KB Virtual 0x1010 0x1100 0x1400 Physical 1KB+16 1kB+256 Interrupt OS Segment Base Size Code Heap 1KB 1KB Stack

(free) heap (free) stack (free) 0KB 1KB 2KB 3KB 4KB 5KB Virtual 0x2C00 Physical 4KB Segment Base Size Positive? Code 1 Heap 1KB 1KB 1 Stack 5KB 1KB 0

Support for Code Sharing Idea: make base/bounds for the code of several processes point to the same physical mem Careful: need extra protection! Adding protection bits Segment Base Size Positive? Protection Code 1 Read-Execute Heap 1KB 1KB 1 Read-Write Stack 5KB 1KB 0 Read-Write

Space Management Generally manage memory via free list Free chunks are scattered throughout memory Allocate memory from a chunk able to accommodate it Maintains information about allocated and free regions Policies: First-fit: Allocate the first chunk that is big enough Best-fit: Allocate the smallest chunk that is big enough Worst-fit: Allocate the largest chunk; must also search entire list Next-fit: Allocate the second chunk that is big enough Segregated Lists, Buddy Allocation

Fragmentation External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used Reduce external fragmentation by compaction Shuffle memory contents to place all free memory together in one large block Compaction is possible only if relocation is dynamic, and is done at execution time

Segmentation Pros? supports sparse address space code sharing fine grained protection Cons? external fragmentation Next: paging