Top Banner
1 Dynamic Memory Allocation
33

Dynamic Memory Allocation

Jan 26, 2016

Download

Documents

Dynamic Memory Allocation. Outline. Explicit Free List Segregated Free List Suggested reading: 9.9. Explicit free lists. Explicit list among the free blocks using pointers within the free blocks Use data space for link pointers Typically doubly linked - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dynamic Memory Allocation

1

Dynamic Memory Allocation

Page 2: Dynamic Memory Allocation

2

Outline

• Explicit Free List• Segregated Free List

• Suggested reading: 9.9

Page 3: Dynamic Memory Allocation

3

Explicit free lists

• Explicit list among the free blocks using

pointers within the free blocks

• Use data space for link pointers

– Typically doubly linked

– Still need boundary tags for coalescing

– It is important to realize that links are not

necessarily in the same order as the blocks

Page 4: Dynamic Memory Allocation

4

Explicit free lists

A B C

4 4 4 4 66 44 4 4

Forward links

Back links

A B

C

Page 5: Dynamic Memory Allocation

5

Freeing with explicit free lists

• Where to put the newly freed block in the

free list

– LIFO (last-in-first-out) policy

• insert freed block at the beginning of the free list

• pro: simple and constant time

• con: studies suggest fragmentation is worse than

address ordered.

Page 6: Dynamic Memory Allocation

6

Freeing with explicit free lists

• Where to put the newly freed block in the free list– Address-ordered policy

• insert freed blocks so that free list blocks are always in address order

– i.e. addr(pred) < addr(curr) < addr(succ)• con: requires search

• pro: studies suggest fragmentation is better than LIFO

Page 7: Dynamic Memory Allocation

7

Segregated Storage

• Each size “class” has its own

collection of blocks

– Often have separate collection for every small

size (2,3,4,…)

– For larger sizes typically have a collection for

each power of 2

Page 8: Dynamic Memory Allocation

8

Segregated Storage

1-2

3

4

5-8

9-16

Page 9: Dynamic Memory Allocation

9

• 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

Simple segregated storage

Page 10: Dynamic Memory Allocation

10

• To free a block:

– Add to free list

• Tradeoffs:

– fast, but can fragment badly

Simple segregated storage

Page 11: Dynamic Memory Allocation

11

• Array of free lists, each one for some size

class

Segregated fits

Page 12: Dynamic Memory Allocation

12

• 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

– if no blocks is found in all classes, try more heap memory

Segregated fits

Page 13: Dynamic Memory Allocation

13

• 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

• A simple first-fit approximates a best-fit over entire heap

– coalescing can increase search times• deferred coalescing can help

Segregated fits

Page 14: Dynamic Memory Allocation

14

• A special case of segregated fits

– Each size is power of 2

• Initialize

– A heap of size 2m

Buddy Systems

Page 15: Dynamic Memory Allocation

15

• Allocate

– Roundup to power of 2 such as 2k

– Find a free block of size 2j (k j m)

– Split the block in half until j=k

• Each remaining half block (buddy) is placed on the

appreciate free list

• Free

– Continue coalescing with the free buddies

Buddy Systems

Page 16: Dynamic Memory Allocation

16

Memory Hierarchy (I)

Page 17: Dynamic Memory Allocation

17

Outline

• Random-Access Memory (RAM)

• Nonvolatile Memory

• Suggested Reading: 6.1

Page 18: Dynamic Memory Allocation

18

Random-Access Memory (RAM)

• Key features

– RAM is packaged as a chip.

– Basic storage unit is a cell (one bit per cell).

– Multiple RAM chips form a memory.

Page 19: Dynamic Memory Allocation

19

Random-Access Memory (RAM)

• Static RAM (SRAM)– Each cell stores bit with a six-transistor circuit.

– Retains value indefinitely, as long as it is kept powered.

– Relatively insensitive to disturbances such as electrical noise.

– Faster and more expensive than DRAM.

Page 20: Dynamic Memory Allocation

20

Random-Access Memory (RAM)

Page 21: Dynamic Memory Allocation

21

Random-Access Memory (RAM)

• Dynamic RAM (DRAM)

– Each cell stores bit with a capacitor and

transistor.

– Value must be refreshed every 10-100 ms.

– Sensitive to disturbances.

– Slower and cheaper than SRAM.

