Dynamic memory allocation and fragmentation Seminar on Network and Operating Systems Group II.

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
Quick Review of Apr 10 material B+-Tree File Organization –similar to B+-tree index –leaf nodes store records, not pointers to records stored in an original.
File Systems.
KERNEL MEMORY ALLOCATION Unix Internals, Uresh Vahalia Sowmya Ponugoti CMSC 691X.
Fixed/Variable Partitioning
7. Physical Memory 7.1 Preparing a Program for Execution
Allocating Memory.
5/23/20151 GC16/3011 Functional Programming Lecture 19 Memory Allocation Techniques.
OS Fall’02 Memory Management Operating Systems Fall 2002.
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Memory Management Memory Areas and their use Memory Manager Tasks:
CSCI2413 Lecture 5 Operating Systems Memory Management 1 phones off (please)
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
Chapter 3.1 : Memory Management
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.
Computer Organization and Architecture
Memory Management Operating Systems - Spring 2003 Gregory (Grisha) Chokler Ittai Abraham Zinovi Rabinovich.
1 Chapter 3.1 : Memory Management Storage hierarchy Storage hierarchy Important memory terms Important memory terms Earlier memory allocation schemes Earlier.
Memory Allocation CS Introduction to Operating Systems.
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 9: Memory Management Memory management is an OS activity which controls distribution of memory among processes. The part of the OS that manages.
1. Memory Manager 2 Memory Management In an environment that supports dynamic memory allocation, the memory manager must keep a record of the usage of.
Chapter 4 Memory Management.
Memory Management Techniques
Memory Management Chapter 7.
Subject: Operating System.
1 Memory Management Requirements of memory management system to provide the memory space to enable several processes to execute concurrently to provide.
Dynamic Storage Allocation Bradley Herrup CS 297 Security and Programming Languages.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
Operating System Concepts and Techniques Lecture 8
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.
CS 241 Discussion Section (11/17/2011). Outline Review of MP7 MP8 Overview Simple Code Examples (Bad before the Good) Theory behind MP8.
I MPLEMENTING FILES. Contiguous Allocation:  The simplest allocation scheme is to store each file as a contiguous run of disk blocks (a 50-KB file would.
Memory Management -Memory allocation -Garbage collection.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Mono an multiprogramming.
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.
Dynamic Memory Allocation II
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)
Lecture Topics: 12/1 File System Implementation –Space allocation –Free Space –Directory implementation –Caching Disk Scheduling File System/Disk Interaction.
Chapter 5 Record Storage and Primary File Organizations
External fragmentation in a paging system Use paging circuitry to map groups of noncontiguous free pages into logically contiguous addresses (remap your.
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.
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 One of the most important OS jobs.
Chapter 17 Free-Space Management
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
Day 18 Memory Management.
Memory Management Memory Areas and their use Memory Manager Tasks:
Main Memory Management
Optimizing Malloc and Free
CS Introduction to Operating Systems
So far… Text RO …. printf() RW link printf Linking, loading
Memory Management (1).
Presentation made by Steponas Šipaila
Memory Management Memory Areas and their use Memory Manager Tasks:
CS703 - Advanced Operating Systems
Presentation transcript:

Dynamic memory allocation and fragmentation Seminar on Network and Operating Systems Group II

Schedule Today (Monday):  General memory allocation mechanisms  The Buddy System Thursday:  General Object Caching  Slabs

What is an allocator and what must it do?

Memory Allocator Keeps track of memory in use and free memory Must be fast and waste little memory Services memory requests it receives Prevent forming of memory “holes” “For any possible allocation algorithm, there will always be a program behavior that forces it into severe fragmentation.”

The three levels of an allocator Strategies  Try to find regularities in incoming memory requests. Policies  Decides where and how to place blocks in memory (selected by the strategy) Mechanisms  The algorithms that implement the policy

Policy techniques Uses splitting and coalescing to satisfy the incoming requests.  Split large blocks for small requests  Coalesce small blocks for larger requests

Fragmentation, why is it a problem?

Fragmentation Fragmentation is the inability to reuse memory that is free External fragmentation occurs when enough free memory is available but isn’t contiguous  Many small holes Internal fragmentation arises when a large enough block is allocated but it is bigger than needed  Blocks are usually split to prevent internal fragmentation

What causes fragmentation? Isolated deaths  When adjacent objects do not die at the same time. Time-varying program behavior  Memory requests change unexpectedly

Why traditional approaches don’t work Program behavior is not predictable in general The ability to reuse memory depends on the future interaction between the program and the allocator  100 blocks of size 10 and 200 of size 20?

How do we avoid fragmentation? A single death is a tragedy. A million deaths is a statistic. -Joseph Stalin

Understanding program behavior Common behavioral patterns  Ramps Data structures that are accumulated over time  Peaks Memory used in bursty patterns usually while building up temporal data structures.  Plateaus Data structures build quickly and are used for long periods of time

Memory usage in the GNU C Compiler KBytes in use Allocation Time in Megabytes

Memory usage in the Grobner program KBytes in use Allocation Time in Megabytes

Memory usage in Espresso PLA Optimizer KBytes in use Allocation Time in Megabytes

Mechanisms Most common mechanisms used  Sequential fits  Segregated free lists Buddy System  Bitmap fits  Index fits

Sequential fits Based on a single linear list  Stores all free memory blocks  Usually circularly or doubly linked  Most use boundary tag technique Most common mechanisms use this method.

Sequential fits Best fit, First fit, Worst fit Next fit  Uses a roving pointer for allocation Optimal fit  “Samples” the list first to find a good enough fit Half fit  Splits blocks twice the requested size

Segregated free lists Use arrays of lists which hold free blocks of particular size Use size classes for indexing purposes  Usually in sizes that are a power of two Requested sizes are rounded up to the nearest available size

Segregated free lists Simple segregated list  No splitting of free blocks  Subject to severe external fragmentation Segregated fit  Splits larger blocks if there is no free block in the appropriate free list  Uses first fit or next fit to find a free block  Three types: exact lists, strict size classes with rounding or size classes with range lists.

Buddy system A special case of segregated fit  Supports limited splitting and coalescing  Separate free list for each allowable size  Simple block address computation A free block can only be merged with its unique buddy.  Only whole entirely free blocks can be merged.

Buddy system 16 MB 8 MB 4 MB 3 MB Free

Buddy system Split Free 16 MB 8 MB 4 MB 3 MB Free

Buddy system Split Free 16 MB 8 MB 4 MB 3 MB Free

Buddy system Split Alloc. Free 16 MB 8 MB 4 MB

Binary buddies Simplest implementation  All buddy sizes are powers of two  Each block divided into two equal parts Internal fragmentation very high  Expected 28%, in practice usually higher (Demonstration applet)

Fibonacci buddies Size classes based on the fibonacci series  More closely-spaced set of size classes  Reduces internal fragmentation  Blocks can only be split into sizes that are also in the series Uneven block sizes a disadvantage?  When allocating many equal sized blocks

Fibonacci buddies … Size series: Splitting blocks:

Weighted buddies Size classes are power of two  Between each pair is a size three times a power of two Two different splitting methods  2 x numbers can be split in half  2 x *3 numbers can be split in half or unevenly into two sizes.

Weighted buddies … (2 1 ) (2 0 *3) (2 2 ) (2 1 *3) (2 3 ) (2 2 *3) (2 4 ) (2 3 *3) … Size series: Splitting of 2 x *3 numbers:

Double buddies Use 2 different binary buddy series  One list uses powers of two sizes  Other uses powers of two spacing, offset by x Splitting rules  Blocks can only be split in half  Split blocks stay in the same series

Double buddies … (2 1 ) (2 2 ) (2 3 ) (2 4 ) (2 5 ) (2 6 ) (2 7 )… Size series: Splitting of 3*2 x numbers: … (3*2 0 ) (3*2 1 ) (3*2 2 ) (3*2 3 ) (3*2 4 ) (3*2 5 ) (3*2 6 )…

Deferred coalescing Blocks are not merged as soon as they are freed. Uses quick lists or subpools  Arrays of free lists, one for each size class that is to be deferred  Blocks larger than those defined to be deferred are returned to the general allocator

Deferred reuse Recently freed blocks are not immediately reused  Older free blocks used instead of newly freed Compacts long-lived memory blocks  Can cause increased fragmentation if only short-lived blocks are requested

Discussion

Questions? Why can deferred reuse cause increased fragmentation if only short-lived blocks are requested? How can the order in which the requests arrive effect memory fragmentation? Why is fragmentation at peaks more important than at intervening points?

Questions? When would deferred coalescing be likely to cause more fragmentation? What is a possible disadvantage when splitting blocks using the fibonacci buddy system? In the double buddy system, why does the added size-class list reduce internal fragmentation by about 50%?