DOC PREVIEW
CMU CS 15213 - Lecture

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

15 213 Introduction to Computer Systems Memory Management I Dynamic Storage Allocation Oct 8 1998 Topics User level view Policies Mechanisms class14 ppt Harsh Reality Memory 3Matters 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 Cache and virtual memory effects can greatly affect program performance Adapting program to characteristics of memory system can lead to major speed improvements class14 ppt 2 CS 213 F 98 Dynamic Storage Allocation Application Dynamic Storage Allocator Heap Memory Application Requests and frees contiguous blocks of memory Allocator e g Unix malloc package Provides an abstraction of memory as a set of blocks Doles out free memory blocks to application Keeps track of free and allocated blocks Heap memory region starting after bss segment class14 ppt 3 CS 213 F 98 Process memory image Reserved for kernel Alpha 0xffff ffff ffff ffff 0xffff fc00 0000 0000 0xffff fbff ffff ffff 0x0000 0400 0000 0000 0x0000 03ff ffff ffff 0x0000 03ff 8000 0000 0x0000 03ff 7fff ffff Not accessible Reserved for shared libraries and dynamic loader Available for heap Heap via malloc Grows up Bss segment gp 0x0000 0001 2000 0000 0x0000 0000 1fff ffff sp 0x0000 0000 0001 0000 0x0000 0000 0000 ffff 0x0000 0000 0000 0000 class14 ppt Data segment Text segment Stack Grows down to zero Available for stack Not accessible by convention 64KB 4 CS 213 F 98 Malloc void malloc int size package if successful returns 8 byte aligned pointer to memory block of at least size bytes is size 0 returns NULL 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 class14 ppt 5 CS 213 F 98 Definitions and assumptions Heap Memory fixed size Relative Address word address 0 4 8 Allocated block 4 words 12 Free block 3 words Program Primitives Allocation request Ai n Allocate n words and call it block i Example A7 128 Free request Fj Free block j Example F7 class14 ppt 6 CS 213 F 98 Allocation example A1 4 A2 5 A3 6 F2 A4 2 class14 ppt 7 CS 213 F 98 Applications Constraint s 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 class14 ppt 8 CS 213 F 98 Fragmentation A1 4 A2 5 A3 6 F2 A4 6 class14 ppt oops 9 CS 213 F 98 Fragmentation cont Def external fragmentation is the inability to reuse free memory possible because applications can free blocks in any order potentially creating holes Minimizing fragmentation is the fundamental problem of dynamic resource allocation Unfortunately there is no good operational definition Function of Number and sizes of holes Placement of allocated blocks Past program behavior pattern of allocates and frees Future program behavior class14 ppt 10 CS 213 F 98 Fragmentation cont A B C Which heaps have a fragmentation problem It depends 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 class14 ppt 11 CS 213 F 98 Fragmentation cont First Fit A1 1 A2 2 A3 4 Oops The policy for placing allocated blocks has a big impact on fragmentation class14 ppt 12 CS 213 F 98 Fragmentation cont Best Fit A1 1 A2 2 A3 4 But best fit doesn t always work best either class14 ppt 13 CS 213 F 98 Fragmentation cont Best Fit A1 1 A2 2 A3 2 A4 2 oops class14 ppt 14 CS 213 F 98 Fragmentation cont First Fit A1 1 A2 2 A3 2 A4 2 class14 ppt 15 CS 213 F 98 Splitting A1 1 1 Find a free block that is big enough 2 Split the block into two free blocks 3 Allocate the first block class14 ppt 16 CS 213 F 98 Coalescing 2 F2 1 free the block 2 merge any adjacent free blocks into a single free block Crucial operation for any dynamic storage allocator Can be immediate performed at every free request deferred performed every k free requests or when necessary class14 ppt 17 CS 213 F 98 Organizing the set of free blocks Some data structure needed to organize the search of the free blocks Efficient implementations use the free blocks themselves to hold the necessary link fields disadvantage every allocated block must be large enough to hold the link fields since the block could later be freed imposes a minimum block size could result in wasted space internal fragmentation Common approach list of free blocks embedded in an array of allocated blocks class14 ppt 18 CS 213 F 98 Organizing the set of free blocks address ordering no memory overhead doubly linked list of free blocks simple popular reasonable memory overhead might not scale to large sets of free blocks tree structures more scalable less memory efficient than lists segregated free lists different free lists for different size classes of free blocks internal fragmentation class14 ppt 19 CS 213 F 98 Placement policies When a block is allocated we must search the free list for a free block that is large enough to satisfy the request feasible free block Placement policy determines which feasible free block to choose A1 1 Each of these free blocks is feasible Where do we place the allocated block class14 ppt 20 CS 213 F 98 Placement policies cont first fit search list from beginning choose first free block that fits simple and popular can increase search time because splinters can accumulate near the front of the list simplicity lends itself to tight inner loop might not scale well for large free lists Search starts here A1 1 First fit chooses this block class14 ppt 21 CS 213 F 98 Placement policies cont best fit choose free block that fits the best motivation is to try to keep fragments what s left over after splitting as small as possible can backfire if blocks almost fit but not quite Search starts here A1 1 Best fit chooses this block class14 ppt 22 CS 213 F 98 Placement policies cont next fit


View Full Document

CMU CS 15213 - Lecture

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?