Memory Management I Dynamic Storage Allocation, Lecture Slide - Computer Science, Slides of Introduction to Computers

Dynamic Storage Allocation, User-Level View, Policies Mechanism

Typology: Slides

2010/2011

Uploaded on 10/07/2011

rolla45
rolla45 🇺🇸

4

(6)

133 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Memory Management I:
Dynamic Storage Allocation
Oct 8, 1998
Topics
User-level view
Policies
Mechanisms
class14.ppt
15-213
Introduction to Computer Systems
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Memory Management I Dynamic Storage Allocation, Lecture Slide - Computer Science and more Slides Introduction to Computers in PDF only on Docsity!

Memory Management I:

Dynamic Storage Allocation

Oct 8, 1998

Topics

User-level view

Policies

Mechanisms

class14.ppt

Introduction to Computer Systems

  • 2 –

class14.ppt

Harsh Reality

Memory Matters

Memory is not unbounded

It must be allocated and managed

Many applications are memory dominated

  • Especially those based on complex, graph algorithms

Memory referencing bugs especially pernicious

Effects are distant in both time and space

Memory performance is not uniform

performanceCache and virtual memory effects can greatly affect program

major speed improvementsAdapting program to characteristics of memory system can lead to

  • 4 –

class14.ppt

Process memory image (Alpha)

Reserved for kernel

Reserved for shared libraries

and dynamic loader

Available for heap

Heap (via malloc())

Grows up

Bss segment

Text segmentData segment

Stack

Not accessible

Available for stack

Grows down to zero

Not accessible by convention

(64KB)

$sp $gp

0x

0000

0000

0000

0x

0000

0000

ffff

0x

0000

0001

0000

0x

0000

1fff

ffff

0x

0001

2000

0000

0x

03ff

7fff

ffff

0x

03ff

8000

0000

0x

03ff

ffff

ffff

0x

0400

0000

0000

0xffff

fbff

ffff

ffff

0xffff

fc

0000

0000

0xffff

ffff

ffff

ffff

  • 5 –

class14.ppt

Malloc package

void *malloc(int size)

if successful:

  • is size=0, returns NULL – returns 8-byte aligned pointer to memory block of at least size bytes

if unsuccessful:

  • returns NULL

void free(void *p)

returns block pointed at by p to pool of available memory

p must come from a previous call to malloc().

  • 7 –

class14.ppt

Allocation example

A1(4)

A2(5)

A3(6)

F

A4(2)

  • 8 –

class14.ppt

Constraints

Applications:

Can issue arbitrary sequence of allocation and free requests

Free requests must correspond to an allocated block

Allocators

Can’t control number or size of allocated blocks

Must respond immediately to all allocation requests

  • i.e., can’t reorder or buffer requests

Must allocate blocks from free memory

  • i.e., can only place allocated blocks in free memory

Must align blocks so they satisfy all alignment requirements

  • usually 8 byte alignment

Can only manipulate and modify free memory

Can’t move the allocated blocks once they are allocated

  • i.e., compaction is not allowed
  • 10 –

class14.ppt

Fragmentation (cont)

Def:

(external) fragmentation is the inability to reuse free

memory.

creating holes.possible because applications can free blocks in any order, potentially

Minimizing fragmentation is the fundamental problem of

dynamic resource allocation...

Function ofUnfortunately, there is no good operational definition.

Number and sizes of holes,

  • Past program behavior (pattern of allocates and frees) – Placement of allocated blocks,

Future program behavior.

  • 11 –

class14.ppt

Fragmentation (cont)

It depends...Which heaps have a fragmentation problem?

Qualitatively, C has fewer and bigger holes.

But fragmentation occurs only if program needs a large block.

Still, C is probably less likely to encounter problems.

Definitive answer requires a model of program

execution.

C B A

  • 13 –

class14.ppt

Fragmentation (cont)

A1(1)

“Best Fit”

A3(4) A2(2)

But “best fit” doesn’t always work best either

  • 14 –

class14.ppt

Fragmentation (cont)

A1(1)

“Best Fit”

A4(2) A3(2) A2(2)

oops!

  • 16 –

class14.ppt

Splitting

A1(1)

(3) Allocate the first block(2) Split the block into two free blocks(1) Find a free block that is big enough

  • 17 –

class14.ppt

Coalescing

2

F

(2) merge any adjacent free blocks into a single free block(1) free the block

Can be:Crucial operation for any dynamic storage allocator

immediate (performed at every free request)

deferred (performed every k free requests or when necessary)

  • 19 –

class14.ppt

Organizing the set of free blocks

address ordering

  • no memory overhead

doubly linked list of free blocks

  • might not scale to large sets of free blocks – simple, popular, reasonable memory overhead

tree structures

  • less memory efficient than lists – more scalable

segregated free lists

  • internal fragmentation – different free lists for different size classes of free blocks.
  • 20 –

class14.ppt

Placement policies

When a block is allocated, we must search the free list

request (for a free block that is large enough to satisfy the

feasible free block).

Placement policy determines which feasible free block

to choose.

A1(1)

Where do we place the allocated block?Each of these free blocks is feasible.