Skip to content

Commit a039e60

Browse files
committed
Merge remote-tracking branch 'couchbase/morpheus' to master
* couchbase/morpheus: MB-68823: Introduce ArenaMalloc::getCurrentClientArena() CBD-6348: [BP] Fix TestRingBufferVector template constructor CBD-6348: [BP] Update for C++20 compatibility CBD-6348: [BP] Preparing for folly upgrade to v2022.02.14.00 CBD-6348: [BP] Fix building with fmt 10.1.0 CBD-6348: [BP] Remove deprecated format_to(memory_buffer) overload Revert "MB-68823: Catch alloc/dealloc arena mismatch for NoClientIndex" MB-68823: Catch alloc/dealloc arena mismatch for NoClientIndex MB-68823: Allow to toggle ArenaMalloc debug checks dynamically Change-Id: I42e06fa071c7300aa183664012812772ca26cee7
2 parents 21ecc5b + 9d64849 commit a039e60

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/je_arena_malloc.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ namespace cb {
3636
static bool tcacheEnabled{true};
3737

3838
/// Are additional checks on arena allocations enabled?
39-
static const bool arenaDebugChecksEnabled{
40-
getenv("CB_ARENA_MALLOC_VERIFY_DEALLOC_CLIENT") != nullptr};
39+
static bool arenaDebugChecksEnabled() {
40+
#ifndef NDEBUG
41+
return getenv("CB_ARENA_MALLOC_VERIFY_DEALLOC_CLIENT") != nullptr;
42+
#else
43+
return false;
44+
#endif
45+
}
4146

4247
/**
4348
* Should Tcache be used?
@@ -57,7 +62,7 @@ static const bool arenaDebugChecksEnabled{
5762
* we can get a false error.
5863
*/
5964
static bool isTcacheEnabled(bool requested) {
60-
return tcacheEnabled && requested && !arenaDebugChecksEnabled;
65+
return tcacheEnabled && requested && !arenaDebugChecksEnabled();
6166
}
6267

6368
JEArenaMallocBase::CurrentClient::CurrentClient(uint8_t index,
@@ -275,14 +280,14 @@ ArenaMallocClient JEArenaMalloc::registerClient(bool threadCache) {
275280
auto& client = lockedClients->at(index);
276281
if (!client.used) {
277282
assignClientArenas(client.arenas,
278-
arenaDebugChecksEnabled
283+
arenaDebugChecksEnabled()
279284
? ArenaMode::OnePerDomain
280285
: ArenaMode::SingleArena);
281286
client.used = true;
282287

283288
ArenaMallocClient newClient{
284289
client.arenas, index, isTcacheEnabled(threadCache)};
285-
clientRegistered(newClient, arenaDebugChecksEnabled);
290+
clientRegistered(newClient, arenaDebugChecksEnabled());
286291
return newClient;
287292
}
288293
}
@@ -429,7 +434,7 @@ template <>
429434
void JEArenaMalloc::free(void* ptr) {
430435
if (ptr) {
431436
auto c = ThreadLocalData::get().getCurrentClient();
432-
if (arenaDebugChecksEnabled) {
437+
if (arenaDebugChecksEnabled()) {
433438
verifyMemDeallocatedByCorrectClient(c, ptr, je_sallocx(ptr, 0));
434439
}
435440
memDeallocated(c.index, c.domain, ptr);
@@ -447,7 +452,7 @@ template <>
447452
void JEArenaMalloc::sized_free(void* ptr, size_t size) {
448453
if (ptr) {
449454
auto c = ThreadLocalData::get().getCurrentClient();
450-
if (arenaDebugChecksEnabled) {
455+
if (arenaDebugChecksEnabled()) {
451456
verifyMemDeallocatedByCorrectClient(c, ptr, size);
452457
}
453458
memDeallocated(c.index, c.domain, size);

0 commit comments

Comments
 (0)