Automatic Pool Allocation

17
1 Automatic Pool Allocation Chris Lattner and Vikram Adve Presented by William Lovas

description

Automatic Pool Allocation. Chris Lattner and Vikram Adve Presented by William Lovas. Motivation. Data locality is important! Compilers are good with arrays… … but bad with pointer-based data structures. Motivation. Existing techniques focus on individual references or data elements - PowerPoint PPT Presentation

Transcript of Automatic Pool Allocation

Page 1: Automatic Pool Allocation

1

Automatic Pool AllocationAutomatic Pool Allocation

Chris Lattner and Vikram Adve

Presented by William Lovas

Page 2: Automatic Pool Allocation

2

MotivationMotivation

• Data locality is important!

• Compilers are good with arrays…

• … but bad with pointer-based data structures

Page 3: Automatic Pool Allocation

3

MotivationMotivation

• Existing techniques focus on individual references or data elements

• Big idea: analyze how programs use entire data structures!

Page 4: Automatic Pool Allocation

4

Pool AllocationPool Allocation

• Allocate disjoint data structures in disjoint portions of the heap (pools)

• … automatically, via static program transformation!

Page 5: Automatic Pool Allocation

5

Pool AllocationPool Allocation

• Transform:

Page 6: Automatic Pool Allocation

6

Pool AllocationPool Allocation

• Into:

Page 7: Automatic Pool Allocation

7

ApproachApproach

• Create a data structure graph for each function F A “points-to” graph with some extra info

• DS graph records, for each object: Type of the object Whether it’s heap-allocated Whether it escapes F

Page 8: Automatic Pool Allocation

8

ApproachApproach

• Use DS graph to assign a pool to each object

• Use assignment to rewrite program: Calls to malloc/free become calls to

pool_alloc/pool_free

Creates local pools for non-escaping objects Adds pool arguments for escaping objects

Page 9: Automatic Pool Allocation

9

Example [Lattner]Example [Lattner]

list *list *makeListmakeList(int Num) {(int Num) { list *New = list *New = mallocmalloc(sizeof(list));(sizeof(list)); New->Next = Num ? New->Next = Num ? makeListmakeList(Num-1) : 0;(Num-1) : 0; New->Data = Num; return New;New->Data = Num; return New;}}

void void twoListstwoLists( ) {( ) {

list *X = list *X = makeListmakeList(10);(10); list *Y = list *Y = makeListmakeList(100);(100); GL = Y;GL = Y; processListprocessList(X);(X); processListprocessList(Y);(Y); freeListfreeList(X);(X); freeListfreeList(Y);(Y);

}}

Page 10: Automatic Pool Allocation

10

Example [Lattner]Example [Lattner]

list *list *makeListmakeList(int Num(int Num, Pool *P, Pool *P) {) { list *New = list *New = pool_allocpool_alloc((P,P, sizeof(list)); sizeof(list)); New->Next = Num ? New->Next = Num ? makeListmakeList(Num-1(Num-1, P, P) : 0;) : 0; New->Data = Num; return New;New->Data = Num; return New;}}

void void twoListstwoLists( ) {( ) {

list *X = list *X = makeListmakeList(10);(10); list *Y = list *Y = makeListmakeList(100);(100); GL = Y;GL = Y; processListprocessList(X);(X); processListprocessList(Y);(Y); freeListfreeList(X);(X); freeListfreeList(Y);(Y);

}}

Page 11: Automatic Pool Allocation

11

Example [Lattner]Example [Lattner]

list *list *makeListmakeList(int Num(int Num, Pool *P, Pool *P) {) { list *New = list *New = pool_allocpool_alloc((P,P, sizeof(list)); sizeof(list)); New->Next = Num ? New->Next = Num ? makeListmakeList(Num-1(Num-1, P, P) : 0;) : 0; New->Data = Num; return New;New->Data = Num; return New;}}

void void twoListstwoLists( ) {( ) { Pool P1;Pool P1; pool_init(&P1);pool_init(&P1); list *X = list *X = makeListmakeList(10(10, &P1, &P1);); list *Y = list *Y = makeListmakeList(100);(100); GL = Y;GL = Y; processListprocessList(X);(X); processListprocessList(Y);(Y); freeListfreeList(X(X, &P1, &P1);); freeListfreeList(Y);(Y); pool_destroy(&P1);pool_destroy(&P1);}}

Page 12: Automatic Pool Allocation

12

Example [Lattner]Example [Lattner]

list *list *makeListmakeList(int Num(int Num, Pool *P, Pool *P) {) { list *New = list *New = pool_allocpool_alloc((P,P, sizeof(list)); sizeof(list)); New->Next = Num ? New->Next = Num ? makeListmakeList(Num-1(Num-1, P, P) : 0;) : 0; New->Data = Num; return New;New->Data = Num; return New;}}

void void twoListstwoLists( ( Pool *P2Pool *P2 ) { ) { Pool P1;Pool P1; pool_init(&P1);pool_init(&P1); list *X = list *X = makeListmakeList(10(10, &P1, &P1);); list *Y = list *Y = makeListmakeList(100(100, P2, P2);); GL = Y;GL = Y; processListprocessList(X);(X); processListprocessList(Y);(Y); freeListfreeList(X(X, &P1, &P1);); freeListfreeList(Y(Y, P2, P2);); pool_destroy(&P1);pool_destroy(&P1);}}

Page 13: Automatic Pool Allocation

13

DifficultiesDifficulties

• Function pointers Two functions with different properties might

be called (indirectly) at the same site

• Solution: Partition functions into equivalence classes Merge DS graphs

Page 14: Automatic Pool Allocation

14

DifficultiesDifficulties

• Global pools Pool arguments for heap-allocated globals

must be added to every function that touches the globals

Can be thousands of arguments in practice

• Solution: Use global variables for global pools Pool arguments grow with original arguments

Page 15: Automatic Pool Allocation

15

ResultsResults

• Small additional compile time <= 1.25 seconds in all experiments <= 3% of total compile time

• Low overhead <= 5% in most experiments

• Improved performance 5% to 20% in most experiments 2x and 10x in a few examples

Page 16: Automatic Pool Allocation

16

ResultsResults

• Limited discussion of corner cases

• Automatic pool allocation could decrease performance Decrease locality for certain access patterns Small pools on nearly-empty pages

Some techniques help address these issues

Page 17: Automatic Pool Allocation

17

ConclusionsConclusions

• Simple yet sophisticated data structure analysis, for data locality

• Experimentally validated

• Not obviously universally applicable