malloc

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MB = 1 << 20
	GB = 1 << 30
)

Variables

This section is empty.

Functions

func NewFixedSizeMmapAllocator added in v1.2.1

func NewFixedSizeMmapAllocator(
	size uint64,
) (ret *fixedSizeMmapAllocator)

func NewFixedSizeSyncPoolAllocator added in v1.2.1

func NewFixedSizeSyncPoolAllocator(size uint64) (ret *fixedSizeSyncPoolAllocator)

func SetDefaultConfig added in v1.2.1

func SetDefaultConfig(delta Config)

func WriteProfileData added in v1.2.4

func WriteProfileData(w io.Writer) error

Types

type AllocateInfo added in v1.2.1

type AllocateInfo struct {
	Deallocator Deallocator
	Size        uint64
}

type Allocator added in v1.2.1

type Allocator interface {
	Allocate(size uint64, hint Hints) ([]byte, Deallocator, error)
}

func GetDefault added in v1.2.1

func GetDefault(defaultConfig *Config) Allocator

type AtomicInteger added in v1.2.1

type AtomicInteger[T any] interface {
	Add(T) T
	Load() T
}

type CAllocator added in v1.2.1

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

func NewCAllocator added in v1.2.1

func NewCAllocator() *CAllocator

func (*CAllocator) Allocate added in v1.2.1

func (c *CAllocator) Allocate(size uint64, hints Hints) ([]byte, Deallocator, error)

type CheckedAllocator added in v1.2.1

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

func NewCheckedAllocator added in v1.2.1

func NewCheckedAllocator(
	upstream Allocator,
) *CheckedAllocator

func (*CheckedAllocator) Allocate added in v1.2.1

func (c *CheckedAllocator) Allocate(size uint64, hints Hints) ([]byte, Deallocator, error)

type Class added in v1.2.1

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

type ClassAllocator added in v1.2.1

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

func NewClassAllocator added in v1.2.1

func NewClassAllocator[T FixedSizeAllocator](
	newAllocator func(size uint64) T,
) *ClassAllocator[T]

func (*ClassAllocator[T]) Allocate added in v1.2.1

func (c *ClassAllocator[T]) Allocate(size uint64, hints Hints) ([]byte, Deallocator, error)

type ClosureDeallocator added in v1.2.3

type ClosureDeallocator[T any, P interface {
	*T
	TraitHolder
}] struct {
	// contains filtered or unexported fields
}

func (*ClosureDeallocator[T, P]) As added in v1.2.3

func (a *ClosureDeallocator[T, P]) As(target Trait) bool

func (*ClosureDeallocator[T, P]) Deallocate added in v1.2.3

func (a *ClosureDeallocator[T, P]) Deallocate(hints Hints)

func (*ClosureDeallocator[T, P]) SetArgument added in v1.2.3

func (a *ClosureDeallocator[T, P]) SetArgument(arg T)

type ClosureDeallocatorPool added in v1.2.3

type ClosureDeallocatorPool[T any, P interface {
	*T
	TraitHolder
}] struct {
	// contains filtered or unexported fields
}

func NewClosureDeallocatorPool added in v1.2.3

func NewClosureDeallocatorPool[T any, P interface {
	*T
	TraitHolder
}](
	deallocateFunc func(Hints, *T),
) *ClosureDeallocatorPool[T, P]

func (*ClosureDeallocatorPool[T, P]) Get added in v1.2.3

func (c *ClosureDeallocatorPool[T, P]) Get(args T) Deallocator

func (*ClosureDeallocatorPool[T, P]) Get2 added in v1.2.3

func (c *ClosureDeallocatorPool[T, P]) Get2(fn func(*T) T) Deallocator

type Config added in v1.2.1

type Config struct {

	// Allocator controls which allocator to use
	Allocator *string `toml:"allocator"`

	// CheckFraction controls the fraction of checked deallocations
	// On average, 1 / fraction of deallocations will be checked for double free or missing free
	CheckFraction *uint32 `toml:"check-fraction"`

	// FullStackFraction controls the fraction of full stack collecting in profile sampling
	// On average, 1 / fraction of allocations will be sampled with full stack information
	FullStackFraction *uint32 `toml:"full-stack-fraction"`

	// EnableMetrics indicates whether to expose metrics to prometheus
	EnableMetrics *bool `toml:"enable-metrics"`
}

