memory

package
v0.0.0-...-9474aff Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Overview

Package memory contains common utilities to allocate memory and read memory pressure state on ChromeOS and Android.

Package memory contains test helpers for allocating memory and determining if memory is low.

Index

Constants

View Source
const (
	// KiB is the number of bytes in a kibibyte.
	KiB = 1024
	// MiB is the number of bytes in a mebibyte.
	MiB = KiB * 1024
	// GiB is the number of bytes in a gibibyte.
	GiB = MiB * 1024
	// TiB is the number of bytes in a tebibyte.
	TiB = GiB * 1024
	// PageBytes is the number of bytes in a page.
	PageBytes = 4096
	// KiBInMiB is the denominator to convert KiB to MiB
	KiBInMiB = 1024
)

Variables

This section is empty.

Functions

func ChromeOSAvailableMetrics

func ChromeOSAvailableMetrics(ctx context.Context, p *perf.Values, suffix string) error

ChromeOSAvailableMetrics logs performance metrics for ChromeOS memory margins and ChromeOS's available memory counter.

func CrosvmFincoreMetrics

func CrosvmFincoreMetrics(ctx context.Context, p *perf.Values, outdir, suffix string) error

CrosvmFincoreMetrics logs a JSON file with the amount resident memory for each file used as a disk by crosvm. If p is not nil, the amount of memory used by each VM type is logged as perf.Values. If outdir is "", then no logs are written.

func IgnoreZone

func IgnoreZone(info ZoneInfo) bool

IgnoreZone checks if a zone is not used. It checks if the pages free, min, low are all 0.

func LogPSIMetricsSlice

func LogPSIMetricsSlice(begin, end *PSIStats, p *perf.Values, suffix string)

LogPSIMetricsSlice logs delta metrics between two existing snapshots (no new snapshots are taken).

func LogZramStatMetricsSlice

func LogZramStatMetricsSlice(begin, end *ZramStats, p *perf.Values, suffix string)

LogZramStatMetricsSlice logs delta metrics between two previously-extracted snapshots.

func ManaTEEMetrics

func ManaTEEMetrics(ctx context.Context, p *perf.Values, outdir, suffix string) error

ManaTEEMetrics generates metrics for ManaTEE hypervisor memory usage.

func NewSmapsRollup

func NewSmapsRollup(smapsRollupFileData []byte) (map[string]uint64, error)

NewSmapsRollup parses the contents of a /proc/<pid>/smaps_rollup file. All sizes are in bytes.

func PSIMetrics

func PSIMetrics(ctx context.Context, a *arc.ARC, base *PSIStats, p *perf.Values, outdir, suffix string) error

PSIMetrics writes a JSON file containing statistics from PSI metrics. Parameter base is optional:

  • if base is set, it defines the starting point for metrics, and its contents are overwritten with the latest snapshot of PSI metrics.
  • if base is nil, metrics are averaged since boot.

If outdir is "", then no logs are written.

func ReportHostMetrics

func ReportHostMetrics(summary *HostSummary, p *perf.Values, suffix string)

ReportHostMetrics outputs a set of representative metrics into the supplied performance data dictionary.

func ReportZramMmStatMetrics

func ReportZramMmStatMetrics(summary *ZramSummary, p *perf.Values, suffix string)

ReportZramMmStatMetrics outputs a set of representative metrics into the supplied performance data dictionary.

func ZramStatMetrics

func ZramStatMetrics(ctx context.Context, base *ZramStats, p *perf.Values, outdir, suffix string) error

ZramStatMetrics writes a JSON file containing statistics from /sys/block/zram*/stat. If outdir is "", then no logs are written.

Types

type AvailableLimit

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

AvailableLimit is a Limit for ChromeOS available memory.

func NewAvailableLimit

func NewAvailableLimit(ctx context.Context, rm *resourced.Client, margin uint64) (*AvailableLimit, error)

NewAvailableLimit creates a Limit that measures how far away ChromeOS available memory is from a specified margin, in bytes.

func (*AvailableLimit) AssertNotReached

func (l *AvailableLimit) AssertNotReached(ctx context.Context) error

AssertNotReached checks that available memory is above the margin.

func (*AvailableLimit) Distance

func (l *AvailableLimit) Distance(ctx context.Context) (int64, error)

Distance returns the difference between available memory and the provided margin, in bytes. Result will be negative if available memory is below the margin.

type CategoryHostMetrics

type CategoryHostMetrics struct {
	Pss      uint64
	PssSwap  uint64
	PssGuest uint64
}

CategoryHostMetrics has a summary of host HostMetrics we keep on a per-category basis for reporting. All values in Kilobytes.

type ChromeOSAllocator

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

ChromeOSAllocator helps test code allocate memory on ChromeOS.

func NewChromeOSAllocator

func NewChromeOSAllocator() *ChromeOSAllocator

NewChromeOSAllocator creates a helper to allocate memory on ChromeOS. Returns the helper.

func (*ChromeOSAllocator) Allocate

func (c *ChromeOSAllocator) Allocate(size int) error

