Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS703 - Advanced Operating Systems

Similar presentations


Presentation on theme: "CS703 - Advanced Operating Systems"— Presentation transcript:

1 CS703 - Advanced Operating Systems
By Mr. Farhan Zaidi

2 Lecture No. 21

3 Overview of today’s lecture
Explicit free lists base allocator details Freeing with LIFO policy Segregated free lists Exploiting allocation patterns of programs Exploiting peaks via arena allocators Garbage collection

4 Explicit Free Lists A B C Forward links A B 4 4 4 4 6 6 4 4 4 4 C
Back links

5 Allocating From Explicit Free Lists
pred succ free block Before: pred succ After: (with splitting) free block

6 Freeing With Explicit Free Lists
Insertion policy: Where in the free list do you put a newly freed block? LIFO (last-in-first-out) policy Insert freed block at the beginning of 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)

7 Freeing With a LIFO Policy
pred (p) succ (s) Case 1: a-a-a Case 2: a-a-f a self a p s before: a self f p s after: a f

8 Freeing With a LIFO Policy (cont)
s before: f self a Case 3: f-a-a Case 4: f-a-f p s after: f a p1 s1 p2 s2 before: f self f p1 s1 p2 s2 after: f

9 Explicit List Summary Comparison to implicit list: Allocate is linear time in number of free blocks instead of total blocks -- much faster allocates when most of the memory is full Slightly more complicated allocate and free since needs to move blocks in and out of the list Some extra space for the links (2 extra words needed for each block) Main use of linked lists is in conjunction with segregated free lists Keep multiple linked lists of different size classes, or possibly for different types of objects

10 Simple Segregated Storage
Separate free list for each size class No splitting Tradeoffs: Fast, but can fragment badly

11 Segregated Fits Coalesce and place on appropriate list (optional)
Array of free lists, each one for some size class 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 of simple segregated storage Coalescing can increase search times Deferred coalescing can help

12 Known patterns of real programs
ramps: accumulate data monotonically over time peaks: allocate many objects, use briefly, then free all plateaus: allocate many objects, use for a long time bytes bytes bytes

13 Exploiting peaks 64k 64k free pointer
Peak phases: alloc a lot, then free everything Advantages: alloc is a pointer increment, free is “free”, & there is no wasted space for tags or list pointers. 64k 64k free pointer

14 Implicit Memory Management: Garbage Collection
Garbage collection: automatic reclamation of heap-allocated storage -- application never has to free

15 Garbage Collection How does the memory manager know when memory can be freed? Need to make certain assumptions about pointers Memory manager can distinguish pointers from non-pointers All pointers point to the start of a block Cannot hide pointers (e.g., by coercing them to an int, and then back again)

16 Reference counting ref=2 a b
Algorithm: counter pointers to object each object has “ref count” of pointers to it increment when pointer set to it decremented when pointer killed ref=2 a b void foo(bar c) { bar a, b; a = c; c->refcnt++; b = a; a->refcnt++; a = 0; a->refcnt--; return; b->refcnt--; }

17 Problems Circular data structures always have refcnt > 0 ref=1

18 Memory as a Graph Each block is a node in the graph
We view memory as a directed graph Each block is a node in the graph Each pointer is an edge in the graph Locations not in the heap that contain pointers into the heap are called root nodes (e.g. registers, locations on the stack, global variables) Root nodes Heap nodes Not-reachable (garbage) reachable

19 Assumptions Instructions used by the Garbage Collector
is_ptr(p): determines whether p is a pointer length(b): returns the length of block b, not including the header get_roots(): returns all the roots


Download ppt "CS703 - Advanced Operating Systems"

Similar presentations


Ads by Google