type CounterInteger added in v1.2.1

type CounterInteger interface {
	int32 | int64 | uint32 | uint64
}

type Deallocator added in v1.2.1

type Deallocator interface {
	TraitHolder
	Deallocate(hint Hints)
}

func ChainDeallocator added in v1.2.1

func ChainDeallocator(dec1 Deallocator, dec2 Deallocator) Deallocator

type FixedSizeAllocator added in v1.2.1

type FixedSizeAllocator interface {
	Allocate(hint Hints) ([]byte, Deallocator, error)
}

type Freezer added in v1.2.3

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

func (*Freezer) IsTrait added in v1.2.3

func (*Freezer) IsTrait()

type FuncDeallocator added in v1.2.1

type FuncDeallocator func(hints Hints)

func (FuncDeallocator) As added in v1.2.3

func (FuncDeallocator) As(target Trait) bool

func (FuncDeallocator) Deallocate added in v1.2.1

func (f FuncDeallocator) Deallocate(hints Hints)

type FunctionKey added in v1.2.1

type FunctionKey struct {
	Name string
}

type HeapSampleValues added in v1.2.1

type HeapSampleValues struct {
	AllocatedObjects ShardedCounter[int64, atomic.Int64, *atomic.Int64]
	AllocatedBytes   ShardedCounter[int64, atomic.Int64, *atomic.Int64]
	InuseObjects     ShardedCounter[int64, atomic.Int64, *atomic.Int64]
	InuseBytes       ShardedCounter[int64, atomic.Int64, *atomic.Int64]
}

func (*HeapSampleValues) DefaultSampleType added in v1.2.1

func (h *HeapSampleValues) DefaultSampleType() string

func (*HeapSampleValues) Init added in v1.2.1

func (h *HeapSampleValues) Init()

func (*HeapSampleValues) SampleTypes added in v1.2.1

func (h *HeapSampleValues) SampleTypes() []*profile.ValueType

func (*HeapSampleValues) Values added in v1.2.1

func (h *HeapSampleValues) Values() []int64

type Hints added in v1.2.1

type Hints uint64
const (
	NoHints    Hints = 0
	DoNotReuse Hints = 1 << iota
	NoClear
)

type LeaksTracker added in v1.2.3

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

func (*LeaksTracker) ReportLeaks added in v1.2.3

func (t *LeaksTracker) ReportLeaks(w io.Writer) (leaks bool)

type LeaksTrackingAllocator added in v1.2.3

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

func NewLeaksTrackingAllocator added in v1.2.3

func NewLeaksTrackingAllocator(
	upstream Allocator,
	tracker *LeaksTracker,
) (ret *LeaksTrackingAllocator)

func (*LeaksTrackingAllocator) Allocate added in v1.2.3

func (t *LeaksTrackingAllocator) Allocate(size uint64, hints Hints) ([]byte, Deallocator, error)

type LocationKey added in v1.2.1

type LocationKey struct {
	PC       uintptr
	Function string
}

type ManagedAllocator added in v1.2.3

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

func NewManagedAllocator added in v1.2.3

func NewManagedAllocator(
	upstream Allocator,
) *ManagedAllocator

func (*ManagedAllocator) Allocate added in v1.2.3

func (m *ManagedAllocator) Allocate(size uint64, hints Hints) ([]byte, error)

func (*ManagedAllocator) Deallocate added in v1.2.3

func (m *ManagedAllocator) Deallocate(slice []byte, hints Hints)

type MetricsAllocator added in v1.2.1

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

func NewMetricsAllocator added in v1.2.1

func NewMetricsAllocator(
	upstream Allocator,
	allocateBytesCounter prometheus.Counter,
	inuseBytesGauge prometheus.Gauge,
	allocateObjectsCounter prometheus.Counter,
	inuseObjectsGauge prometheus.Gauge,
) *MetricsAllocator

func (*MetricsAllocator) Allocate added in v1.2.1

func (m *MetricsAllocator) Allocate(size uint64, hints Hints) ([]byte, Deallocator, error)

type MmapInfo added in v1.2.3

type MmapInfo struct {
	Addr   unsafe.Pointer
	Length uint64
}

func (*MmapInfo) IsTrait added in v1.2.3

func (*MmapInfo) IsTrait()

