metadata

package
v0.0.0-...-b0ebb22 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SmallBufferSize        = 256
	SecondLevelIndex uint8 = 5
	MemoryClassShift       = 7
	MaxMemoryClasses       = 65 - MemoryClassShift
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllocationRequest

type AllocationRequest struct {
	// BlockAllocationHandle is a numeric handle used to identify individual allocations within the metadata
	BlockAllocationHandle BlockAllocationHandle
	// Size the total size of the allocation, maybe larger than what was originally requested
	Size int
	// Item is a Suballocation object indicating basic information about the allocation
	Item Suballocation
	// CustomData
	CustomData    uint32
	AlgorithmData uint64
	Type          AllocationRequestType
}

AllocationRequest is a type returned from BlockMetadata.CreateAllocationRequest which indicates where and how the metadata intends to allocate new memory. This allocation can be applied to the actual memory pool consuming memutils, and then committed to the metadata with BlockMetadata.Alloc

type AllocationRequestType

type AllocationRequestType uint32

AllocationRequestType is an enum that indicates the type of allocation that is being made. It is returned in AllocationRequest from CreateAllocationRequest

const (
	// AllocationRequestTLSF indicates that the allocation request was sourced from metadata.TLSFBlockMetadata
	AllocationRequestTLSF AllocationRequestType = iota
	// AllocationRequestUpperAddress indicates that the allocation request was sourced from metadata.LinearBlockMetadata
	// and that it is an allocation for the upper side of a double stack
	AllocationRequestUpperAddress
	// AllocationRequestEndOf1st indicates that the allocation request was sourced from metadata.LinearBlockMetadata
	// and that it is an allocation to be added to the end of the first memory vector
	AllocationRequestEndOf1st
	// AllocationRequestEndOf2nd indicates that the allocation request was sourced from metadata.LinearBlockMetadata
	// and that it is an allocation to be added to the end of the second memory vector
	AllocationRequestEndOf2nd
)

func (AllocationRequestType) String

func (t AllocationRequestType) String() string

type AllocationStrategy

type AllocationStrategy uint32

AllocationStrategy exposes several options for choosing the location of a new memory allocation. You can choose several and memutils will select one of them based on its own preferences. If none is chosen, a balanced strategy will be used.

const (
	// AllocationStrategyMinMemory selects the allocation strategy that chooses the smallest-possible
	// free range for the allocation to minimize memory usage and fragmentation, possibly at the expense of
	// allocation time
	AllocationStrategyMinMemory AllocationStrategy = 1 << iota
	// AllocationStrategyMinTime selects the allocation strategy that chooses the first suitable free
	// range for the allocation- not necessarily in terms of the smallest offset, but the one that is easiest
	// and fastest to find to minimize allocation time, possibly at the expense of allocation quality.
	AllocationStrategyMinTime
	// AllocationStrategyMinOffset selects the allocation strategy that chooses the lowest offset in
	// available space. This is not the most efficient strategy, but achieves highly packed data. Used internally
	// by defragmentation, not recommended in typical usage.
	AllocationStrategyMinOffset
)

type BlockAllocationHandle

type BlockAllocationHandle uint64
const (
	NoAllocation BlockAllocationHandle = math.MaxUint64
)

type BlockMetadata

type BlockMetadata interface {
	Init(size int)
	Size() int

	Validate() error
	AllocationCount() int
	FreeRegionsCount() int
	SumFreeSize() int
	GranularityHandler() GranularityCheck

	IsEmpty() bool

	VisitAllBlocks(handleBlock func(handle BlockAllocationHandle, offset int, size int, userData any, free bool) error) error
	AllocationListBegin() (BlockAllocationHandle, error)
	FindNextAllocation(allocHandle BlockAllocationHandle) (BlockAllocationHandle, error)
	FindNextFreeRegionSize(allocHandle BlockAllocationHandle) (int, error)
	AllocationOffset(allocHandle BlockAllocationHandle) (int, error)
	AllocationUserData(allocHandle BlockAllocationHandle) (any, error)
	SetAllocationUserData(allocHandle BlockAllocationHandle, userData any) error

	AddDetailedStatistics(stats *memutils.DetailedStatistics)
	AddStatistics(stats *memutils.Statistics)

	Clear()
	DebugLogAllAllocations(log *slog.Logger, logFunc func(log *slog.Logger, offset int, size int, userData any))
	PrintDetailedMapHeader(json jwriter.ObjectState)

	CheckCorruption(blockData unsafe.Pointer) (common.VkResult, error)
	CreateAllocationRequest(
		allocSize int, allocAlignment uint,
		upperAddress bool,
		allocType uint32,
		strategy AllocationStrategy,
	) (bool, AllocationRequest, error)
	Alloc(request AllocationRequest, allocType uint32, userData any) error

	Free(allocHandle BlockAllocationHandle) error
}

