SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
Reconsidering
Custom Memory Allocation

Emery Berger, Ben Zorn, Kathryn McKinley




     UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE
Custom Memory Allocation
    Programmers replace                              Very common practice
                                                
    new/delete, bypassing                                 Apache, gcc, lcc, STL,
                                                      

    system allocator                                      database servers…
                                                          Language-level
        Reduce runtime – often                        
    
                                                          support in C++
        Expand functionality – sometimes
    

                                                          Widely recommended
        Reduce space – rarely                         
    



                                                           “Use custom
                                                             allocators”

           UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE            2
Drawbacks of Custom Allocators
    Avoiding system allocator:


        More code to maintain & debug
    

        Can’t use memory debuggers
    

        Not modular or robust:
    

              Mix memory from custom
          

              and general-purpose allocators → crash!
    Increased burden on programmers



          Are custom allocators really a win?
        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   3
Overview
    Introduction


    Perceived benefits and drawbacks


    Three main kinds of custom allocators


    Comparison with general-purpose allocators


    Advantages and drawbacks of regions


    Reaps – generalization of regions & heaps





     UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   4
(1) Per-Class Allocators
    Recycle freed objects from a free list


    a = new Class1;               Class1
                                                       Fast
                                  free list
    b = new Class1;                                +
    c = new Class1;                                         Linked list operations
                                                        +
                                     a
    delete a;                                          Simple
                                                   +
    delete b;
                                                            Identical semantics
                                    b                   +
    delete c;
                                                            C++ language support
                                                        +
    a = new Class1;
                                     c
                                                       Possibly space-inefficient
    b = new Class1;                                -
    c = new Class1;




           UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE              5
(II) Custom Patterns
             Tailor-made to fit allocation patterns
         

                 Example: 197.parser (natural language parser)
             


                              db
                         a             c
char[MEMORY_LIMIT]

                       end_of_array
                           end_of_array
                               end_of_array
                                  end_of_array
                                      end_of_array
       a = xalloc(8);                       Fast
                                       +
       b = xalloc(16);                           Pointer-bumping allocation
                                             +
       c = xalloc(8);
                                       - Brittle
       xfree(b);
                                             - Fixed memory size
       xfree(c);
                                             - Requires stack-like lifetimes
       d = xalloc(8);
                 UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   6
(III) Regions
    Separate areas, deletion only en masse


    regioncreate(r)               r
    regionmalloc(r, sz)
    regiondelete(r)
                                                     - Risky
    Fast
+

                                                          - Dangling
         Pointer-bumping allocation
     +

                                                            references
         Deletion of chunks
     +

                                                          - Too much space
    Convenient
+

         One call frees all memory
     +


             Increasingly popular custom allocator
         
              UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   7
Overview
    Introduction


    Perceived benefits and drawbacks


    Three main kinds of custom allocators


    Comparison with general-purpose allocators


    Advantages and drawbacks of regions


    Reaps – generalization of regions & heaps





     UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   8
Custom Allocators Are Faster…
                                Runtime - Custom Allocator Benchmarks

                                                           Custom             Win32

                         1.75
    Normalized Runtime




                                       non-regions                             regions
                          1.5
                         1.25
                            1
                         0.75
                          0.5
                         0.25
                           0
                                                              r




                                                                                    he
                                    er




                                                                                                  lle
                                                  ze
                                    m




                                                                          c




                                                                                            c
                                                            vp


                                                                       gc




                                                                                         lc
                                 rs



                                 si




                                                                                                ud
                                                                                  ac
                                                ee



                                                          5.


                                                                     6.
                               d-
                              pa




                                                                                                m
                                                       17




                                                                               ap
                                             br




                                                                  17
                            xe
                            7.




                                           c-
                         bo
                         19




                   As good as and sometimes much faster than Win32

                           UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE                 9
