Class MemoryTrackingContext

java.lang.Object
io.trino.memory.context.MemoryTrackingContext

@ThreadSafe public final class MemoryTrackingContext extends Object
This class is used to track memory usage at all levels (operator, driver, pipeline, etc.).

At every level we have three aggregate and three local memory contexts. The local memory contexts track the allocations in the current level while the aggregate memory contexts aggregate the memory allocated by the leaf levels and the current level.

The reason we have local memory contexts at every level is that not all the allocations are done by the leaf levels (e.g., at the pipeline level exchange clients can do system allocations directly, see the ExchangeOperator, another example is the buffers doing system allocations at the task context level, etc.).

As another example, at the pipeline level there will be system allocations initiated by the operator context and there will be system allocations initiated by the exchange clients (local allocations). All these system allocations will be visible in the systemAggregateMemoryContext.

To perform local allocations clients should use localUserMemoryContext() and get a reference to the local memory contexts. Clients can also use updateUserMemory()/tryReserveUserMemory() to allocate memory (non-local allocations), which will be reflected to all ancestors of this context in the hierarchy.

  • Constructor Details

  • Method Details

    • close

      public void close()
    • localUserMemoryContext

      public LocalMemoryContext localUserMemoryContext()
    • localRevocableMemoryContext

      public LocalMemoryContext localRevocableMemoryContext()
    • newUserMemoryContext

      public LocalMemoryContext newUserMemoryContext(String allocationTag)
    • aggregateUserMemoryContext

      public AggregatedMemoryContext aggregateUserMemoryContext()
    • aggregateRevocableMemoryContext

      public AggregatedMemoryContext aggregateRevocableMemoryContext()
    • newAggregateUserMemoryContext

      public AggregatedMemoryContext newAggregateUserMemoryContext()
    • newAggregateRevocableMemoryContext

      public AggregatedMemoryContext newAggregateRevocableMemoryContext()
    • getUserMemory

      public long getUserMemory()
    • getRevocableMemory

      public long getRevocableMemory()
    • newMemoryTrackingContext

      public MemoryTrackingContext newMemoryTrackingContext()
    • initializeLocalMemoryContexts

      public void initializeLocalMemoryContexts(String allocationTag)
      This method has to be called to initialize the local memory contexts. Otherwise, calls to methods localUserMemoryContext(), etc. will fail.
    • toString

      public String toString()
      Overrides:
      toString in class Object