sysmem

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sysmem answers two questions about memory: how much this process was given, and how much of it the Go runtime is holding.

"Given" is the container's limit when there is one (cgroup v2 memory.max, cgroup v1 memory.limit_in_bytes) and the machine's RAM otherwise: a filex in a container with 4 GiB on a 64 GiB host was given 4 GiB, and that is the figure a budget has to be a share of. The search index takes its memory budget from here (issue #115).

Index

Constants

View Source
const (
	SourceCgroupV2 = "cgroup v2 memory.max"
	SourceCgroupV1 = "cgroup v1 memory.limit_in_bytes"
	SourceHost     = "host memory"
	SourceUnknown  = "unknown"
)

Sources, as Budget.Source names them in the log.

Variables

This section is empty.

Functions

func Clamp

func Clamp(v, min, max int) int

Clamp keeps v inside [min, max].

func InUse

func InUse() uint64

InUse is the memory the Go runtime holds and has not handed back to the operating system: every heap span, stack and runtime structure. It leaves out memory-mapped files (the search index's segments), whose pages are the kernel's to drop under pressure and are not this process's to ration.

Types

type Budget

type Budget struct {
	Bytes  uint64
	Source string
}

Budget is the memory this process was given and where the figure came from. Bytes is 0 when nothing could be read.

func Allocated

func Allocated() Budget

Allocated returns the memory this process was given: the container's limit when it has one below the machine's RAM, the machine's RAM otherwise.

func (Budget) Share

func (b Budget) Share(percent, min, max int) uint64

Share is percent of b, with percent clamped to [min, max]. A budget that could not be read has no share.

Jump to

Keyboard shortcuts

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