Not So Fast…
                                       Runtime - Custom Allocator Benchmarks
                                                               Custom    Win32     DLmalloc

                         1.75
                                            non-regions                           regions
    Normalized Runtime




                          1.5
                         1.25
                           1
                         0.75
                          0.5
                         0.25
                           0




                                                                                                      lle
                                                           e



                                                                     r




                                                                                       he



                                                                                                c
                                  r


                                                m




                                                                              c
                                                                   vp
                                   e




                                                                                              lc
                                                         z




                                                                            gc
                                              si




                                                                                                     ud
                                rs




                                                      ee




                                                                                    ac
                                                                 5.
                                            d-




                                                                          6.
                             pa




                                                                                                    m
                                                      br


                                                                17




                                                                                  ap
                                                                         17
                                        xe
                           7.




                                                    c-
                                       bo
                          19




                         DLmalloc: as fast or faster for most benchmarks

                           UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE                     10
The Lea Allocator (DLmalloc 2.7.0)
    Mature public-domain general-purpose

    allocator
    Optimized for common allocation patterns


        Per-size quicklists ≈ per-class allocation
    

    Deferred coalescing

    (combining adjacent free objects)
        Highly-optimized fastpath
    

    Space-efficient




        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   11
Space Consumption: Mixed Results
                                      Space - Custom Allocator Benchmarks

                                                         Custom        DLmalloc

                   1.75
                                  non-regions                                     regions
Normalized Space




                    1.5
                   1.25
                      1
                   0.75
                    0.5
                   0.25
                      0




                                                                                                   lle
                                                     e



                                                              r




                                                                                  he



                                                                                            c
                            r


                                        sim




                                                                       c
                                                            vp
                             e




                                                                                            lc
                                                   z




                                                                     gc




                                                                                                  ud
                          rs




                                                ee




                                                                              ac
                                                          5.
                                      d-




                                                                   6.
                      pa




                                                                                                 m
                                                br


                                                         17




                                                                            ap
                                                                  17
                                  xe
                    7.




                                              c-
                                 bo
                   19




                     UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE                        12
Overview
    Introduction


    Perceived benefits and drawbacks


    Three main kinds of custom allocators


    Comparison with general-purpose allocators


    Advantages and drawbacks of regions


    Reaps – generalization of regions & heaps





     UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   13
Regions – Pros and Cons
    Fast, convenient, etc.
+

    Avoid resource leaks (e.g., Apache)
+

         Tear down memory for terminated connections
     



    No individual object deletion
-
         Unbounded memory consumption
    
         (producer-consumer, long-running computations,
          off-the-shelf programs)
     Apache: vulnerable to DoS, memory leaks

         UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   14
Reap Hybrid Allocator
          Reap = region + heap
      

               Adds individual object deletion & heap
          

reapcreate(r)
                             r
reapmalloc(r, sz)
reapfree(r,p)
reapdelete(r)

          Can reduce memory consumption
      +

          Fast
      +

               Adapts to use (region or heap style)
          +

               Cheap deletion
          +

              UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   15
Reap Runtime
                             Runtime - Custom Allocation Benchmarks

                                                  Custom        Win32    DLmalloc       Reap

                     1.75
Normalized runtime




                                        non-regions                          regions
                      1.5
                     1.25
                        1
                     0.75
                      0.5
                     0.25
                        0




                                                                                                 lle
                                                       e


                                                                r




                                                                                   he



                                                                                         c
                              r


                                           im




                                                                         c
                                                              vp
                               e




                                                                                         lc
                                                     z




                                                                       gc




                                                                                                ud
                            rs




                                                  ee
                                        -s




                                                                               ac
                                                            5.


                                                                     6.
                        pa


                                       d




                                                                                               m
                                                  br


                                                           17




                                                                              ap
                                                                    17
                                    xe
                      7.




                                                c-
                                   bo
                     19




                       UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE                    16
Reap Space
                             Space - Custom Allocator Benchmarks
                                                         Custom    DLmalloc       Reap

                   1.75
                                      non-regions                                regions
Normalized Space




                    1.5
                   1.25
                      1
                   0.75
                    0.5
                   0.25
                      0




                                                                                                  lle
                                                     e


                                                               r




                                                                                 he



                                                                                           c
                            r


                                        sim




                                                                        c
                                                             vp
                             e




                                                                                           lc
                                                   z




                                                                      gc




                                                                                                 ud
                          rs




                                                ee




                                                                              ac
                                                           5.
                                      d-




                                                                    6.
                      pa




                                                                                                m
                                                br


                                                          17




                                                                            ap
                                                                   17
                                  xe
                    7.




                                              c-
                                 bo
                   19




                     UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE                       17
