CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)

Slides:



Advertisements
Similar presentations
Dynamic Memory Management
Advertisements

Chapter 6: Memory Management
The Linux Kernel: Memory Management
Kernel memory allocation
Chapter 12. Kernel Memory Allocation
Free Space and Allocation Issues
Memory Management Chapter 7.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Chapter 9: Searching, Sorting, and Algorithm Analysis
7. Physical Memory 7.1 Preparing a Program for Execution
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
5/23/20151 GC16/3011 Functional Programming Lecture 19 Memory Allocation Techniques.
Sorting Chapter Sorting Consider list x 1, x 2, x 3, … x n We seek to arrange the elements of the list in order –Ascending or descending Some O(n.
Lab 3: Malloc Lab. “What do we need to do?”  Due 11/26  One more assignment after this one  Partnering  Non-Honors students may work with one other.
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Dynamic memory allocation and fragmentation Seminar on Network and Operating Systems Group II.
Memory Management Memory Areas and their use Memory Manager Tasks:
1 Optimizing Malloc and Free Professor Jennifer Rexford
Memory Management A memory manager should take care of allocating memory when needed by programs release memory that is no longer used to the heap. Memory.
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.
Memory Management Chapter 5.
Memory Allocation CS Introduction to Operating Systems.
The memory allocation problem Define the memory allocation problem Memory organization and memory allocation schemes.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Dynamic Memory Allocation Questions answered in this lecture: When is a stack appropriate? When is a heap? What are best-fit, first-fit, worst-fit, and.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Storage Management - Chap 10 MANAGING A STORAGE HIERARCHY on-chip --> main memory --> 750ps - 8ns ns. 128kb - 16mb 2gb -1 tb. RATIO 1 10 hard disk.
Memory Management II: Dynamic Storage Allocation Mar 7, 2000 Topics Segregated free lists –Buddy system Garbage collection –Mark and Sweep –Copying –Reference.
CS 241 Discussion Section (11/11/--11). Outline Good Ideas for MP7 Socket Programming Hypertext Transfer Protocol (HTTP)
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 Παρουσίαση : Δρ. Αναγνωστό π ουλος Χρήστος.
Writing You Own malloc() March 29, 2003 Topics Explicit Allocation Data structures Mechanisms Policies class19.ppt “The course that gives CMU its.
Memory Management Problem: Records (of various lengths) need to be stored. Model: A big array of space to store them, managed by a memory manager. Like.
11/26/2015IT 3271 Memory Management (Ch 14) n Dynamic memory allocation Language systems provide an important hidden player: Runtime memory manager – Activation.
Chapter 17 Free-Space Management Chien-Chung Shen CIS, UD
CS 241 Discussion Section (11/17/2011). Outline Review of MP7 MP8 Overview Simple Code Examples (Bad before the Good) Theory behind MP8.
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 -Memory allocation -Garbage collection.
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)
Dynamic Memory Allocation II
University of Washington Today More memory allocation!
CS 241 Discussion Section (2/9/2012). MP2 continued Implement malloc, free, calloc and realloc Reuse free memory – Sequential fit – Segregated fit.
Lecture 7 Page 1 CS 111 Summer 2013 Dynamic Domain Allocation A concept covered in a previous lecture We’ll just review it here Domains are regions of.
1 Dynamic Memory Allocation (II) Implementation. 2 Outline Implementation of a simple allocator Explicit Free List Segregated Free List Suggested reading:
University of Washington Implementation Issues How do we know how much memory to free given just a pointer? How do we keep track of the free blocks? How.
CS4432: Database Systems II
External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
Memory Management I: Dynamic Storage Allocation Oct 8, 1998 Topics User-level view Policies Mechanisms class14.ppt Introduction to Computer Systems.
Chapter 7 Memory Management
Chapter 17 Free-Space Management
Storage Allocation Mechanisms
Section 10: Memory Allocation Topics
Memory Management Memory Areas and their use Memory Manager Tasks:
Day 19 Memory Management.
Dynamic memory allocation and fragmentation
Partitioned Memory Allocation
Operating Systems (CS 340 D)
Memory Management Memory Areas and their use Memory Manager Tasks:
Optimizing Malloc and Free
CS703 - Advanced Operating Systems
Binding Times Binding is an association between two things Examples:
Operating System Chapter 7. Memory Management
Presentation made by Steponas Šipaila
Memory Management Memory Areas and their use Memory Manager Tasks:
CS703 - Advanced Operating Systems
Presentation transcript:

CS 241 Discussion Section (12/1/2011)

Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation) – Coalesce Make bigger chunks (avoid external fragmentation)

Basic Allocator Mechanisms Sequential fits (implicit or explicit single free list) – best fit, first fit, or next fit placement Tradeoffs – Expand: No fit – Split: Threshold – Coalesce: Immediate or Deferred

Basic allocator mechanisms Segregated free lists – simple segregated storage -- separate heap for each size class – segregated fits -- separate linked list for each size class Tradeoffs – Expand: No big blocks – Split: No “right” sized blocks – Coalesce: Immediate or Deferred

Segregate Storage Each size “class” has its own collection of blocks Often have separate collection for every small size (2,3,4,…) FAST For larger sizes typically have a collection for each power of 2 EFFICIENT

Simple segregated storage Separate heap and free list for each size class No splitting To allocate a block of size n: – if free list for size n is not empty, allocate first block on list (note, list can be implicit or explicit) – if free list is empty, get a new page create new free list from all blocks in page allocate first block on list – constant time To free a block: – Add to free list – If page is empty, return the page for use by another size (optional) Tradeoffs: – fast, but can fragment badly

Segregated fits Array of free lists, each one for some size class To allocate a block of size n: – search appropriate free list for block of size m > n – if an appropriate block is found: split block and place fragment on appropriate list (optional) – if no block is found, try next larger class – repeat until block is found To free a block: – coalesce and place on appropriate list (optional) Tradeoffs – faster search than sequential fits (i.e., log time for power of two size classes) – controls fragmentation of simple segregated storage – coalescing can increase search times deferred coalescing can help

Buddy systems Special case of segregated fits. – all blocks are power of two sizes Basic idea: – Heap is 2 m words – Maintain separate free lists of each size 2 k, 0 <= k <= m. – Requested block sizes are rounded up to nearest power of 2. – Originally, one free block of size 2 m.

Buddy systems (cont) To allocate a block of size 2 k : – Find first available block of size 2 j s.t. k <= j <= m. – if j == k then done. – otherwise recursively split block until j == k. – Each remaining half is called a “buddy” and is placed on the appropriate free list 2m2m buddy

Buddy systems (cont) To free a block of size 2 k – continue coalescing with buddies while the buddies are free buddy Block to free buddy Not free, done Added to appropriate free list

Buddy systems (cont) Key fact about buddy systems: – given the address and size of a block, it is easy to compute the address of its buddy – e.g., block of size 32 with address xxx...x00000 has buddy xxx...x10000 Tradeoffs: – fast search and coalesce – subject to internal fragmentation

Internal fragmentation Internal fragmentation is wasted space inside allocated blocks: – minimum block size larger than requested amount e.g., due to minimum free block size, free list overhead – policy decision not to split blocks e.g., buddy system Much easier to define and measure than external fragmentation.

Other Sources of Wisdom Many implementations and algorithms online… All work should be your own! Good Luck