MemoryStats 结构体详解:深入理解 Linux 和 Windows 容器内存指标

MemoryStats 结构体用于收集容器自启动以来所有的内存使用统计信息。需要注意的是,在 Linux 系统上,该结构体包含所有内存指标,而在 Windows 系统上,它只包含提交字节数和私有工作集统计信息。

// MemoryStats aggregates all memory stats since container inception on Linux.
// Windows returns stats for commit and private working set only.
type MemoryStats struct {
	// Linux Memory Stats

	// current res_counter usage for memory
	Usage uint64 'json:"usage,omitempty"'
	// maximum usage ever recorded.
	MaxUsage uint64 'json:"max_usage,omitempty"'
	// TODO(vishh): Export these as stronger types.
	// all the stats exported via memory.stat.
	Stats map[string]uint64 'json:"stats,omitempty"'
	// number of times memory usage hits limits.
	Failcnt uint64 'json:"failcnt,omitempty"'
	// 容器被分配的内存限制
	Limit   uint64 'json:"limit,omitempty"'

	// Windows Memory Stats
	// See https://technet.microsoft.com/en-us/magazine/ff382715.aspx

	// committed bytes
	Commit uint64 'json:"commitbytes,omitempty"'
	// peak committed bytes
	CommitPeak uint64 'json:"commitpeakbytes,omitempty"'
	// private working set
	PrivateWorkingSet uint64 'json:"privateworkingset,omitempty"'
}

Limit 字段详解

MemoryStats 结构体中,'Limit' 表示容器被分配的内存资源限制。 该字段表示容器可以使用的最大内存量,单位为字节。

其他重要字段

除了 Limit 字段外,MemoryStats 结构体还包含以下重要字段:

Linux 平台:

  • Usage: 当前内存使用量。
  • MaxUsage: 历史最大内存使用量。
  • Stats: 通过 /proc/vmstat 文件获取的详细内存统计信息。
  • Failcnt: 内存使用量触及限制的次数。

Windows 平台:

  • Commit: 提交的字节数。
  • CommitPeak: 峰值提交字节数。
  • PrivateWorkingSet: 私有工作集。

通过 MemoryStats 结构体,开发人员可以全面了解容器的内存使用情况,并根据实际需求进行资源限制和性能优化。

MemoryStats 结构体详解:深入理解 Linux 和 Windows 容器内存指标

原文地址: https://www.cveoy.top/t/topic/fAEb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录