type ProfileAllocator added in v1.2.1

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

func NewProfileAllocator added in v1.2.1

func NewProfileAllocator(
	upstream Allocator,
	profiler *Profiler[HeapSampleValues, *HeapSampleValues],
	fraction uint32,
) *ProfileAllocator

func (*ProfileAllocator) Allocate added in v1.2.1

func (p *ProfileAllocator) Allocate(size uint64, hints Hints) ([]byte, Deallocator, error)

type Profiler added in v1.2.1

type Profiler[T any, P interface {
	*T
	SampleValues
}] struct {
	// contains filtered or unexported fields
}

func NewProfiler added in v1.2.1

func NewProfiler[T any, P interface {
	*T
	SampleValues
}]() *Profiler[T, P]

func (*Profiler[T, P]) Sample added in v1.2.1

func (p *Profiler[T, P]) Sample(
	skip int,
	fullStackFraction uint32,
) P

func (*Profiler[T, P]) Write added in v1.2.1

func (p *Profiler[T, P]) Write(w io.Writer) error

type RandomAllocator added in v1.2.3

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

RandomAllocator calls upstream1 or upstream2 in certain probability

func NewRandomAllocator added in v1.2.3

func NewRandomAllocator(
	upstream1 Allocator,
	upstream2 Allocator,
	upstream2Fraction uint32,
) *RandomAllocator

func (*RandomAllocator) Allocate added in v1.2.3

func (r *RandomAllocator) Allocate(size uint64, hint Hints) ([]byte, Deallocator, error)

type ReadOnlyAllocator added in v1.2.3

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

func NewReadOnlyAllocator added in v1.2.3

func NewReadOnlyAllocator(
	upstream Allocator,
) *ReadOnlyAllocator

func (*ReadOnlyAllocator) Allocate added in v1.2.3

func (r *ReadOnlyAllocator) Allocate(size uint64, hint Hints) ([]byte, Deallocator, error)

type SampleInfo added in v1.2.1

type SampleInfo[T any] struct {
	Values    T
	Locations []*profile.Location
}

type SampleKey added in v1.2.1

type SampleKey struct {
	Hash uint64
}

type SampleValues added in v1.2.1

type SampleValues interface {
	Init()
	SampleTypes() []*profile.ValueType
	DefaultSampleType() string
	Values() []int64
}

type ShardedAllocator added in v1.2.1

type ShardedAllocator []Allocator

func NewShardedAllocator added in v1.2.1

func NewShardedAllocator(numShards int, newShard func() Allocator) ShardedAllocator

func (ShardedAllocator) Allocate added in v1.2.1

func (s ShardedAllocator) Allocate(size uint64, hints Hints) ([]byte, Deallocator, error)

type ShardedCounter added in v1.2.1

type ShardedCounter[T CounterInteger, A any, P interface {
	*A
	AtomicInteger[T]
}] struct {
	// contains filtered or unexported fields
}

func NewShardedCounter added in v1.2.1

func NewShardedCounter[T CounterInteger, A any, P interface {
	*A
	AtomicInteger[T]
}](shards int) *ShardedCounter[T, A, P]

func (*ShardedCounter[T, A, P]) Add added in v1.2.1

func (s *ShardedCounter[T, A, P]) Add(v T)

func (*ShardedCounter[T, A, P]) Load added in v1.2.1

func (s *ShardedCounter[T, A, P]) Load() (ret T)

type SizeBoundedAllocator added in v1.2.1

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

func NewSizeBoundedAllocator added in v1.2.1

func NewSizeBoundedAllocator(upstream Allocator, maxSize uint64, counter *atomic.Uint64) (ret *SizeBoundedAllocator)

func (*SizeBoundedAllocator) Allocate added in v1.2.1

func (s *SizeBoundedAllocator) Allocate(size uint64, hints Hints) ([]byte, Deallocator, error)

type StacktraceID added in v1.2.3

type StacktraceID uint64

func GetStacktraceID added in v1.2.3

func GetStacktraceID(skip int) StacktraceID

func (StacktraceID) String added in v1.2.3

func (s StacktraceID) String() string

type Trait added in v1.2.3

type Trait interface {
	IsTrait()
}

type TraitHolder added in v1.2.3

type TraitHolder interface {
	As(trait Trait) bool
}

Jump to

Keyboard shortcuts

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