type BlockMetadataBase

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

func NewBlockMetadata

func NewBlockMetadata(bufferImageGranularity int, granularityHandler GranularityCheck) BlockMetadataBase

func (*BlockMetadataBase) GranularityHandler

func (m *BlockMetadataBase) GranularityHandler() GranularityCheck

func (*BlockMetadataBase) Init

func (m *BlockMetadataBase) Init(size int)

func (*BlockMetadataBase) PrintDetailedMap_Header

func (m *BlockMetadataBase) PrintDetailedMap_Header(json jwriter.ObjectState, unusedBytes, allocationCount, unusedRangeCount int)

func (*BlockMetadataBase) Size

func (m *BlockMetadataBase) Size() int

type GranularityCheck

type GranularityCheck interface {
	AllocPages(allocType uint32, offset, size int)
	FreePages(offset, size int)
	Clear()
	CheckConflictAndAlignUp(allocOffset, allocSize, blockOffset, blockSize int, allocType uint32) (int, bool)
	RoundUpAllocRequest(allocType uint32, allocSize int, allocAlignment uint) (int, uint)
	AllocationsConflict(firstAllocType uint32, secondAllocType uint32) bool

	StartValidation() any
	Validate(ctx any, offset, size int) error
	FinishValidation(ctx any) error
}

type LinearBlockMetadata

type LinearBlockMetadata struct {
	BlockMetadataBase
	// contains filtered or unexported fields
}

func NewLinearBlockMetadata

func NewLinearBlockMetadata(bufferImageGranularity int, granularityHandler GranularityCheck) *LinearBlockMetadata

func (*LinearBlockMetadata) AddDetailedStatistics

func (m *LinearBlockMetadata) AddDetailedStatistics(stats *memutils.DetailedStatistics)

func (*LinearBlockMetadata) AddStatistics

func (m *LinearBlockMetadata) AddStatistics(stats *memutils.Statistics)

func (*LinearBlockMetadata) Alloc

func (m *LinearBlockMetadata) Alloc(req AllocationRequest, allocType uint32, userData any) error

func (*LinearBlockMetadata) AllocationCount

func (m *LinearBlockMetadata) AllocationCount() int

func (*LinearBlockMetadata) AllocationListBegin

func (m *LinearBlockMetadata) AllocationListBegin() (BlockAllocationHandle, error)

func (*LinearBlockMetadata) AllocationOffset

func (m *LinearBlockMetadata) AllocationOffset(allocHandle BlockAllocationHandle) (int, error)

func (*LinearBlockMetadata) AllocationUserData

func (m *LinearBlockMetadata) AllocationUserData(allocHandle BlockAllocationHandle) (any, error)

func (*LinearBlockMetadata) CheckCorruption

func (m *LinearBlockMetadata) CheckCorruption(blockData unsafe.Pointer) (common.VkResult, error)

func (*LinearBlockMetadata) Clear

func (m *LinearBlockMetadata) Clear()

func (*LinearBlockMetadata) CreateAllocationRequest

func (m *LinearBlockMetadata) CreateAllocationRequest(
	allocSize int, allocAlignment uint,
	upperAddress bool,
	allocType uint32,
	strategy AllocationStrategy,
) (bool, AllocationRequest, error)

func (*LinearBlockMetadata) DebugLogAllAllocations

func (m *LinearBlockMetadata) DebugLogAllAllocations(log *slog.Logger, logFunc func(log *slog.Logger, offset int, size int, userData any))

func (*LinearBlockMetadata) FindNextAllocation

func (m *LinearBlockMetadata) FindNextAllocation(allocHandle BlockAllocationHandle) (BlockAllocationHandle, error)

func (*LinearBlockMetadata) FindNextFreeRegionSize

func (m *LinearBlockMetadata) FindNextFreeRegionSize(allocHandle BlockAllocationHandle) (int, error)

func (*LinearBlockMetadata) Free

func (m *LinearBlockMetadata) Free(allocHandle BlockAllocationHandle) error

func (*LinearBlockMetadata) FreeRegionsCount

func (m *LinearBlockMetadata) FreeRegionsCount() int

func (*LinearBlockMetadata) Init

func (m *LinearBlockMetadata) Init(size int)

func (*LinearBlockMetadata) IsEmpty

func (m *LinearBlockMetadata) IsEmpty() bool

func (*LinearBlockMetadata) PrintDetailedMapHeader

func (m *LinearBlockMetadata) PrintDetailedMapHeader(json jwriter.ObjectState)

func (*LinearBlockMetadata) SetAllocationUserData

func (m *LinearBlockMetadata) SetAllocationUserData(allocHandle BlockAllocationHandle, userData any) error

func (*LinearBlockMetadata) SumFreeSize

