summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alk@tut.by>2014-02-22 13:46:11 -0800
committerAliaksey Kandratsenka <alk@tut.by>2014-02-22 13:46:11 -0800
commit6a000d6dd5968ac29f8fc43f7dfc736338e11781 (patch)
treea7b7940030bd67a9120149ac600f1a98657520c1
parenteb2d69014cb3e163f2ab3ed676fbedf5c3a97caa (diff)
downloadgperftools-6a000d6dd5968ac29f8fc43f7dfc736338e11781.tar.gz
issue-489: added unit test for chromium-style decommitting
-rw-r--r--src/tests/tcmalloc_unittest.cc56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/tests/tcmalloc_unittest.cc b/src/tests/tcmalloc_unittest.cc
index 6a90e3b..236bab6 100644
--- a/src/tests/tcmalloc_unittest.cc
+++ b/src/tests/tcmalloc_unittest.cc
@@ -869,17 +869,17 @@ static size_t GetUnmappedBytes() {
}
#endif
-class AggressiveDecommitDisabler {
+class AggressiveDecommitChanger {
size_t old_value_;
public:
- AggressiveDecommitDisabler() {
+ AggressiveDecommitChanger(size_t new_value) {
MallocExtension *inst = MallocExtension::instance();
bool rv = inst->GetNumericProperty("tcmalloc.aggressive_memory_decommit", &old_value_);
CHECK_CONDITION(rv);
- rv = inst->SetNumericProperty("tcmalloc.aggressive_memory_decommit", 0);
+ rv = inst->SetNumericProperty("tcmalloc.aggressive_memory_decommit", new_value);
CHECK_CONDITION(rv);
}
- ~AggressiveDecommitDisabler() {
+ ~AggressiveDecommitChanger() {
MallocExtension *inst = MallocExtension::instance();
bool rv = inst->SetNumericProperty("tcmalloc.aggressive_memory_decommit", old_value_);
CHECK_CONDITION(rv);
@@ -897,7 +897,7 @@ static void TestReleaseToSystem() {
const double old_tcmalloc_release_rate = FLAGS_tcmalloc_release_rate;
FLAGS_tcmalloc_release_rate = 0;
- AggressiveDecommitDisabler disabler;
+ AggressiveDecommitChanger disabler(0);
static const int MB = 1048576;
void* a = malloc(MB);
@@ -949,6 +949,51 @@ static void TestReleaseToSystem() {
#endif // #ifndef DEBUGALLOCATION
}
+static void TestAggressiveDecommit() {
+ // Debug allocation mode adds overhead to each allocation which
+ // messes up all the equality tests here. I just disable the
+ // teset in this mode.
+#ifndef DEBUGALLOCATION
+
+ if(!HaveSystemRelease) return;
+
+ fprintf(LOGSTREAM, "Testing aggressive de-commit\n");
+
+ AggressiveDecommitChanger enabler(1);
+
+ static const int MB = 1048576;
+ void* a = malloc(MB);
+ void* b = malloc(MB);
+
+ size_t starting_bytes = GetUnmappedBytes();
+
+ // ReleaseToSystem shouldn't do anything either.
+ MallocExtension::instance()->ReleaseToSystem(MB);
+ EXPECT_EQ(starting_bytes, GetUnmappedBytes());
+
+ free(a);
+
+ // The span to release should be 1MB.
+ EXPECT_EQ(starting_bytes + MB, GetUnmappedBytes());
+
+ free(b);
+
+ EXPECT_EQ(starting_bytes + 2*MB, GetUnmappedBytes());
+
+ // Nothing else to release.
+ MallocExtension::instance()->ReleaseFreeMemory();
+ EXPECT_EQ(starting_bytes + 2*MB, GetUnmappedBytes());
+
+ a = malloc(MB);
+ free(a);
+
+ EXPECT_EQ(starting_bytes + 2*MB, GetUnmappedBytes());
+
+ fprintf(LOGSTREAM, "Done testing aggressive de-commit\n");
+
+#endif // #ifndef DEBUGALLOCATION
+}
+
// On MSVC10, in release mode, the optimizer convinces itself
// g_no_memory is never changed (I guess it doesn't realize OnNoMemory
// might be called). Work around this by setting the var volatile.
@@ -1327,6 +1372,7 @@ static int RunAllTests(int argc, char** argv) {
TestHugeThreadCache();
TestRanges();
TestReleaseToSystem();
+ TestAggressiveDecommit();
TestSetNewMode();
return 0;