Skip to content
Permalink
Browse files

test: large-alloc stress test program from #36

  • Loading branch information...
bpowers committed Mar 7, 2019
1 parent 7d2f22c commit 5363c1e96bf4943068fa3518d1a0839ce5ec54f6
Showing with 23 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 GNUmakefile
  3. +19 −0 src/test/global-large-stress.cc
@@ -31,6 +31,7 @@ __pycache__
/src/test/local-alloc-tcmalloc
/src/test/local-alloc-jemalloc
/src/test/local-alloc-mesh
/src/test/global-large-stress
/test/docker/*/mstatgcc
/test/docker/*/mstat
/test/spec/data
@@ -176,6 +176,9 @@ src/test/big-alloc-glibc: src/test/big-alloc.c $(CONFIG)
src/test/thread-example: src/test/thread.cc $(CONFIG)
$(CXX) -std=c++11 -pipe -fno-builtin-malloc -fno-omit-frame-pointer -g -o $@ $< -L$(PWD) -lmesh -Wl,-rpath,"$(PWD)" -lpthread

src/test/global-large-stress: src/test/global-large-stress.cc $(CONFIG)
$(CXX) -pipe -fno-builtin-malloc -fno-omit-frame-pointer -g -O3 -DNDEBUG -Isrc -Isrc/vendor/Heap-Layers -o $@ $< -L$(PWD) -lmesh -Wl,-rpath,"$(PWD)"

src/test/larson-mesh: src/test/larson.cc $(CONFIG)
$(CXX) -pipe -fno-builtin-malloc -fno-omit-frame-pointer -g -O3 -DNDEBUG -Isrc -Isrc/vendor/Heap-Layers -o $@ $< -L$(PWD) -lmesh -Wl,-rpath,"$(PWD)" -lpthread

@@ -0,0 +1,19 @@
#include <cstdlib>
#include <vector>

static constexpr size_t kMinAllocSz = 800000;
static constexpr size_t kMaxAllocSz = 900000;
static constexpr unsigned kMaxLiveAlloc = 128; // keep no more than 128 * kMaxAllocSz memory allocated.

int main(void) {
std::vector<void *> alloc(kMaxLiveAlloc, nullptr);

while (1) {
const size_t ix = rand() % kMaxLiveAlloc;
const size_t sz = (rand() % (kMaxAllocSz - kMinAllocSz)) + kMinAllocSz;

free(alloc[ix]);
alloc[ix] = malloc(sz);
}
return 0;
}

0 comments on commit 5363c1e

Please sign in to comment.
You can’t perform that action at this time.