Dynamic Memory Allocation

Slides:



Advertisements
Similar presentations
Chris Riesbeck, Fall 2007 Dynamic Memory Allocation Today Dynamic memory allocation – mechanisms & policies Memory bugs.
Advertisements

Note on malloc() and slab allocation CS-502 (EMC) Fall A Note on malloc() and Slab Allocation CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
The Linux Kernel: Memory Management
Kernel memory allocation
Chapter 12. Kernel Memory Allocation
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
7. Physical Memory 7.1 Preparing a Program for Execution
Allocating Memory.
Ken Birman. What’s the goal? Each program you build consists of Code you wrote Pre-existing libraries your code accesses In early days, the balance.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
OS Fall’02 Memory Management Operating Systems Fall 2002.
Memory Management Policies: UNIX
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Memory Management Chapter 5.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 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.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Memory Allocation CS Introduction to Operating Systems.
The memory allocation problem Define the memory allocation problem Memory organization and memory allocation schemes.
Tutorial 6 Memory Management
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
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.
Memory Management 1 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
Operating Systems CMPSC 473 Virtual Memory Management (4) November – Lecture 22 Instructor: Bhuvan Urgaonkar.
Chapter 4 Memory Management Virtual Memory.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
The buddy memory allocation algorithm Παρουσίαση : Δρ. Αναγνωστό π ουλος Χρήστος.
Chapter 17 Free-Space Management Chien-Chung Shen CIS, UD
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Processes and Virtual Memory
Memory Management CS Spring Overview Partitioning, Segmentation, and Paging External versus Internal Fragmentation Logical to Physical Address.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
Programs and Processes. The Virtual Address Space A typical process VAS space includes: user regions in the lower half V->P mappings specific to each.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
Virtual Memory – Managing Physical Memory
CS 241 Discussion Section (2/9/2012). MP2 continued Implement malloc, free, calloc and realloc Reuse free memory – Sequential fit – Segregated fit.
CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)
CSE 351 Dynamic Memory Allocation 1. Dynamic Memory Dynamic memory is memory that is “requested” at run- time Solves two fundamental dilemmas: How can.
Memory Management Chapter 5 Advanced Operating System.
External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your.
Memory Management I: Dynamic Storage Allocation Oct 8, 1998 Topics User-level view Policies Mechanisms class14.ppt Introduction to Computer Systems.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
Memory Management Chapter 7.
Chapter 17 Free-Space Management
William Stallings Computer Organization and Architecture
Section 10: Last section! Final review.
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.
CS Introduction to Operating Systems
Segmentation Lecture November 2018.
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.
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 32 Syed Mansoor Sarwar
Chapter 8: Memory management
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Lecture 7: Flexible Address Translation
Address Spaces Physical Memory Virtual Memory Process Memory Layout
Buddy Allocation CS 161: Lecture 5 2/11/19.
COMP755 Advanced Operating Systems
CSE 542: Operating Systems
Page Main Memory.
Presentation transcript:

Dynamic Memory Allocation CSCE 410/611 Dynamic Memory Allocation Memory Allocation: where? Fragmentation external vs. internal Implementation Approaches Naïve vs. Buddy System Dynamic Memory Management

Dynamic Memory Allocation – when? CSCE 410/611 Dynamic Memory Allocation – when? When does new memory get allocated in the kernel? New process gets created (fork()) New program gets loaded into memory (execve()) Process stack grows What about thread stacks? Process expands heap (malloc()) Process “creates” (attaches to) shared memory segment (shmat()) Map a file to memory (mmap()) Note: These memory segments “belong to” the user! For internal memory management OS uses Slab Allocator. Dynamic Memory Management

libraries & dev.drivers CSCE 410/611 Memory Allocation memory space user program area libraries & dev.drivers Monitor Job1 Job2 Job3 Job4 Dynamic Memory Management

Memory Allocation X First Fit Worst Fit Best Fit CSCE 410/611 Dynamic Memory Management

(External) Fragmentation CSCE 410/611 (External) Fragmentation allocate() ?! Dynamic Memory Management

(Internal) Fragmentation CSCE 410/611 (Internal) Fragmentation Internal Fragmentation Dynamic Memory Management

(Internal) Fragmentation CSCE 410/611 (Internal) Fragmentation Dynamic Memory Management

Memory Allocation: Data Structures CSCE 410/611 Memory Allocation: Data Structures global memory descriptor next memory regions start end memory space start end next free list Dynamic Memory Management

(Binary) Buddy System Allocation CSCE 410/611 (Binary) Buddy System Allocation Maintain multiple free lists, one for each power-of-2 size. Allocation: Increase size of request to next power of 2*. Look up segment in free lists. If exists, allocate. If none exists, split next larger segment in half, put first half (the “buddy”) on free list, and return second half. Harry Markowitz 1927- 1990 Nobel Memorial Prize in Economics (nobelprize.org) De-Allocation: Return segment to free list. Check if buddy is free. If so, coalesce. References: Donald Knuth: The Art of Computer Programming Volume 1: Fundamental Algorithms. Second Edition (Reading, Massachusetts: Addison-Wesley, 1997), pp. 435-455. ISBN 0-201-89683-4 Dynamic Memory Management

How to find a buddy? The buddy of each block can be found with an Exclusive OR of the block’s address and the block’s size. Ex) 32KB size = 1000 0000 0000 0000 First 32KB Block = 0000 0000 0000 0000 XOR 1000 0000 0000 0000

Allocation at Different Levels user level explicit user-level allocation: malloc(size) allocate virtually contiguous sequence of bytes at user level user-level library kernel level byte-sized allocations: kmalloc(size, gfp_mask) allocate physically contiguous sequence of bytes vmalloc(size, gfp_mask) allocate virtually contiguous sequence of bytes Slab Allocator (+ caching) alloc_pages() and __get_free_pages() allocate frames or pages, at low level useful to allocate contiguous frames/pages. Buddy System!

Summary: Dynamic Memory Allocation CSCE 410/611 Summary: Dynamic Memory Allocation Memory Allocation Internal and External Fragmentation Implementation Approaches Free Lists Buddy System Dynamic Memory Management