Reap: Best of Both Worlds
    Allows mixing of regions and new/delete


    Case study:


     New Apache module “mod_bc”

              bc: C-based arbitrary-precision calculator
          

              Changed 20 lines out of 8000
          


        Benchmark: compute 1000th prime
    

              With Reap: 240K
          

              Without Reap: 7.4MB
          



        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   18
Conclusions and Future Work
    Empirical study of custom allocators


        Lea allocator often as fast or faster
    

        Non-region custom allocation ineffective
    

    Reap: region performance without drawbacks


    Future work:


        Reduce space with per-page bitmaps
    

        Combine with scalable general-purpose
    

        allocator (e.g., Hoard)

        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   19
Software


http://www.cs.umass.edu/~emery
(Reap: part of Heap Layers distribution)

http://g.oswego.edu
(DLmalloc 2.7.0)


    UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   20
If You Can Read This,
I Went Too Far




   UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   21
Backup Slides




   UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   22
Experimental Methodology

    Comparing to general-purpose


    allocators
        Same semantics: no problem
    

              E.g., disable per-class allocators
          


        Different semantics: use emulator
    

            Uses general-purpose allocator
          

           Adds bookkeeping to support

            region semantics
        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   23
Why Did They Do That?
    Recommended practice


    Premature optimization


        Microbenchmarks vs. actual performance
    

    Drift


        Not bottleneck anymore
    

    Improved competition


        Modern allocators are better
    




        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   24
Reaps as Regions: Runtime
                                  Runtime - Region-Based Benchmarks

                                         Custom   Win32   DLmalloc   Reap

                     1.75

                      1.5
Normalized Runtime




                     1.25

                       1

                     0.75

                      0.5

                     0.25

                       0
                                        lcc                           mudlle


                      Reap performance nearly matches regions

                        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   25
Using Reap as Regions
                                       Runtime - Region-Based Benchmarks

                                  Original   Win32    DLmalloc   WinHeap   Vmalloc   Reap
                                                   4.08
                      2.5


                       2
 Normalized Runtime




                      1.5


                       1


                      0.5


                       0
                                             lcc                           mudlle


Reap performance nearly matches regions
                            UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE    26
Drawbacks of Regions
    Can’t reclaim memory within regions


        Bad for long-running computations,
    

        producer-consumer patterns,
        “malloc/free” programs
        unbounded memory consumption
    




    Current situation for Apache:


        vulnerable to denial-of-service
    

        limits runtime of connections
    

        limits module programming
    


        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   27
Use Custom Allocators?
    Strongly recommended by practitioners


    Little hard data on performance/space

    improvements
        Only one previous study [Zorn 1992]
    

        Focused on just one type of allocator
    

        Custom allocators: waste of time
    

              Small gains, bad allocators
          


    Different allocators better? Trade-offs?




        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   28
Kinds of Custom Allocators
    Three basic types of custom allocators


        Per-class
    

              Fast
          

        Custom patterns
    

              Fast, but very special-purpose
          

        Regions
    

              Fast, possibly more space-efficient
          

              Convenient
          

              Variants: nested, obstacks
          




        UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE   29
Optimization Opportunity
                                  Time Spent in Memory Operations

                                             Memory Operations                Other

                100
% of runtime




                    80
                    60
                    40
                    20
                    0
                                 sim




                                                                                         ll e
                                                                                 lcc
                                             ze




                                                                 cc




                                                                                                  e
                                                                           e
                                                       pr
                           r
                         se




                                                                                                ag
                                                                          h




                                                                                       ud
                                                      v

                                                                g
                                           e




                                                                       ac
                                 d-




                                                   5.
                    ar




                                                             6.
                                        re




                                                                                              er
                                                                                       m
                                                                      ap
                                                  17
                               xe




                                                            17
                   p




                                         b




                                                                                            Av
                7.




                                      c-
                          bo
               19




                 UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE                         30

Mais conteúdo relacionado

Destaque (6)