Page 22: Dynamic Memory Allocation

22

SRAM vs DRAM summary

Tran. Accessper bit time Persist?Sensitive? Cost Applications

SRAM 6 1X Yes No 100x cache memoriesDRAM 1 10X No Yes 1X Main memories,

frame buffers

Page 23: Dynamic Memory Allocation

23

Conventional DRAM organization

• d x w DRAM:– dw total bits organized as d supercells of size w bits

cols

rows

0 1 2 3

0

1

2

3

internal row buffer

16 x 8 DRAM chip

addr

data

supercell(2,1)

2 bits/

8 bits/

memorycontroller

(to CPU)

pins

Page 24: Dynamic Memory Allocation

24

Reading DRAM supercell (2,1)

• Step 1(a): Row access strobe (RAS) selects row 2.• Step 1(b): Row 2 copied from DRAM array to row buffer.

RAS=2cols

rows

0 1 2 3

0

1

2

3

internal row buffer

16 x 8 DRAM chip

row 2

addr

data

2/

8/

memorycontroller

Page 25: Dynamic Memory Allocation

25

Reading DRAM supercell (2,1)

• Step 2(a): Column access strobe (CAS) selects column 1.• Step 2(b): Supercell (2,1) copied from buffer to data lines, and

eventually back to the CPU.

supercell (2,1)

cols

rows

0 1 2 3

0

1

2

3

internal row buffer

16 x 8 DRAM chip

CAS=1

addr

data

2/

8/

memorycontroller

Page 26: Dynamic Memory Allocation

26

Memory modules

: supercell (i,j)

031 78151623243263 394047485556

64-bit doubleword at main memory address A

addr (row = i, col = j)

data

64 MB memory moduleconsisting ofeight 8Mx8 DRAMs

Memorycontroller

bits0-7

DRAM 7

DRAM 0

bits8-15

bits16-23

bits24-31

bits32-39

bits40-47

bits48-55

bits56-63

64-bit doubleword to CPU chip

Page 27: Dynamic Memory Allocation

27

Enhanced DRAMs

• All enhanced DRAMs are built around the

conventional DRAM core

• Fast page mode DRAM (FPM DRAM)

– Access contents of row with [RAS, CAS, CAS,

CAS, CAS] instead of [(RAS,CAS), (RAS,CAS),

(RAS,CAS), (RAS,CAS)].

Page 28: Dynamic Memory Allocation

28

Enhanced DRAMs

• Extended data out DRAM (EDO DRAM)

– Enhanced FPM DRAM with more closely spaced

CAS signals.

• Synchronous DRAM (SDRAM)

– Driven with rising clock edge instead of

asynchronous control signals

Page 29: Dynamic Memory Allocation

29

Enhanced DRAMs

• Double data-rate synchronous DRAM (DDR SDRAM)– Enhancement of SDRAM that uses both clock

edges as control signals.– Different sizes of small prefetch buffers that

increase the effective bandwidth– DDR (2 bits), DDR2 (4 bits), and DDR3 (8 bits)

Page 30: Dynamic Memory Allocation

30

Enhanced DRAMs

• Rambus DRAM(RDRAM)– An alternative proprietary technology with a

higher maximum bandwidth than DDR SDRAM

• Video RAM (VRAM)– Like FPM DRAM, but output is produced by

shifting row buffer

– Dual ported (allows concurrent reads and writes)

Page 31: Dynamic Memory Allocation

31

Nonvolatile memories

• DRAM and SRAM are volatile memories– Lose information if powered off.

• Nonvolatile memories retain value even if powered off– Generic name is read-only memory (ROM).

– Misleading because some ROMs can be read and modified.

Page 32: Dynamic Memory Allocation

32

Types of ROMs

• Programmable ROM (PROM)– Write once

• Erasable programmable ROM (EPROM)– Erase by ultraviolet light– Write by a special device– About 1000 times

• Electrically erasable PROM (EEPROM)– Reprogramming in-place on printed circuit cards

• Flash memory– Based on EEPROM

Page 33: Dynamic Memory Allocation

33

Nonvolatile memories

• Firmware– Program stored in a ROM– BIOS (basic input/output system)

• Boot time code• a small set of primitive input and output

functions– graphics cards, disk controllers

• Translate I/O (input/output) requests from the CPU