mon

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPoolAllocationSize = envutil.EnvOrDefaultInt64("COCKROACH_MEMORY_ALLOCATION_CHUNK_SIZE", 10*1024)

DefaultPoolAllocationSize specifies the unit of allocation used by a monitor to reserve and release memory to a pool.

Functions

This section is empty.

Types

type BoundAccount

type BoundAccount struct {
	MemoryAccount
	// contains filtered or unexported fields
}

BoundAccount implements a MemoryAccount attached to a specific monitor.

func MakeStandaloneBudget

func MakeStandaloneBudget(capacity int64) BoundAccount

MakeStandaloneBudget creates a BoundAccount suitable for root monitors.

func (*BoundAccount) Clear

func (b *BoundAccount) Clear(ctx context.Context)

Clear is an accessor for b.mon.ClearAccount.

func (*BoundAccount) Close

func (b *BoundAccount) Close(ctx context.Context)

Close is an accessor for b.mon.CloseAccount.

func (*BoundAccount) Grow

func (b *BoundAccount) Grow(ctx context.Context, x int64) error

Grow is an accessor for b.mon.Grow.

func (*BoundAccount) ResizeItem

func (b *BoundAccount) ResizeItem(ctx context.Context, oldSz, newSz int64) error

ResizeItem is an accessor for b.mon.ResizeItem.

type MemoryAccount

type MemoryAccount struct {
	// contains filtered or unexported fields
}

MemoryAccount tracks the cumulated allocations for one client of MemoryPool or MemoryMonitor. MemoryMonitor has an account to its pool; MemoryMonitor clients have an account to the monitor. This allows each client to release all the memory at once when it completes its work.

See the comments in mem_usage.go for a fuller picture of how these accounts are used in CockroachDB.

type MemoryMonitor

type MemoryMonitor struct {
	// contains filtered or unexported fields
}

MemoryMonitor defines an object that can track and limit memory usage by other CockroachDB components. The monitor must be set up via Start/Stop before and after use. The various counters express sizes in bytes.

func MakeMonitor

func MakeMonitor(
	name string,
	curCount *metric.Counter,
	maxHist *metric.Histogram,
	increment int64,
	noteworthy int64,
) MemoryMonitor

MakeMonitor creates a new monitor. Arguments:

  • name is used to annotate log messages, can be used to distinguish monitors.
  • curCount and maxHist are the metric objects to update with usage statistics.
  • increment is the block size used for upstream allocations from the pool. Note: if set to 0 or lower, the default pool allocation size is used.
  • noteworthy determines the minimum total allocated size beyond which the monitor starts to log increases. Use 0 to always log or math.MaxInt64 to never log.

func MakeUnlimitedMonitor

func MakeUnlimitedMonitor(
	ctx context.Context,
	name string,
	curCount *metric.Counter,
	maxHist *metric.Histogram,
	noteworthy int64,
) MemoryMonitor

MakeUnlimitedMonitor creates a new monitor and starts the monitor in "detached" mode without a pool and without a maximum budget.

func (*MemoryMonitor) ClearAccount

func (mm *MemoryMonitor) ClearAccount(ctx context.Context, acc *MemoryAccount)

ClearAccount releases all the cumulated allocations of an account at once and primes it for reuse.

func (*MemoryMonitor) CloseAccount

func (mm *MemoryMonitor) CloseAccount(ctx context.Context, acc *MemoryAccount)

CloseAccount releases all the cumulated allocations of an account at once.

func (*MemoryMonitor) GrowAccount

func (mm *MemoryMonitor) GrowAccount(
	ctx context.Context, acc *MemoryAccount, extraSize int64,
) error

GrowAccount requests a new allocation in an account.

func (*MemoryMonitor) MakeBoundAccount

func (mm *MemoryMonitor) MakeBoundAccount() BoundAccount

MakeBoundAccount greates a BoundAccount connected to the given monitor.

func (*MemoryMonitor) OpenAccount

func (mm *MemoryMonitor) OpenAccount(_ *MemoryAccount)

OpenAccount creates a new empty account.

func (*MemoryMonitor) OpenAndInitAccount

func (mm *MemoryMonitor) OpenAndInitAccount(
	ctx context.Context, acc *MemoryAccount, initialAllocation int64,
) error

OpenAndInitAccount creates a new account and pre-allocates some initial amount of memory.

func (*MemoryMonitor) ResizeItem

func (mm *MemoryMonitor) ResizeItem(
	ctx context.Context, acc *MemoryAccount, oldSize, newSize int64,
) error

ResizeItem requests a size change for an object already registered in an account. The reservation is not modified if the new allocation is refused, so that the caller can keep using the original item without an accounting error. This is better than calling ClearAccount then GrowAccount because if the Clear succeeds and the Grow fails the original item becomes invisible from the perspective of the monitor.

func (*MemoryMonitor) ShrinkAccount

func (mm *MemoryMonitor) ShrinkAccount(ctx context.Context, acc *MemoryAccount, delta int64)

ShrinkAccount releases part of the cumulated allocations by the specified size.

func (*MemoryMonitor) Start

func (mm *MemoryMonitor) Start(ctx context.Context, pool *MemoryMonitor, reserved BoundAccount)

Start begins a monitoring region. Arguments:

  • pool is the upstream memory monitor that provision allocations exceeding the pre-reserved budget. If pool is nil, no upstream allocations are possible and the pre-reserved budget determines the entire capacity of this monitor.

- reserved is the pre-reserved budget (see above).

func (*MemoryMonitor) Stop

func (mm *MemoryMonitor) Stop(ctx context.Context)

Stop completes a monitoring region.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL