Skip to content

Commit

Permalink
Set tcmalloc heap limit prior to testing oom
Browse files Browse the repository at this point in the history
Otherwise it can take long time to OOM on osex.
  • Loading branch information
alk committed Mar 1, 2021
1 parent c939dd5 commit a015377
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/tcmalloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ using tcmalloc::Static;
using tcmalloc::ThreadCache;

DECLARE_double(tcmalloc_release_rate);
DECLARE_int64(tcmalloc_heap_limit_mb);

// Those common architectures are known to be safe w.r.t. aliasing function
// with "extra" unused args to function with fewer arguments (e.g.
Expand Down Expand Up @@ -835,6 +836,12 @@ class TCMallocImplementation : public MallocExtension {
return true;
}

if (strcmp(name, "tcmalloc.heap_limit_mb") == 0) {
SpinLockHolder l(Static::pageheap_lock());
*value = FLAGS_tcmalloc_heap_limit_mb;
return true;
}

return false;
}

Expand All @@ -853,6 +860,12 @@ class TCMallocImplementation : public MallocExtension {
return true;
}

if (strcmp(name, "tcmalloc.heap_limit_mb") == 0) {
SpinLockHolder l(Static::pageheap_lock());
FLAGS_tcmalloc_heap_limit_mb = value;
return true;
}

return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/tests/tcmalloc_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1615,11 +1615,16 @@ static int RunAllTests(int argc, char** argv) {
// Check that large allocations fail with NULL instead of crashing
#ifndef DEBUGALLOCATION // debug allocation takes forever for huge allocs
fprintf(LOGSTREAM, "Testing out of memory\n");
size_t old_limit;
CHECK(MallocExtension::instance()->GetNumericProperty("tcmalloc.heap_limit_mb", &old_limit));
// Don't exercise more than 1 gig, no need to.
CHECK(MallocExtension::instance()->SetNumericProperty("tcmalloc.heap_limit_mb", 1 << 10));
for (int s = 0; ; s += (10<<20)) {
void* large_object = rnd.alloc(s);
if (large_object == NULL) break;
free(large_object);
}
CHECK(MallocExtension::instance()->SetNumericProperty("tcmalloc.heap_limit_mb", old_limit));
#endif

TestHugeThreadCache();
Expand Down

0 comments on commit a015377

Please sign in to comment.