Giter Site home page Giter Site logo

m4drat / memplusplus Goto Github PK

View Code? Open in Web Editor NEW
52.0 5.0 4.0 1.27 MB

C++ memory allocator with smart GC

CMake 5.65% C++ 93.85% Shell 0.50%
cpp cplusplus gc garbage-collection garbage-collector allocator memory-allocator data-structures compacting layouting

memplusplus's People

Contributors

akoul02 avatar lithium1337mwfgtkam avatar m4drat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

memplusplus's Issues

General refactoring

  • Allocate should only allocate memory for an object. Create separate method for object construction and one more method to automatically allocate and construct objects.
  • Change inheritance scheme (We should only have MemoryManager/MemoryAllocator + GC as a member)
  • Inside GC, increase newly created arena size

Add more security features, e.g. chunk header xor-ing, better randomization, double-free checks, buffer overflow prevention, ...

  • heap canaries
  • randomized allocations? (probably it isn't possible)
  • headers encryption
  • better randomization of mmaped arenas (e.g. mimalloc: mi_unix_mmapx)
  • Top chunk checks
  • Checks on chunks merging
  • Replace std::terminate with std::abort?
  • On deallocate fill memory with zeroes
  • Check for invalid headers (for example: chunk header gets overwritten, so we need to check for invalid merging)
  • Check for invalid smart pointer initialization
  • Check for double-free
  • Check for invalid free

option(MPP_SECURE "Build with advanced security checks" OFF)

Performance comparisons (mimalloc, malloc, jemalloc) + cpu/memory Profiling

Specifically measure: Using valgrind to measure cache misses

Implement performance comparison with these memory allocators:

  • gcpp (only speed gain after compacting)
  • mimalloc (only allocation/deallocation speed)
  • rpmalloc (only allocation/deallocation speed)
  • jemalloc (only allocation/deallocation speed)
  • hoard (only allocation/deallocation speed)
  • supermalloc (only allocation/deallocation speed)
  • ptmalloc3 (only allocation/deallocation speed)
  • ptmalloc2 (only allocation/deallocation speed) - use latest libc
  • mem++ (speed gain after compacting + allocation/deallocation speed)
  • Mesh (only allocation/deallocation speed)
  • tcmalloc (only allocation/deallocation speed)

Useful links:

  1. rpmalloc-benchmark
  2. how-can-i-profile-c-code-running-on-linux
  3. easy_profiler
  4. prof
  5. VISUAL BENCHMARKING in C++ (how to measure performance visually)
  6. Google benchmark
  7. "Performance Matters" by Emery Berger
  8. Coz: Finding Code that Counts with Causal Profiling
  9. P2329-move_at_scale
  10. CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!"
  11. Intel v-tune
  12. github-gprof2dot
  13. How to benchamrk correctly: llvm

Don't forget to use clang stabilizer!

Add PROFILING definition and option to build

#!/bin/bash

# build the program (no special flags are needed)
g++ -std=c++11 cpuload.cpp -o cpuload

# run the program with callgrind; generates a file callgrind.out.12345 that can be viewed with kcachegrind
valgrind --tool=callgrind ./cpuload

# open profile.callgrind with kcachegrind
kcachegrind profile.callgrind
#!/bin/bash

# build the program; For our demo program, we specify -DWITHGPERFTOOLS to enable the gperftools specific #ifdefs
g++ -std=c++11 -DWITHGPERFTOOLS -lprofiler -g ../cpuload.cpp -o cpuload

# run the program; generates the profiling data file (profile.log in our example)
./cpuload

# convert profile.log to callgrind compatible format
pprof --callgrind ./cpuload profile.log > profile.callgrind

# open profile.callgrind with kcachegrind
kcachegrind profile.callgrind

SharedGcPtr class

  1. Calling of ctor/dtor
  2. update internal state of GC, while adding/removing SharedGcPtr.
  3. Different SharedGcPtr's that points to the same object.
  4. Initialization of smart pointers
1. auto ptr = SharedGcPtr<SharedGcPtr>((UserClass*)(void* ptr));
2. auto ptr = SharedGcPtr<SharedGcPtr>(SharedGcPtrptr);
3. auto ptr = SharedGcPtr<SharedGcPtr*>(SharedGcPtr* ptr);
  1. SharedGcPtr, that points bot to the beginning of chunk.
  2. Active objects iteration
  3. make_SharedGcPtr(Args...)

Info:

Refactor statistics system

  1. Refactor everything statistics-related (right now the system looks like a lot of dirty hacks)
  2. GC metrics: #67
  3. Use macros to define statistics-related things

Allocator general improvements

  • Add cache layer
  • Change allocation logic (firstly reuse all available space in free list, and only then allocate new arena)
  • Inside GC, increase newly created arena size

Tests for ChunkTreap

  1. Тест удаления конкретного чанка из дерева (с разными адресами, но одинаковыми размерами). (2 случая: 1-ый чанк лежит перед 2-ым, 1-ый чанк лежит после 2-го)

Update std::allocator interface

We already have default std::allocator interface that uses Allocate/Deallocate functions directly. But we are going to get rid of these functions in the future (due to some problems described in #30). So we have to refactor this interface in such a way, so it's possible to use it without presence of Allocate/Deallocate methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.