Allocate some memory on ChromeOS. Parameter size is the size of the allocation in bytes. Allocated memory is filled with random data so that page compression can't shrink it.

func (*ChromeOSAllocator) AllocateUntil

func (c *ChromeOSAllocator) AllocateUntil(
	ctx context.Context,
	rm *resourced.Client,
	attemptInterval time.Duration,
	attempts int,
	margin uint64,
) ([]uint64, error)

AllocateUntil allocates memory until available memory is at the passed margin, in bytes. To allow the system to stabilize, it will try attempts times, waiting attemptInterval duration between each attempt. If too much memory has been allocated, then the extra is freed between attempts to avoid overshooting the margin. Returns the allocated memory at every attempt.

func (*ChromeOSAllocator) FreeAll

func (c *ChromeOSAllocator) FreeAll() (uint64, error)

FreeAll frees all allocated buffers. Returns the size of freed memory.

func (*ChromeOSAllocator) FreeLast

func (c *ChromeOSAllocator) FreeLast() (uint64, error)

FreeLast frees the most recently allocated buffer. Returns the size of the buffer freed.

func (*ChromeOSAllocator) Size

func (c *ChromeOSAllocator) Size() uint64

Size returns the size of all allocated memory

type CompositeLimit

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

CompositeLimit combines a set of Limits.

func NewCompositeLimit

func NewCompositeLimit(limits ...Limit) *CompositeLimit

NewCompositeLimit creates a Limit that returns the minimum Distance() returned by all the passed limits.

func (*CompositeLimit) AssertNotReached

func (l *CompositeLimit) AssertNotReached(ctx context.Context) error

AssertNotReached checks that child Limits are above their limits.

func (*CompositeLimit) Distance

func (l *CompositeLimit) Distance(ctx context.Context) (int64, error)

Distance returns the minimum Distance returned by any child Limit.

type HostSummary

type HostSummary struct {
	MemTotal         uint64
	MemFree          uint64
	HostCachedKernel uint64
	CategoryMetrics  NameToCategoryMetricsMap
}

HostSummary captures a few key data items that are used to compute overall system memory status. All values are expressed in Kilobytes.

func GetHostMetrics

func GetHostMetrics(ctx context.Context, outdir, suffix string) (*HostSummary, error)

GetHostMetrics parses smaps and smaps_rollup information from every running process on the ChromeOS (host) side. Values are summarized according to the processCategories defined above and returned in the HostSummary structure. If outdir is provided, detailed rollup information is also written to files in that directory.

type Limit

type Limit interface {
	// Distance returns the amount of memory that can be allocated in bytes
	// before the limit is reached. If negative, abs(Distance()) bytes must be
	// freed to go below the limit.
	Distance(ctx context.Context) (int64, error)
	// AssertNotReached returns an error if the limit has been reached. Useful
	// for Polls to get information about which limit was exceeded, and by how
	// much.
	AssertNotReached(ctx context.Context) error
}

Limit allows tests to determine if memory use is close to a limit without having to know the specific memory counters used.

type NameToCategoryMetricsMap

type NameToCategoryMetricsMap map[string]*CategoryHostMetrics

NameToCategoryMetricsMap maps a process category name to its key PSS metrics.

type NamedSmapsRollup

type NamedSmapsRollup struct {
	Command string
	Pid     int32
	Shared  *SharedInfo
	Rollup  map[string]uint64
}

NamedSmapsRollup is a SmapsRollup plus the process name and ID, and information on shared memory use (Shared field).

type PSIDetail

type PSIDetail struct {
	Avg10, Avg60, Avg300 float64
	Total                uint64
}

PSIDetail holds one line of statistics from memory pressure dumps.

type PSIOneSystemStats

type PSIOneSystemStats struct {
	Some PSIDetail
	Full PSIDetail
}

PSIOneSystemStats holds statistics from memory pressure dumps for one system.

func (*PSIOneSystemStats) Clone

Clone creates a deep copy of the provided pointer.

type PSIStats

type PSIStats struct {
	Host      *PSIOneSystemStats
	Arc       *PSIOneSystemStats
	Timestamp time.Time
}

PSIStats holds statistics from memory pressure dumps.

func NewPSIStats

func NewPSIStats(ctx context.Context, a *arc.ARC) (*PSIStats, error)

NewPSIStats parses /proc/pressure/memory to create a PSIStats.

func (*PSIStats) Clone

func (t *PSIStats) Clone() *PSIStats

Clone creates a deep copy of the provided pointer.

type SharedInfo

type SharedInfo struct {
	SharedSwapPss  uint64
	CrosvmGuestPss uint64
}

SharedInfo holds shared memory use information for one process. SharedSwapPss is the amount of swap used by shared memory regions divided by the number of times those regions are mapped. CrosvmGuestPss is the sum of the Pss used by the crosvm_guest region,

(which means memory from the VM mapped on the host).

type SharedInfoMap

type SharedInfoMap map[int32]*SharedInfo

SharedInfoMap maps process ids to shared memory information.

type SharedMapping

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

