| 352 | } |
| 353 | |
| 354 | bool BoltMemoryManager::tryDestructSafe() { |
| 355 | // Bolt memory pools considered safe to destruct when no alive allocations. |
| 356 | for (const auto& pool : heldBoltPools_) { |
| 357 | if (pool && pool->currentBytes() != 0) { |
| 358 | LOG(INFO) << pool->name() << " still hold " << pool->currentBytes() |
| 359 | << " bytes, can't be freed immediately.\n" |
| 360 | << pool->treeMemoryUsage(); |
| 361 | return false; |
| 362 | } |
| 363 | } |
| 364 | if (boltLeafPool_ && boltLeafPool_->currentBytes() != 0) { |
| 365 | LOG(INFO) << boltLeafPool_->name() << " still hold " |
| 366 | << boltLeafPool_->currentBytes() |
| 367 | << " bytes, can't be freed immediately.\n" |
| 368 | << boltLeafPool_->treeMemoryUsage(); |
| 369 | return false; |
| 370 | } |
| 371 | if (boltAggregatePool_ && boltAggregatePool_->currentBytes() != 0) { |
| 372 | LOG(INFO) << boltAggregatePool_->name() << " still hold " |
| 373 | << boltAggregatePool_->currentBytes() |
| 374 | << " bytes, can't be freed immediately.\n" |
| 375 | << boltAggregatePool_->treeMemoryUsage(); |
| 376 | return false; |
| 377 | } |
| 378 | heldBoltPools_.clear(); |
| 379 | boltLeafPool_.reset(); |
| 380 | boltAggregatePool_.reset(); |
| 381 | |
| 382 | // Bolt memory manager considered safe to destruct when no alive pools. |
| 383 | if (boltMemoryManager_) { |
| 384 | if (boltMemoryManager_->numPools() > 3) { |
| 385 | LOG(INFO) << "memory::MemoryManager still hold " |
| 386 | << boltMemoryManager_->numPools() << " pools, expect 2.\n" |
| 387 | << boltMemoryManager_->toString(true); |
| 388 | return false; |
| 389 | } |
| 390 | if (boltMemoryManager_->numPools() == 3) { |
| 391 | // Assert the pool is spill pool |
| 392 | // See |
| 393 | // https://github.com/facebookincubator/velox/commit/e6f84e8ac9ef6721f527a2d552a13f7e79bdf72e |
| 394 | int32_t spillPoolCount = 0; |
| 395 | int32_t cachePoolCount = 0; |
| 396 | int32_t tracePoolCount = 0; |
| 397 | boltMemoryManager_->visitSystemRootChildren( |
| 398 | [&](bolt::memory::MemoryPool* child) -> bool { |
| 399 | if (child == boltMemoryManager_->spillPool()) { |
| 400 | spillPoolCount++; |
| 401 | } |
| 402 | if (child == boltMemoryManager_->cachePool()) { |
| 403 | cachePoolCount++; |
| 404 | } |
| 405 | if (child == boltMemoryManager_->tracePool()) { |
| 406 | tracePoolCount++; |
| 407 | } |
| 408 | return true; |
| 409 | }); |
| 410 | BOLT_CHECK( |
| 411 | spillPoolCount == 1, |
nothing calls this directly
no test coverage detected