Operating Systems 1 (9/12) - Memory Management Concepts
Operating Systems 1 (9/12) - Memory Management ConceptsOperating Systems 1 (9/12) - Memory Management Concepts
Operating Systems 1 (9/12) - Memory Management Concepts
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
chapter 2 memory and process management
chapter 2 memory and process managementchapter 2 memory and process management
chapter 2 memory and process management
 
Memory management in Linux
Memory management in LinuxMemory management in Linux
Memory management in Linux
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Zettabyte File Storage System
Zettabyte File Storage SystemZettabyte File Storage System
Zettabyte File Storage System
 

Semelhante a Reconsidering Custom Memory Allocation

Practical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyPractical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in Groovy
Guillaume Laforge
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag
Marcel Bruch
 
Ph d colloquium 2
Ph d colloquium 2Ph d colloquium 2
Ph d colloquium 2
Rishi Roy
 
Kamaelia-ACCU-20050422
Kamaelia-ACCU-20050422Kamaelia-ACCU-20050422
Kamaelia-ACCU-20050422
journeyer
 
32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlays
myrajendra
 
Close encounters in MDD: when Models meet Code
Close encounters in MDD: when Models meet CodeClose encounters in MDD: when Models meet Code
Close encounters in MDD: when Models meet Code
lbergmans
 
Close Encounters in MDD: when models meet code
Close Encounters in MDD: when models meet codeClose Encounters in MDD: when models meet code
Close Encounters in MDD: when models meet code
lbergmans
 

Semelhante a Reconsidering Custom Memory Allocation (20)

Operating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory ManagementOperating Systems - Dynamic Memory Management
Operating Systems - Dynamic Memory Management
 
Operating Systems - Intro to C++
Operating Systems - Intro to C++Operating Systems - Intro to C++
Operating Systems - Intro to C++
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
Practical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyPractical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in Groovy
 
Operating Systems - Architecture
Operating Systems - ArchitectureOperating Systems - Architecture
Operating Systems - Architecture
 
Kamaelia - Networking Using Generators
Kamaelia - Networking Using GeneratorsKamaelia - Networking Using Generators
Kamaelia - Networking Using Generators
 
IN4308 1
IN4308 1IN4308 1
IN4308 1
 
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
Trends in Programming Technology you might want to keep an eye on af Bent Tho...Trends in Programming Technology you might want to keep an eye on af Bent Tho...
Trends in Programming Technology you might want to keep an eye on af Bent Tho...
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag
 
XS Boston 2008 Paravirt Ops in Linux IA64
XS Boston 2008 Paravirt Ops in Linux IA64XS Boston 2008 Paravirt Ops in Linux IA64
XS Boston 2008 Paravirt Ops in Linux IA64
 
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
 
Ph d colloquium 2
Ph d colloquium 2Ph d colloquium 2
Ph d colloquium 2
 
Kamaelia-ACCU-20050422
Kamaelia-ACCU-20050422Kamaelia-ACCU-20050422
Kamaelia-ACCU-20050422
 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlays
 
Rubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystemRubinius - Improving the Rails ecosystem
Rubinius - Improving the Rails ecosystem
 
Close encounters in MDD: when Models meet Code
Close encounters in MDD: when Models meet CodeClose encounters in MDD: when Models meet Code
Close encounters in MDD: when Models meet Code
 
Close Encounters in MDD: when models meet code
Close Encounters in MDD: when models meet codeClose Encounters in MDD: when models meet code
Close Encounters in MDD: when models meet code
 
C++ in kernel mode
C++ in kernel modeC++ in kernel mode
C++ in kernel mode
 
Scalable Elastic Systems Architecture (SESA)
Scalable Elastic Systems Architecture (SESA)Scalable Elastic Systems Architecture (SESA)
Scalable Elastic Systems Architecture (SESA)
 

Mais de Emery Berger

Dthreads: Efficient Deterministic Multithreading
Dthreads: Efficient Deterministic MultithreadingDthreads: Efficient Deterministic Multithreading
Dthreads: Efficient Deterministic Multithreading
Emery Berger
 
Programming with People
Programming with PeopleProgramming with People
Programming with People
Emery Berger
 
Stabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance EvaluationStabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance Evaluation
Emery Berger
 
Operating Systems - Advanced File Systems
Operating Systems - Advanced File SystemsOperating Systems - Advanced File Systems
Operating Systems - Advanced File Systems
Emery Berger
 