func (m *LinearBlockMetadata) SumFreeSize() int

func (*LinearBlockMetadata) Validate

func (m *LinearBlockMetadata) Validate() error

func (*LinearBlockMetadata) VisitAllBlocks

func (m *LinearBlockMetadata) VisitAllBlocks(handleBlock func(handle BlockAllocationHandle, offset int, size int, userData any, free bool) error) error

type SecondVectorMode

type SecondVectorMode uint32
const (
	SecondVectorModeEmpty SecondVectorMode = iota
	SecondVectorModeRingBuffer
	SecondVectorModeDoubleStack
)

func (SecondVectorMode) String

func (m SecondVectorMode) String() string

type Suballocation

type Suballocation struct {
	Offset   int
	Size     int
	UserData any
	Type     uint32
}

type TLSFBlockMetadata

type TLSFBlockMetadata struct {
	BlockMetadataBase
	// contains filtered or unexported fields
}

func NewTLSFBlockMetadata

func NewTLSFBlockMetadata(bufferImageGranularity int, granularityHandler GranularityCheck) *TLSFBlockMetadata

func (*TLSFBlockMetadata) AddDetailedStatistics

func (m *TLSFBlockMetadata) AddDetailedStatistics(stats *memutils.DetailedStatistics)

func (*TLSFBlockMetadata) AddStatistics

func (m *TLSFBlockMetadata) AddStatistics(stats *memutils.Statistics)

func (*TLSFBlockMetadata) Alloc

func (m *TLSFBlockMetadata) Alloc(req AllocationRequest, suballocType uint32, userData any) error

func (*TLSFBlockMetadata) AllocationCount

func (m *TLSFBlockMetadata) AllocationCount() int

func (*TLSFBlockMetadata) AllocationListBegin

func (m *TLSFBlockMetadata) AllocationListBegin() (BlockAllocationHandle, error)

func (*TLSFBlockMetadata) AllocationOffset

func (m *TLSFBlockMetadata) AllocationOffset(allocHandle BlockAllocationHandle) (int, error)

func (*TLSFBlockMetadata) AllocationUserData

func (m *TLSFBlockMetadata) AllocationUserData(allocHandle BlockAllocationHandle) (any, error)

func (*TLSFBlockMetadata) CheckCorruption

func (m *TLSFBlockMetadata) CheckCorruption(blockData unsafe.Pointer) (common.VkResult, error)

func (*TLSFBlockMetadata) Clear

func (m *TLSFBlockMetadata) Clear()

func (*TLSFBlockMetadata) CreateAllocationRequest

func (m *TLSFBlockMetadata) CreateAllocationRequest(
	allocSize int, allocAlignment uint,
	upperAddress bool,
	allocType uint32,
	strategy AllocationStrategy,
) (bool, AllocationRequest, error)

func (*TLSFBlockMetadata) DebugLogAllAllocations

func (m *TLSFBlockMetadata) DebugLogAllAllocations(logger *slog.Logger, logFunc func(log *slog.Logger, offset int, size int, userData any))

func (*TLSFBlockMetadata) FindNextAllocation

func (m *TLSFBlockMetadata) FindNextAllocation(alloc BlockAllocationHandle) (BlockAllocationHandle, error)

func (*TLSFBlockMetadata) FindNextFreeRegionSize

func (m *TLSFBlockMetadata) FindNextFreeRegionSize(alloc BlockAllocationHandle) (int, error)

func (*TLSFBlockMetadata) Free

func (m *TLSFBlockMetadata) Free(allocHandle BlockAllocationHandle) error

func (*TLSFBlockMetadata) FreeRegionsCount

func (m *TLSFBlockMetadata) FreeRegionsCount() int

func (*TLSFBlockMetadata) Init

func (m *TLSFBlockMetadata) Init(size int)

func (*TLSFBlockMetadata) IsEmpty

func (m *TLSFBlockMetadata) IsEmpty() bool

func (*TLSFBlockMetadata) PrintDetailedMapHeader

func (m *TLSFBlockMetadata) PrintDetailedMapHeader(json jwriter.ObjectState)

func (*TLSFBlockMetadata) SetAllocationUserData

func (m *TLSFBlockMetadata) SetAllocationUserData(allocHandle BlockAllocationHandle, userData any) error

func (*TLSFBlockMetadata) SumFreeSize

func (m *TLSFBlockMetadata) SumFreeSize() int

func (*TLSFBlockMetadata) Validate

func (m *TLSFBlockMetadata) Validate() error

func (*TLSFBlockMetadata) VisitAllBlocks

func (m *TLSFBlockMetadata) VisitAllBlocks(handleBlock func(handle BlockAllocationHandle, offset int, size int, userData any, free bool) error) error

Jump to

Keyboard shortcuts

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