vralloc

package
v2.6.11 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator[T comparable] interface {
	// Allocate allocates the resource, returns true if the resource is allocated. If allocation failed, returns the short resource.
	// The short resource is a positive value, e.g., if there is additional 8 bytes in disk needed, returns (0, 0, 8).
	// Allocate on identical id is not allowed, in which case it returns (false, nil). Use #Reallocate instead.
	Allocate(id T, r *Resource) (allocated bool, short *Resource)
	// Reallocate re-allocates the resource on given id with delta resource. Delta can be negative, in which case the resource is released.
	// If delta is negative and the allocated resource is less than the delta, returns (false, nil).
	Reallocate(id T, delta *Resource) (allocated bool, short *Resource)
	// Release releases the resource
	Release(id T) *Resource
	// Used returns the used resource
	Used() Resource
	// Wait waits for new release. Releases could be initiated by #Release or #Reallocate.
	Wait()
	// Inspect returns the allocated resources
	Inspect() map[T]*Resource
	// contains filtered or unexported methods
}

type FixedSizeAllocator

type FixedSizeAllocator[T comparable] struct {
	// contains filtered or unexported fields
}

func NewFixedSizeAllocator

func NewFixedSizeAllocator[T comparable](limit *Resource) *FixedSizeAllocator[T]

func (*FixedSizeAllocator[T]) Allocate

func (a *FixedSizeAllocator[T]) Allocate(id T, r *Resource) (allocated bool, short *Resource)

func (*FixedSizeAllocator[T]) Inspect

func (a *FixedSizeAllocator[T]) Inspect() map[T]*Resource

func (*FixedSizeAllocator[T]) Reallocate

func (a *FixedSizeAllocator[T]) Reallocate(id T, delta *Resource) (allocated bool, short *Resource)

func (*FixedSizeAllocator[T]) Release

func (a *FixedSizeAllocator[T]) Release(id T) *Resource

func (*FixedSizeAllocator[T]) Used

func (a *FixedSizeAllocator[T]) Used() Resource

func (*FixedSizeAllocator[T]) Wait

func (a *FixedSizeAllocator[T]) Wait()

type GroupedAllocator

type GroupedAllocator struct {
	SharedAllocator
	// contains filtered or unexported fields
}

GroupedAllocator is a shared allocator that can be grouped with other shared allocators. The sum of used resources of all children should not exceed the limit.

func (*GroupedAllocator) Allocate

func (ga *GroupedAllocator) Allocate(id string, r *Resource) (allocated bool, short *Resource)

Allocate allocates the resource, returns true if the resource is allocated. If allocation failed, returns the short resource. The short resource is a positive value, e.g., if there is additional 8 bytes in disk needed, returns (0, 0, 8). Allocate on identical id is not allowed, in which case it returns (false, nil). Use #Reallocate instead.

func (*GroupedAllocator) GetAllocator

func (ga *GroupedAllocator) GetAllocator(name string) Allocator[string]

func (*GroupedAllocator) Reallocate

func (ga *GroupedAllocator) Reallocate(id string, delta *Resource) (allocated bool, short *Resource)

func (*GroupedAllocator) Release

func (ga *GroupedAllocator) Release(id string) *Resource

Release releases the resource

type GroupedAllocatorBuilder

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

func NewGroupedAllocatorBuilder

func NewGroupedAllocatorBuilder(name string, limit *Resource) *GroupedAllocatorBuilder

func (*GroupedAllocatorBuilder) AddChild

func (*GroupedAllocatorBuilder) AddChildGroup

func (*GroupedAllocatorBuilder) Build

type PhysicalAwareFixedSizeAllocator

type PhysicalAwareFixedSizeAllocator[T comparable] struct {
	FixedSizeAllocator[T]
	// contains filtered or unexported fields
}

PhysicalAwareFixedSizeAllocator allocates resources with additional consideration of physical resource usage. Note: wait on PhysicalAwareFixedSizeAllocator may only be notified if there is virtual resource released.

func NewPhysicalAwareFixedSizeAllocator

func NewPhysicalAwareFixedSizeAllocator[T comparable](limit *Resource, hwMemoryLimit, hwDiskLimit int64, dir string) *PhysicalAwareFixedSizeAllocator[T]

func (*PhysicalAwareFixedSizeAllocator[T]) Allocate

func (a *PhysicalAwareFixedSizeAllocator[T]) Allocate(id T, r *Resource) (allocated bool, short *Resource)

func (*PhysicalAwareFixedSizeAllocator[T]) Reallocate

func (a *PhysicalAwareFixedSizeAllocator[T]) Reallocate(id T, delta *Resource) (allocated bool, short *Resource)

type Resource

type Resource struct {
	Memory int64 // Memory occupation in bytes
	CPU    int64 // CPU in cycles per second
	Disk   int64 // Disk occpuation in bytes
}

func (*Resource) Add

func (r *Resource) Add(r2 *Resource) *Resource

Add adds r2 to r

func (*Resource) Diff

func (r *Resource) Diff(r2 *Resource) *Resource

func (Resource) Le

func (r Resource) Le(limit *Resource) bool

Le tests if the resource is less than or equal to the limit

func (*Resource) Sub

func (r *Resource) Sub(r2 *Resource) *Resource

Sub subtracts r2 from r

type SharedAllocator

type SharedAllocator struct {
	Allocator[string]
	// contains filtered or unexported fields
}

func (*SharedAllocator) Allocate

func (sa *SharedAllocator) Allocate(id string, r *Resource) (allocated bool, short *Resource)

Allocate allocates the resource, returns true if the resource is allocated. If allocation failed, returns the short resource. The short resource is a positive value, e.g., if there is additional 8 bytes in disk needed, returns (0, 0, 8).

func (*SharedAllocator) Reallocate

func (sa *SharedAllocator) Reallocate(id string, delta *Resource) (allocated bool, short *Resource)

Reallocate re-allocates the resource on given id with delta resource. Delta can be negative, in which case the resource is released. If delta is negative and the allocated resource is less than the delta, returns (false, nil).

func (*SharedAllocator) Release

func (sa *SharedAllocator) Release(id string) *Resource

Release releases the resource

Jump to

Keyboard shortcuts

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