Operating Systems - Queuing Systems
Operating Systems - Queuing SystemsOperating Systems - Queuing Systems
Operating Systems - Queuing Systems
Emery Berger
 
Operating Systems - Distributed Parallel Computing
Operating Systems - Distributed Parallel ComputingOperating Systems - Distributed Parallel Computing
Operating Systems - Distributed Parallel Computing
Emery Berger
 
Operating Systems - Concurrency
Operating Systems - ConcurrencyOperating Systems - Concurrency
Operating Systems - Concurrency
Emery Berger
 
Operating Systems - Advanced Synchronization
Operating Systems - Advanced SynchronizationOperating Systems - Advanced Synchronization
Operating Systems - Advanced Synchronization
Emery Berger
 

Mais de Emery Berger (20)

Doppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language BarrierDoppio: Breaking the Browser Language Barrier
Doppio: Breaking the Browser Language Barrier
 
Dthreads: Efficient Deterministic Multithreading
Dthreads: Efficient Deterministic MultithreadingDthreads: Efficient Deterministic Multithreading
Dthreads: Efficient Deterministic Multithreading
 
Programming with People
Programming with PeopleProgramming with People
Programming with People
 
Stabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance EvaluationStabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance Evaluation
 
DieHarder (CCS 2010, WOOT 2011)
DieHarder (CCS 2010, WOOT 2011)DieHarder (CCS 2010, WOOT 2011)
DieHarder (CCS 2010, WOOT 2011)
 
Operating Systems - Advanced File Systems
Operating Systems - Advanced File SystemsOperating Systems - Advanced File Systems
Operating Systems - Advanced File Systems
 
Operating Systems - File Systems
Operating Systems - File SystemsOperating Systems - File Systems
Operating Systems - File Systems
 
Operating Systems - Networks
Operating Systems - NetworksOperating Systems - Networks
Operating Systems - Networks
 
Operating Systems - Queuing Systems
Operating Systems - Queuing SystemsOperating Systems - Queuing Systems
Operating Systems - Queuing Systems
 
Operating Systems - Distributed Parallel Computing
Operating Systems - Distributed Parallel ComputingOperating Systems - Distributed Parallel Computing
Operating Systems - Distributed Parallel Computing
 
Operating Systems - Concurrency
Operating Systems - ConcurrencyOperating Systems - Concurrency
Operating Systems - Concurrency
 
Operating Systems - Advanced Synchronization
Operating Systems - Advanced SynchronizationOperating Systems - Advanced Synchronization
Operating Systems - Advanced Synchronization
 
Operating Systems - Synchronization
Operating Systems - SynchronizationOperating Systems - Synchronization
Operating Systems - Synchronization
 
Processes and Threads
Processes and ThreadsProcesses and Threads
Processes and Threads
 
Virtual Memory and Paging
Virtual Memory and PagingVirtual Memory and Paging
Virtual Memory and Paging
 
Operating Systems - Virtual Memory
Operating Systems - Virtual MemoryOperating Systems - Virtual Memory
Operating Systems - Virtual Memory
 
MC2: High-Performance Garbage Collection for Memory-Constrained Environments
MC2: High-Performance Garbage Collection for Memory-Constrained EnvironmentsMC2: High-Performance Garbage Collection for Memory-Constrained Environments
MC2: High-Performance Garbage Collection for Memory-Constrained Environments
 
Vam: A Locality-Improving Dynamic Memory Allocator
Vam: A Locality-Improving Dynamic Memory AllocatorVam: A Locality-Improving Dynamic Memory Allocator
Vam: A Locality-Improving Dynamic Memory Allocator
 
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory ManagementQuantifying the Performance of Garbage Collection vs. Explicit Memory Management
Quantifying the Performance of Garbage Collection vs. Explicit Memory Management
 
Garbage Collection without Paging
Garbage Collection without PagingGarbage Collection without Paging
Garbage Collection without Paging
 

Último

Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
amitlee9823
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
allensay1
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
dlhescort
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
daisycvs
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
lizamodels9
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 

Último (20)

Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
 
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 

