Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
RUN-TIME
ENVIRONMENTSHEAP MANAGAGEMENT
HEAP
- portion of the store used for data that lives
indefinitely or until explicitly deleted by the
program
Nevermore by ...
MEMORY MANAGER
 the subsystem that allocates and
deallocates space within the heap
 keeps track of all the free space in heap
storage a...
 produces a chunk of contiguous heap
memory of the requested size
 if no chunk of the needed size is
available, it incre...
 returns deallocated space to the pool of
free space (so it can reuse the space)
 typically does not return memory to th...
 Space Efficiency
 Program Efficiency
 Low Overhead
MEMORY MANAGER
WINTERTemplate
MEMORY
HIERARCHY
01
02
Register
1st-Level
Cache
2nd-Level Cache
Physical Memory
Virtual Memory (Disk)
Memory Diagram
Typical Sizes
32 Words
16...
02Memory Diagram
Register
1st-Level
Cache
2nd-Level Cache
Physical Memory
Virtual Memory (Disk)
The goal is to obtain
the ...
03Principle of Locality
Also known as Locality of Reference
The phenomenon of the same value or
related storage locations ...
03
Two Types of Access Locality
1. Temporal Locality
2. Spatial Locality
Principle of Locality
03
1. Temporal Locality
the memory locations the program
accesses are likely to be accessed again
within a short period of...
03
2. Spatial Locality
memory locations close to the location
accessed are likely also to be accessed
within a short perio...
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition,
Reducing Fragmentation
8.16 Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition
CONTIGUOUS MEMORY
8.17 Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition
Contiguous Allocation
 Main memory usual...
8.18 Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition
Contiguous Allocation
 Hole – block of a...
8.19 Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition
Dynamic Storage-Allocation Problem
 Firs...
 Coalescing
REDUCING FRAGMENTATION
COALESCING
- combining adjacent chunks of the heap to
form a larger chunk
 Boundary Tags
- keeping a free/used bit at both ends of each
chunk
- adjacent to the free/used bit is a count of
the # o...
MANUAL DEALLOCATION
REQUEST
 Memory-leak Error
- failing to EVER delete data that cannot be
referenced
 Dangling-pointer-dereference
[note: dangling...
 Object Ownership
- associate an owner with each object (e.g.
functions and their variables)
 Reference Counting
- assoc...
 Region-based Allocation
- allocate all objects in the same region; then
delete the entire region
PROGRAMMING CONVENTIONS...
Fin.
Upcoming SlideShare
Loading in …5
×

Heap Management

2,350 views

Published on

Run time environment

Published in: Devices & Hardware
  • Be the first to comment

Heap Management

  1. 1. RUN-TIME ENVIRONMENTSHEAP MANAGAGEMENT
  2. 2. HEAP - portion of the store used for data that lives indefinitely or until explicitly deleted by the program Nevermore by Paul Gaugin
  3. 3. MEMORY MANAGER
  4. 4.  the subsystem that allocates and deallocates space within the heap  keeps track of all the free space in heap storage at all times  serves as an interface between application programs and the operating system MEMORY MANAGER
  5. 5.  produces a chunk of contiguous heap memory of the requested size  if no chunk of the needed size is available, it increases the heap storage by getting consecutive bytes of virtual memory from the OS ALLOCATION MEMORY ALLOCATION
  6. 6.  returns deallocated space to the pool of free space (so it can reuse the space)  typically does not return memory to the OS, even if heap usage drops DEALLOCATION MEMORY ALLOCATION
  7. 7.  Space Efficiency  Program Efficiency  Low Overhead MEMORY MANAGER
  8. 8. WINTERTemplate MEMORY HIERARCHY 01
  9. 9. 02 Register 1st-Level Cache 2nd-Level Cache Physical Memory Virtual Memory (Disk) Memory Diagram Typical Sizes 32 Words 16 - 64KB 128KB - 4MB 256MB - 2GB > 2GB Typical Access Times 1 ns 5 - 10 ns 40 - 60 ns 100 - 150 ns 3 - 15 ms
  10. 10. 02Memory Diagram Register 1st-Level Cache 2nd-Level Cache Physical Memory Virtual Memory (Disk) The goal is to obtain the best average access speed while minimizing the total cost of the entire memory system.
  11. 11. 03Principle of Locality Also known as Locality of Reference The phenomenon of the same value or related storage locations being frequently accessed. 90/10 Rule comes from the empirical observation: “A program spends 90% of its time in 10% of its code.”
  12. 12. 03 Two Types of Access Locality 1. Temporal Locality 2. Spatial Locality Principle of Locality
  13. 13. 03 1. Temporal Locality the memory locations the program accesses are likely to be accessed again within a short period of time Principle of Locality Example: Instruction in the body of inner loops
  14. 14. 03 2. Spatial Locality memory locations close to the location accessed are likely also to be accessed within a short period of time Principle of Locality Example: Traversing the elements in a one-dimentional array
  15. 15. Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition, Reducing Fragmentation
  16. 16. 8.16 Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition CONTIGUOUS MEMORY
  17. 17. 8.17 Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition Contiguous Allocation  Main memory usually into two partitions:  Resident operating system, usually held in low memory with interrupt vector  User processes then held in high memory
  18. 18. 8.18 Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition Contiguous Allocation  Hole – block of available memory; holes of various size are scattered throughout memory  When a process arrives, it is allocated memory from a hole large enough to accommodate it  Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10
  19. 19. 8.19 Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition Dynamic Storage-Allocation Problem  First-fit: Allocate the first hole that is big enough  Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size  Produces the smallest leftover hole  Worst-fit: Allocate the largest hole; must also search entire list  Produces the largest leftover hole How to satisfy a request of size n from a list of free holes
  20. 20.  Coalescing REDUCING FRAGMENTATION
  21. 21. COALESCING - combining adjacent chunks of the heap to form a larger chunk
  22. 22.  Boundary Tags - keeping a free/used bit at both ends of each chunk - adjacent to the free/used bit is a count of the # of bytes  Doubly Linked, Imbedded Free List - free chunks are linked in a doubly linked list - chunks must accommodate two boundary tags and two pointers COALESCING REDUCING FRAGMENTATION
  23. 23. MANUAL DEALLOCATION REQUEST
  24. 24.  Memory-leak Error - failing to EVER delete data that cannot be referenced  Dangling-pointer-dereference [note: dangling pointers - pointers to storage that has been deallocated] - referencing deleted data MANUAL DEALLOCATION REQUESTS
  25. 25.  Object Ownership - associate an owner with each object (e.g. functions and their variables)  Reference Counting - associate a count with each dynamically allocated object PROGRAMMING CONVENTIONS & TOOLS MANUAL DEALLOCATION REQUESTS
  26. 26.  Region-based Allocation - allocate all objects in the same region; then delete the entire region PROGRAMMING CONVENTIONS & TOOLS MANUAL DEALLOCATION REQUESTS
  27. 27. Fin.

×