• Stars
    star
    1,618
  • Rank 28,920 (Top 0.6 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A memory allocator that automatically reduces the memory footprint of C/C++ applications.

Mesh: Compacting Memory Management for C/C++

Mesh is a drop in replacement for malloc(3) that can transparently recover from memory fragmentation without any changes to application code.

Mesh is described in detail in a paper (PDF) that appeared at PLDI 2019.

Or watch this talk by Bobby Powers at Strange Loop:

Compacting the Uncompactable

Mesh runs on Linux and macOS. Windows is a work in progress.

Mesh uses bazel as a build system, but wraps it in a Makefile, and has no runtime dependencies other than libc:

$ git clone https://github.com/plasma-umass/mesh
$ cd mesh
$ make; sudo make install
# example: run git with mesh as its allocator:
$ LD_PRELOAD=libmesh.so git status

Please open an issue if you have questions (or issues)!

But will it blend?

If you run a program linked against mesh (or with Mesh LD_PRELOADed), setting the variable MALLOCSTATS=1 will instruct mesh to print a summary at exit:

$ MALLOCSTATS=1 ./bin/redis-server-mesh ./redis.conf
25216:C 11 Mar 20:27:12.050 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
25216:C 11 Mar 20:27:12.050 # Redis version=4.0.2, bits=64, commit=dfe0d212, modified=0, pid=25216, just started
25216:C 11 Mar 20:27:12.050 # Configuration loaded
[...]
^C25216:signal-handler (1583983641) Received SIGINT scheduling shutdown...
25216:M 11 Mar 20:27:21.945 # User requested shutdown...
25216:M 11 Mar 20:27:21.945 * Removing the pid file.
25216:M 11 Mar 20:27:21.945 * Removing the unix socket file.
25216:M 11 Mar 20:27:21.945 # Redis is now ready to exit, bye bye...
MESH COUNT:         25918
Meshed MB (total):  101.2
Meshed pages HWM:   25918
Meshed MB HWM:      101.2
MH Alloc Count:     56775
MH Free  Count:     17
MH High Water Mark: 82687

Not all workloads experience fragmentation, so its possible that Mesh will have a small 'Meshed MB (total' number!

Implementation Overview

Mesh is built on Heap Layers, an infrastructure for building high performance memory allocators in C++ (see the paper for details.)

The entry point of the library is libmesh.cc. This file is where malloc, free and the instantiations of the Heap used for allocating program memory lives.

DEFINITIONS

  • Page: The smallest block of memory managed by the operating system, 4Kb on most architectures. Memory given to the allocator by the operating system is always in multiples of the page size, and aligned to the page size.
  • Span: A contiguous run of 1 or more pages. It is often larger than the page size to account for large allocations and amortize the cost of heap metadata.
  • Arena: A contiguous range of virtual address space we allocate out of. All allocations returned by malloc(3) reside within the arena.
  • GlobalHeap: The global heap carves out the Arena into Spans and performs meshing.
  • MiniHeap: Metadata for a Span -- at any time a live Span has a single MiniHeap owner. For small objects, MiniHeaps have a bitmap to track whether an allocation is live or freed.
  • ThreadLocalHeap: A collections of MiniHeaps and a ShuffleVector so that most allocations and free(3)s can be fast and lock-free.
  • ShuffleVector: A novel data structure that enables randomized allocation with bump-pointer-like speed.

More Repositories

1

scalene

Scalene: a high-performance, high-precision CPU, GPU, and memory profiler for Python with AI-powered optimization proposals
Python
12,131
star
2

coz

Coz: Causal Profiling
C
4,024
star
3

browsix

Browsix is a Unix-like operating system for the browser.
JavaScript
3,149
star
4

doppio

Breaks the browser language barrier (includes a plugin-free JVM).
TypeScript
2,150
star
5

ChatDBG

ChatDBG - AI-assisted debugging. Uses AI to answer 'why'
C++
772
star
6

slipcover

Near Zero-Overhead Python Code Coverage
Python
485
star
7

BLeak

BLeak: Automatically Debugging Memory Leaks in Web Applications
TypeScript
408
star
8

cwhy

"See why!" Explains and suggests fixes for compile-time errors for C, C++, C#, Go, Java, LaTeX, PHP, Python, Ruby, Rust, and TypeScript
C++
272
star
9

sqlwrite

SQLwrite: AI in your DBMS! Automatically converts natural language queries to SQL.
C
106
star
10

NextDoor

Graph Sampling using GPU
Cuda
49
star
11

DataDebug

Excel 2010/2013 add-in that automatically finds errors in spreadsheets
C#
46
star
12

coverup

Automatic AI-powered test suite generator
Python
37
star
13

systemgo

Init system in Go, intended to run on Browsix and other Unix-like OS. Part of GSoC 2016 project.
Go
36
star
14

sheriff

Sheriff consists of two tools: Sheriff-Detect, a false-sharing detector, and Sheriff-Protect, a false-sharing eliminator that you can link with your code to eliminate false sharing.
C++
29
star
15

DoubleTake

Evidence-based dynamic analysis: a fast checker for memory errors.
C
21
star
16

commentator

Automatically comments Python code, adding docstrings and type annotations, with optional translation to other languages.
Python
20
star
17

Predator

Predator: Predictive False Sharing Detection
C
19
star
18

memory-landscape

The space of memory management research and systems produced by the PLASMA lab (https://plasma-umass.org).
16
star
19

snakefish

parallel Python
Python
13
star
20

entroprise

measure entropy of memory allocators
C++
12
star
21

parcel

An Excel formula parser
C#
12
star
22

Rehearsal

Rehearsal: A Configuration Verification Tool for Puppet
Scala
12
star
23

Hound

Hound memory leak detector
C++
11
star
24

smash-project

Smash compressing allocator project
C++
10
star
25

browsix-spec

JavaScript
9
star
26

Archipelago

Archipelago memory allocator
C
8
star
27

simplesocket

A simple socket wrapper for C++.
C++
8
star
28

pythoness

Pythoness: use natural language to define Python functions.
Python
7
star
29

compsci631

Support code for Programming Languages (COMPSCI631)
OCaml
7
star
30

Tortoise

Tortoise: Interactive System Configuration Repair
Scala
6
star
31

scalene-gui

Scalene web GUI
JavaScript
5
star
32

llm-utils

Utilities for our LLM projects (CWhy, ChatDBG, ...).
Python
5
star
33

transparentFS

TransparentFS code, paper, and slides
C
5
star
34

homebrew-scalene

Homebrew tap for Scalene (emeryberger/scalene)
Ruby
4
star
35

GSoC

Description of our Google Summer of Code projects for 2015
4
star
36

vam

Implementation from "A Locality-Improving Dynamic Memory Allocator", Feng and Berger, MSP 2005
C++
4
star
37

HeapToss

HeapToss is an LLVM compiler pass that moves stack variables that may escape their declaring function's context into the heap.
3
star
38

pytest-cleanslate

Python
3
star
39

jsvm

JavaScript
2
star
40

GSoC-2013

Google Summer of Code 2013
2
star
41

plasma-umass.github.io

home page
HTML
2
star
42

spl

Rust
2
star
43

doppio_jcl

Scripts that produce a version of the Java Class Library and Java Home in a way that is compatible with DoppioJVM.
TypeScript
2
star
44

nextdoor-eurosys21

HTML
1
star
45

mesh-testsuite

C
1
star
46

ChatSheet

Python
1
star
47

custom-public

Jupyter Notebook
1
star
48

proto

probabilistic race tolerance
C
1
star
49

wasm-gc-template

C++
1
star
50

typissed

Generates MTurk typo jobs
C#
1
star
51

scalene-benchmarks

Benchmarks comparing Scalene with other commonly-used profilers
Python
1
star
52

emcc_control

C
1
star
53

transparentMM

Transparent memory management
1
star