Title: Storage Allocation in Bounded Time
1Storage Allocation in Bounded Time
Sharath R. CholletiSep 04, 2002Advisor Dr. Ron
K. Cytron
Center for Distributed Object Computing Department
of Computer Science Washington University
Supported by NSF ITR 0081214 and DARPA contract
number F33615-00-C-1697
2Outline
- Dynamic Storage Allocation
- Buddy Allocation
- Tight bound on storage requirement for
defragmentation-free buddy allocator - Greedy Algorithm for partial defragmentation
- Experiments
- Conclusion
3Dynamic Storage Allocation
Program
Heap
Allocation or Deallocation Request
Response
Allocator
- Heap storage used by a program
- Real-Time Systems
- - Bounded time
- Embedded Systems
- - Limited resources
4Fragmentation
Heap
Where to allocate?
- Not enough contiguous free space
5Possible Solutions
- Have a big enough heap
- Defragmentation
- Compaction
- Unreasonably bounded
- Real-Time Systems
- - Bounded time
- Embedded Systems
- - Limited resources
6Questions
- How big a heap we need to avoid defragmentation?
- How to defragment partially to satisfy a single
request within some bounded time ?
7Storage Allocation Free List
- Linked list of free blocks
8Storage Allocation Knuths Buddy System
- Free lists segregated by size
128
64
32
- All the requests are rounded up to a power of 2
16
8
4
2
1
9Buddy System (1)
- Begin with one large block
- Suppose we want a block of size 8
128
64
32
16
8
4
2
1
10Buddy System (2)
- Begin with one large block
- Suppose we want a block of size 8
- Subdivide recursively
128
64
32
16
8
4
2
1
11Buddy System (3)
- Begin with one large block
- Suppose we want a block of size 8
- Subdivide recursively
128
64
32
16
8
4
2
1
12Buddy System (4)
- Begin with one large block
- Suppose we want a block of size 8
- Subdivide recursively
128
64
32
16
8
4
2
1
13Buddy System (5)
- Begin with one large block
- Suppose we want a block of size 8
- Subdivide recursively
- 2 blocks of size 8
128
64
32
16
8
4
2
1
14Buddy System (6)
- Begin with one large block
- Suppose we want a block of size 8
- Subdivide recursively
- 2 blocks of size 8
- One of those given to the program
128
64
32
16
8
4
Given to the program
2
1
15Buddy System (7)
- Coalescing
- Only buddies coalesce
128
64
32
16
8
4
Deallocated
2
1
16Buddy System Tree Notation
Free
Allocate block of size 1 byte
Occupied
16
8
4
2
1
17Buddy System Tree Notation(2)
Free
Allocate block of size 1 byte
Occupied
16
8
4
2
1
18Buddy System Tree Notation(3)
Free
Allocate block of size 1 byte
Occupied
16
8
4
2
1
19Buddy System Tree Notation(4)
Free
Allocate block of size 1 byte
Occupied
16
8
4
2
1
20Buddy System Tree Notation(5)
Free
Allocate block of size 1 byte -- Done
Occupied
16
8
4
2
1
21Buddy System Tree Notation(6)
Free
Allocate block of size 4 bytes
Occupied
16
8
4
2
1
22Questions
- How big a heap we need to avoid defragmentation?
- How to defragment partially to satisfy a single
request within some bounded time ?
23Trivial Bound
- Definitions
- Maxlive max number of bytes the program uses at
any given time throughout its life time - Maxlive denoted by M
- Rounded to next power of 2 (for Buddy System)
- log denotes log base 2
- Trivial Bound
- kM, where k is the number of different block
sizes - For buddy system the bound is M(log M),
- as k log M (not counting the block size of
maxlive) - The bound is very high
- For example if M 210 B, we need 10 210 B
24Heap of 2M is not sufficient
Free
M 16 bytes
- Allocate 16 1-byte blocks
Occupied
32
16
8
4
2
1
25Heap of 2M is not sufficient (2)
Free
M 16 bytes
- Deallocate alternate blocks
- Used storage 8 bytes
Occupied
32
16
8
4
2
1
26Heap of 2M is not sufficient (3)
Free
M 16 bytes
- Allocate 4 blocks of size 2 bytes
- Used storage 16 bytes
Occupied
32
16
8
4
2
1
27Heap of 2M is not sufficient (4)
Free
M 16 bytes
- Deallocate alternate blocks
- Used storage 8 bytes
Occupied
32
16
8
4
2
1
28Heap of 2M is not sufficient (5)
Free
M 16 bytes
- Allocate 2 blocks of size 4 bytes
- Used storage 16 bytes
Occupied
32
16
8
4
2
1
29Heap of 2M is not sufficient (6)
Free
M 16 bytes
- Deallocate alternate blocks
- Used storage 8 bytes
Occupied
32
16
8
4
2
1
30Heap of 2M is not sufficient (7)
Free
M 16 bytes
- Used storage 8 bytes
- Want to allocate a block of 8 bytes!
Occupied
32
16
8
4
2
1
31Tight Bound
- Maxlive M
- Max-blocksize n
- n lt M
- M(log n 2)/2 is necessary and sufficient for
address-ordered buddy allocator - Proof sketch for sufficiency
- P(k) For kltlog n, 2k block cannot be allocated
beyond M(k 2)/2 - Proof of sufficiency by induction on k
32Proof Idea (sufficiency)
Free
M 16 bytes
- 2k size block cannot be allocated beyond M(k2)/2
Occupied
32
16
8
4
2
1
M
M/2
M/2
33Proof Idea (sufficiency)
Free
M 16 bytes
- Assume P(k) is true for 0ltkltlog n
- Then prove for P(k1)
- For klog n, 2(logn) size block cannot be
allocated beyond M(log n2)/2
Occupied
32
16
8
4
2
1
M
M/2
M/2
34Proof Idea (Necessary)
Free
M 16 bytes
- M(log n2)/2 bytes necessary
- Details presented in the thesis
- Example when k1, i.e., block of size 2
Occupied
32
16
8
4
2
1
M
M/2
M/2
35Tight Bound
- M(log n2)/2
- n max-blocksize
- M(log M1)/2
- when n M/2
- Almost half of the trivial bound
- For example, if M 210 B then 5.5 210 B is
needed
36Questions
- How big a heap we need to avoid defragmentation?
- How to defragment partially to satisfy a single
request within some bounded time ?
37Partial Defragmentation Relocation Example
Free
- Need to allocate a block of 8 bytes
- No free block of 8 bytes -- relocate
Occupied
Amount of storage relocated T(1) 1
32
16
8
4
2
1
38Partial Defragmentation Relocation Example (2)
Free
- Again need to allocate a block of 8 bytes
- No free block of 8 bytes -- relocate
Occupied
Amount of storage relocated T(2) T(1)
(21) 1 4
32
16
8
4
2
1
39Worst-case Relocation Heap of M bytes
- Amount storage relocated in worst-case to get a
free block of n - T(n/2)T(n/4)T(1)
- n/2 T(n/4) T(n/8) T(1)
T(n/4)T(1) - n/2 2T(n/4)T(n/8)T(1)
- n(log n)/2
Free
Occupied
32
16
8
4
2
1
40Defragmentation with Heap of 2M bytes
- Theorem Greedy algorithm of selecting a
minimally occupied chunk for relocation moves
less than twice the storage an optimal algorithm
would move. - Proof sketch, details in thesis
- Optimal algorithm has to relocate at least the
amount of storage present in a minimally occupied
chunk (say X bytes) - Greedy algorithm selects a chunk with X bytes
live storage - Let X is made up of blocks of size x1, x2, x3, ,
xn bytes - For each xi, there exists a chunk of size xi with
less than xi/2 live storage - Overall relocation X X/2 X/4 1 lt 2X
- Less than twice optimal
41Defragmentation with Heap of 2M bytes(2)
- Lemma There is a 2k-byte chunk with less than
2(k-1) bytes live storage.
Free
M 16 bytes
Occupied
32
16
8
4
2
1
42Defragmentation with Heap of 2M bytes(3)
- Worst-case relocation
- n, if block of size n is requested
- From the lemma and the theorem
- How to find the minimally occupied chunk?
- Go through the entire heap?
43Heap Manager Algorithm
16
8
8
3
5
4
3
0
1
4
1
2
0
1
2
2
2
1
44Heap Manager Algorithm(2)
- Storage bound O(M)
- Time bound O(M)
- T(n) 2M/n T(n/4) T(n/8) T(4)
- 2M/n 2M/(n/4) T(n/8)
2T(n/16)T(4) - O(Mn0.695)
45Experiments SPEC Benchmarks
- Java -- check, compress, db, jack, javac, jess,
mpegaudio, mtrt, raytrace - C cfrac, gawk, gs, p2c, ptc
- Java traces using contaminated garbage collection
(Dante, Steve, Matt) - Randomly generated traces (Delvin)
- With 2M heap there is no relocation required!
- Even for randomly generated traces
46Compaction Methods
- To compare overall partial defragmentation with
heap of M - Left-first compaction
- Right-first compaction
- Naive Compaction
47Java Benchmarks
48C Benchmarks
49Minimal vs Random Chunk Amount of Relocation
50Minimal vs Random Chunk Number of Relocations
51Conclusion Future Work
- Tight bound for a defragmentation-free buddy
allocator - Greedy algorithm for partial defragmentation
- Experiments
- 2M is good enough in practice!
- Very less defragmentation even with heap of size
M - Our algorithm does much better than compaction
- Minimal vs Random Block Selection
- Implementing the algorithm in JVM?
- Contaminated Reference Counting
52Questions?
53Thanks
- Advisor
- Dr. Ron K. Cytron
- Thesis Committee
- Dr. Jeremy Buhler
- Dr. Chris D. Gill
- Dr. Chenyang Lu
- DOC Group members and others