mirror of
https://github.com/gperftools/gperftools
synced 2025-02-19 21:56:49 +00:00
issue-489: added unit test for chromium-style decommitting
This commit is contained in:
parent
eb2d69014c
commit
6a000d6dd5
@ -869,17 +869,17 @@ static size_t GetUnmappedBytes() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class AggressiveDecommitDisabler {
|
class AggressiveDecommitChanger {
|
||||||
size_t old_value_;
|
size_t old_value_;
|
||||||
public:
|
public:
|
||||||
AggressiveDecommitDisabler() {
|
AggressiveDecommitChanger(size_t new_value) {
|
||||||
MallocExtension *inst = MallocExtension::instance();
|
MallocExtension *inst = MallocExtension::instance();
|
||||||
bool rv = inst->GetNumericProperty("tcmalloc.aggressive_memory_decommit", &old_value_);
|
bool rv = inst->GetNumericProperty("tcmalloc.aggressive_memory_decommit", &old_value_);
|
||||||
CHECK_CONDITION(rv);
|
CHECK_CONDITION(rv);
|
||||||
rv = inst->SetNumericProperty("tcmalloc.aggressive_memory_decommit", 0);
|
rv = inst->SetNumericProperty("tcmalloc.aggressive_memory_decommit", new_value);
|
||||||
CHECK_CONDITION(rv);
|
CHECK_CONDITION(rv);
|
||||||
}
|
}
|
||||||
~AggressiveDecommitDisabler() {
|
~AggressiveDecommitChanger() {
|
||||||
MallocExtension *inst = MallocExtension::instance();
|
MallocExtension *inst = MallocExtension::instance();
|
||||||
bool rv = inst->SetNumericProperty("tcmalloc.aggressive_memory_decommit", old_value_);
|
bool rv = inst->SetNumericProperty("tcmalloc.aggressive_memory_decommit", old_value_);
|
||||||
CHECK_CONDITION(rv);
|
CHECK_CONDITION(rv);
|
||||||
@ -897,7 +897,7 @@ static void TestReleaseToSystem() {
|
|||||||
const double old_tcmalloc_release_rate = FLAGS_tcmalloc_release_rate;
|
const double old_tcmalloc_release_rate = FLAGS_tcmalloc_release_rate;
|
||||||
FLAGS_tcmalloc_release_rate = 0;
|
FLAGS_tcmalloc_release_rate = 0;
|
||||||
|
|
||||||
AggressiveDecommitDisabler disabler;
|
AggressiveDecommitChanger disabler(0);
|
||||||
|
|
||||||
static const int MB = 1048576;
|
static const int MB = 1048576;
|
||||||
void* a = malloc(MB);
|
void* a = malloc(MB);
|
||||||
@ -949,6 +949,51 @@ static void TestReleaseToSystem() {
|
|||||||
#endif // #ifndef DEBUGALLOCATION
|
#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
|
// On MSVC10, in release mode, the optimizer convinces itself
|
||||||
// g_no_memory is never changed (I guess it doesn't realize OnNoMemory
|
// g_no_memory is never changed (I guess it doesn't realize OnNoMemory
|
||||||
// might be called). Work around this by setting the var volatile.
|
// might be called). Work around this by setting the var volatile.
|
||||||
@ -1327,6 +1372,7 @@ static int RunAllTests(int argc, char** argv) {
|
|||||||
TestHugeThreadCache();
|
TestHugeThreadCache();
|
||||||
TestRanges();
|
TestRanges();
|
||||||
TestReleaseToSystem();
|
TestReleaseToSystem();
|
||||||
|
TestAggressiveDecommit();
|
||||||
TestSetNewMode();
|
TestSetNewMode();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user