Reconsidering Custom Memory Allocation

  • 1. Reconsidering Custom Memory Allocation Emery Berger, Ben Zorn, Kathryn McKinley UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE
  • 2. Custom Memory Allocation Programmers replace Very common practice   new/delete, bypassing Apache, gcc, lcc, STL,  system allocator database servers… Language-level Reduce runtime – often   support in C++ Expand functionality – sometimes  Widely recommended Reduce space – rarely   “Use custom allocators” UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 2
  • 3. Drawbacks of Custom Allocators Avoiding system allocator:  More code to maintain & debug  Can’t use memory debuggers  Not modular or robust:  Mix memory from custom  and general-purpose allocators → crash! Increased burden on programmers  Are custom allocators really a win? UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 3
  • 4. Overview Introduction  Perceived benefits and drawbacks  Three main kinds of custom allocators  Comparison with general-purpose allocators  Advantages and drawbacks of regions  Reaps – generalization of regions & heaps  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 4
  • 5. (1) Per-Class Allocators Recycle freed objects from a free list  a = new Class1; Class1 Fast free list b = new Class1; + c = new Class1; Linked list operations + a delete a; Simple + delete b; Identical semantics b + delete c; C++ language support + a = new Class1; c Possibly space-inefficient b = new Class1; - c = new Class1; UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 5
  • 6. (II) Custom Patterns Tailor-made to fit allocation patterns  Example: 197.parser (natural language parser)  db a c char[MEMORY_LIMIT] end_of_array end_of_array end_of_array end_of_array end_of_array a = xalloc(8); Fast + b = xalloc(16); Pointer-bumping allocation + c = xalloc(8); - Brittle xfree(b); - Fixed memory size xfree(c); - Requires stack-like lifetimes d = xalloc(8); UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 6
  • 7. (III) Regions Separate areas, deletion only en masse  regioncreate(r) r regionmalloc(r, sz) regiondelete(r) - Risky Fast + - Dangling Pointer-bumping allocation + references Deletion of chunks + - Too much space Convenient + One call frees all memory + Increasingly popular custom allocator  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 7
  • 8. Overview Introduction  Perceived benefits and drawbacks  Three main kinds of custom allocators  Comparison with general-purpose allocators  Advantages and drawbacks of regions  Reaps – generalization of regions & heaps  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 8
  • 9. Custom Allocators Are Faster… Runtime - Custom Allocator Benchmarks Custom Win32 1.75 Normalized Runtime non-regions regions 1.5 1.25 1 0.75 0.5 0.25 0 r he er lle ze m c c vp gc lc rs si ud ac ee 5. 6. d- pa m 17 ap br 17 xe 7. c- bo 19 As good as and sometimes much faster than Win32  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 9
  • 10. Not So Fast… Runtime - Custom Allocator Benchmarks Custom Win32 DLmalloc 1.75 non-regions regions Normalized Runtime 1.5 1.25 1 0.75 0.5 0.25 0 lle e r he c r m c vp e lc z gc si ud rs ee ac 5. d- 6. pa m br 17 ap 17 xe 7. c- bo 19 DLmalloc: as fast or faster for most benchmarks  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 10
  • 11. The Lea Allocator (DLmalloc 2.7.0) Mature public-domain general-purpose  allocator Optimized for common allocation patterns  Per-size quicklists ≈ per-class allocation  Deferred coalescing  (combining adjacent free objects) Highly-optimized fastpath  Space-efficient  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 11
  • 12. Space Consumption: Mixed Results Space - Custom Allocator Benchmarks Custom DLmalloc 1.75 non-regions regions Normalized Space 1.5 1.25 1 0.75 0.5 0.25 0 lle e r he c r sim c vp e lc z gc ud rs ee ac 5. d- 6. pa m br 17 ap 17 xe 7. c- bo 19 UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 12
  • 13. Overview Introduction  Perceived benefits and drawbacks  Three main kinds of custom allocators  Comparison with general-purpose allocators  Advantages and drawbacks of regions  Reaps – generalization of regions & heaps  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 13
  • 14. Regions – Pros and Cons Fast, convenient, etc. + Avoid resource leaks (e.g., Apache) + Tear down memory for terminated connections  No individual object deletion - Unbounded memory consumption  (producer-consumer, long-running computations, off-the-shelf programs)  Apache: vulnerable to DoS, memory leaks UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 14
  • 15. Reap Hybrid Allocator Reap = region + heap  Adds individual object deletion & heap  reapcreate(r) r reapmalloc(r, sz) reapfree(r,p) reapdelete(r) Can reduce memory consumption + Fast + Adapts to use (region or heap style) + Cheap deletion + UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 15
  • 16. Reap Runtime Runtime - Custom Allocation Benchmarks Custom Win32 DLmalloc Reap 1.75 Normalized runtime non-regions regions 1.5 1.25 1 0.75 0.5 0.25 0 lle e r he c r im c vp e lc z gc ud rs ee -s ac 5. 6. pa d m br 17 ap 17 xe 7. c- bo 19 UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 16
  • 17. Reap Space Space - Custom Allocator Benchmarks Custom DLmalloc Reap 1.75 non-regions regions Normalized Space 1.5 1.25 1 0.75 0.5 0.25 0 lle e r he c r sim c vp e lc z gc ud rs ee ac 5. d- 6. pa m br 17 ap 17 xe 7. c- bo 19 UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 17
  • 18. Reap: Best of Both Worlds Allows mixing of regions and new/delete  Case study:   New Apache module “mod_bc” bc: C-based arbitrary-precision calculator  Changed 20 lines out of 8000  Benchmark: compute 1000th prime  With Reap: 240K  Without Reap: 7.4MB  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 18
  • 19. Conclusions and Future Work Empirical study of custom allocators  Lea allocator often as fast or faster  Non-region custom allocation ineffective  Reap: region performance without drawbacks  Future work:  Reduce space with per-page bitmaps  Combine with scalable general-purpose  allocator (e.g., Hoard) UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 19
  • 20. Software http://www.cs.umass.edu/~emery (Reap: part of Heap Layers distribution) http://g.oswego.edu (DLmalloc 2.7.0) UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 20
  • 21. If You Can Read This, I Went Too Far UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 21
  • 22. Backup Slides UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 22
  • 23. Experimental Methodology Comparing to general-purpose  allocators Same semantics: no problem  E.g., disable per-class allocators  Different semantics: use emulator  Uses general-purpose allocator   Adds bookkeeping to support region semantics UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 23
  • 24. Why Did They Do That? Recommended practice  Premature optimization  Microbenchmarks vs. actual performance  Drift  Not bottleneck anymore  Improved competition  Modern allocators are better  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 24
  • 25. Reaps as Regions: Runtime Runtime - Region-Based Benchmarks Custom Win32 DLmalloc Reap 1.75 1.5 Normalized Runtime 1.25 1 0.75 0.5 0.25 0 lcc mudlle Reap performance nearly matches regions  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 25
  • 26. Using Reap as Regions Runtime - Region-Based Benchmarks Original Win32 DLmalloc WinHeap Vmalloc Reap 4.08 2.5 2 Normalized Runtime 1.5 1 0.5 0 lcc mudlle Reap performance nearly matches regions UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 26
  • 27. Drawbacks of Regions Can’t reclaim memory within regions  Bad for long-running computations,  producer-consumer patterns, “malloc/free” programs unbounded memory consumption  Current situation for Apache:  vulnerable to denial-of-service  limits runtime of connections  limits module programming  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 27
  • 28. Use Custom Allocators? Strongly recommended by practitioners  Little hard data on performance/space  improvements Only one previous study [Zorn 1992]  Focused on just one type of allocator  Custom allocators: waste of time  Small gains, bad allocators  Different allocators better? Trade-offs?  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 28
  • 29. Kinds of Custom Allocators Three basic types of custom allocators  Per-class  Fast  Custom patterns  Fast, but very special-purpose  Regions  Fast, possibly more space-efficient  Convenient  Variants: nested, obstacks  UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 29
  • 30. Optimization Opportunity Time Spent in Memory Operations Memory Operations Other 100 % of runtime 80 60 40 20 0 sim ll e lcc ze cc e e pr r se ag h ud v g e ac d- 5. ar 6. re er m ap 17 xe 17 p b Av 7. c- bo 19 UNIVERSITY OF MASSACHUSETTS • DEPARTMENT OF COMPUTER SCIENCE 30