SharedMapping contains information parsed from a smaps entry. Numbers are KiB.

func ParseSmapsData

func ParseSmapsData(data []byte) ([]SharedMapping, error)

ParseSmapsData parses the given smaps data.

type ZoneInfo

type ZoneInfo struct {
	Name string
	Free uint64
	Low  uint64
	Min  uint64
}

ZoneInfo contains the values of counters from one zone in /proc/zoneinfo. All sizes are in bytes.

func ParseZoneInfo

func ParseZoneInfo(data string) ([]ZoneInfo, error)

ParseZoneInfo converts the contents of /proc/zoneinfo into a []ZoneInfo.

func ReadZoneInfo

func ReadZoneInfo() ([]ZoneInfo, error)

ReadZoneInfo parses /proc/zoneinfo into a slice of ZoneInfo structures.

type ZoneInfoLimit

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

ZoneInfoLimit is a Limit that uses /proc/zoneinfo to allow tests to allocate enough memory to trigger page reclaim, but not so much memory that they OOM.

func NewPageReclaimLimit

func NewPageReclaimLimit() *ZoneInfoLimit

NewPageReclaimLimit creates a Limit that returns Distance 0 when Linux is reclaiming memory and is close to OOMing.

func NewZoneInfoLimit

func NewZoneInfoLimit(readZoneInfo func(context.Context) ([]ZoneInfo, error), zones map[string]bool) *ZoneInfoLimit

NewZoneInfoLimit creates a limit the returns

func (*ZoneInfoLimit) AssertNotReached

func (l *ZoneInfoLimit) AssertNotReached(ctx context.Context) error

AssertNotReached checks that no zone has its free pages counter below (min+low)/2.

func (*ZoneInfoLimit) Distance

func (l *ZoneInfoLimit) Distance(ctx context.Context) (int64, error)

Distance computes how far away from OOMing we are. For each zone, compute zoneDistance := (min+low)/2. If any zoneDistance in l.lowZones is negative, return the lowest zoneDistance to keep any lowZone away from its min watermark. If no l.lowZones is negative, return the sum of all zoneDistance to indicate how many free pages there are in total before we start getting close to the min watermark in any of l.lowZones.

type ZramMmStat

type ZramMmStat struct {
	OrigDataSize, ComprDataSize, MemUsedTotal, MemLimit, MemUsedMax, SamePages, PagesCompacted uint64
	// Some fields have been introduced by newer kernels, make them optional.
	HugePages, HugePagesSince *uint64 `json:",omitempty"`
}

ZramMmStat holds statistics from /sys/block/zram*/mm_stat.

func NewZramMmStat

func NewZramMmStat() (*ZramMmStat, error)

NewZramMmStat parses /sys/block/zram*/mm_stat to create a ZramMmStat.

type ZramOpStats

type ZramOpStats struct {
	Ops, MergedOps, Sectors, Wait uint64
}

ZramOpStats holds stats for one transaction type (read, write, discard).

func (*ZramOpStats) Clone

func (t *ZramOpStats) Clone() *ZramOpStats

Clone creates a deep copy of the provided pointer.

type ZramStats

type ZramStats struct {
	Read                              ZramOpStats
	Write                             ZramOpStats
	InFlightOps, IoTicks, TimeInQueue uint64
	Discard                           *ZramOpStats
}

ZramStats holds statistics from /sys/block/zram*/stat.

func NewZramStats

func NewZramStats() (*ZramStats, error)

NewZramStats parses /sys/block/zram*/stat to create a ZramStats.

func (*ZramStats) Clone

func (t *ZramStats) Clone() *ZramStats

Clone creates a deep copy of the provided pointer.

type ZramSummary

type ZramSummary struct {
	OrigDataSize  uint64
	ComprDataSize uint64
	MemUsedTotal  uint64
}

ZramSummary holds a summary of ZRAM usage by the host. All values in Kilobytes.

func GetZramMmStatMetrics

func GetZramMmStatMetrics(ctx context.Context, outdir, suffix string) (*ZramSummary, error)

GetZramMmStatMetrics parses statistics from /sys/block/zram/mm_stat and returns a summary of them as ZramSummary. If outdir is provided, intermediate files are dumped to that directory.

Directories

Path Synopsis
Package arc contains test helpers for determining if memory is low in ARC.
Package arc contains test helpers for determining if memory is low in ARC.
Package kernelmeter provides a mechanism for collecting kernel-related measurements in parallel with the execution of a test.
Package kernelmeter provides a mechanism for collecting kernel-related measurements in parallel with the execution of a test.
Package memoryuser contains common code to run multifaceted memory tests with Chrome, ARC, and VMs.
Package memoryuser contains common code to run multifaceted memory tests with Chrome, ARC, and VMs.
Package mempressure creates a realistic memory pressure situation and takes related measurements.
Package mempressure creates a realistic memory pressure situation and takes related measurements.
Package metrics implements a unified shell to access various kinds of memory metrics.
Package metrics implements a unified shell to access various kinds of memory metrics.

Jump to

Keyboard shortcuts

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