MCPcopy
hub / github.com/google/gvisor / Init

Function Init

pkg/sentry/usage/memory.go:250–280  ·  view source on GitHub ↗

Init initializes global 'MemoryAccounting'.

()

Source from the content-addressed store, hash-verified

248
249// Init initializes global 'MemoryAccounting'.
250func Init() error {
251 initOnce.Do(func() {
252 initErr = func() error {
253 const name = "memory-usage"
254 fd, err := memutil.CreateMemFD(name, 0)
255 if err != nil {
256 return fmt.Errorf("error creating usage file: %v", err)
257 }
258 file := os.NewFile(uintptr(fd), name)
259 if err := file.Truncate(int64(RTMemoryStatsSize)); err != nil {
260 return fmt.Errorf("error truncating usage file: %v", err)
261 }
262 // Note: We rely on the returned page being initially zeroed. This will
263 // always be the case for a newly mapped page from /dev/shm. If we obtain
264 // the shared memory through some other means in the future, we may have to
265 // explicitly zero the page.
266 mmap, err := memutil.MapFile(0, RTMemoryStatsSize, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED, file.Fd(), 0)
267 if err != nil {
268 return fmt.Errorf("error mapping usage file: %v", err)
269 }
270
271 MemoryAccounting = &MemoryLocked{
272 File: file,
273 RTMemoryStats: RTMemoryStatsPointer(mmap),
274 MemCgIDToMemStats: make(map[uint32]*memoryStats),
275 }
276 return nil
277 }()
278 })
279 return initErr
280}
281
282// MemoryAccounting is the global memory stats.
283//

Callers 2

BootFunction · 0.92
NewFunction · 0.92

Calls 7

CreateMemFDFunction · 0.92
MapFileFunction · 0.92
RTMemoryStatsPointerFunction · 0.85
DoMethod · 0.65
ErrorfMethod · 0.65
NewFileMethod · 0.65
TruncateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…