| 636 | } |
| 637 | |
| 638 | void ExecEnv::InitMemTracker(int64_t bytes_limit) { |
| 639 | DCHECK(AggregateMemoryMetrics::TOTAL_USED != nullptr) << "Memory metrics not reg'd"; |
| 640 | mem_tracker_.reset( |
| 641 | new MemTracker(AggregateMemoryMetrics::TOTAL_USED, bytes_limit, "Process")); |
| 642 | if (FLAGS_mem_limit_includes_jvm) { |
| 643 | // Add JVM metrics that should count against the process memory limit. |
| 644 | obj_pool_->Add(new MemTracker( |
| 645 | JvmMemoryMetric::HEAP_MAX_USAGE, -1, "JVM: max heap size", mem_tracker_.get())); |
| 646 | obj_pool_->Add(new MemTracker(JvmMemoryMetric::NON_HEAP_COMMITTED, -1, |
| 647 | "JVM: non-heap committed", mem_tracker_.get())); |
| 648 | } |
| 649 | if (buffer_pool_ != nullptr) { |
| 650 | // Tests can create multiple buffer pools, meaning that the metrics are not usable. |
| 651 | if (!TestInfo::is_test()) { |
| 652 | // Add BufferPool MemTrackers for cached memory that is not tracked against queries |
| 653 | // but is included in process memory consumption. |
| 654 | obj_pool_->Add(new MemTracker(BufferPoolMetric::FREE_BUFFER_BYTES, -1, |
| 655 | "Buffer Pool: Free Buffers", mem_tracker_.get())); |
| 656 | obj_pool_->Add(new MemTracker(BufferPoolMetric::CLEAN_PAGE_BYTES, -1, |
| 657 | "Buffer Pool: Clean Pages", mem_tracker_.get())); |
| 658 | // Also need a MemTracker for unused reservations as a negative value. Unused |
| 659 | // reservations are counted against queries but not against the process memory |
| 660 | // consumption. This accounts for that difference. |
| 661 | IntGauge* negated_unused_reservation = obj_pool_->Add(new NegatedGauge( |
| 662 | MakeTMetricDef("negated_unused_reservation", TMetricKind::GAUGE, TUnit::BYTES), |
| 663 | BufferPoolMetric::UNUSED_RESERVATION_BYTES)); |
| 664 | obj_pool_->Add(new MemTracker(negated_unused_reservation, -1, |
| 665 | "Buffer Pool: Unused Reservation", mem_tracker_.get())); |
| 666 | } |
| 667 | mem_tracker_->AddGcFunction([buffer_pool=buffer_pool_.get()] (int64_t bytes_to_free) |
| 668 | { |
| 669 | // Only free memory in excess of the current reservation - the buffer pool |
| 670 | // does not need to give up cached memory that is offset by an unused reservation. |
| 671 | int64_t reserved = BufferPoolMetric::RESERVED->GetValue(); |
| 672 | int64_t allocated_from_sys = BufferPoolMetric::SYSTEM_ALLOCATED->GetValue(); |
| 673 | if (reserved >= allocated_from_sys) return; |
| 674 | buffer_pool->ReleaseMemory(min(bytes_to_free, allocated_from_sys - reserved)); |
| 675 | }); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | void ExecEnv::InitSystemStateInfo() { |
| 680 | system_state_info_.reset(new SystemStateInfo()); |