MCPcopy Create free account
hub / github.com/containerd/containerd / start

Method start

internal/oom/watcher.go:101–141  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99}
100
101func (w *watcher) start() {
102 go func() {
103 defer close(w.errCh)
104 defer w.eventFD.Close()
105
106 var (
107 oomKills uint64
108 shouldExit bool
109 )
110 for !shouldExit {
111 buffer := make([]byte, unix.SizeofInotifyEvent*10)
112 bytesRead, err := w.eventFD.Read(buffer)
113 if err != nil {
114 if !errors.Is(err, os.ErrClosed) {
115 w.errCh <- err
116 return
117 }
118 shouldExit = true
119 } else {
120 if bytesRead < unix.SizeofInotifyEvent {
121 continue
122 }
123 }
124
125 // TODO: We should export MemoryEventsStat function
126 out := make(map[string]uint64)
127 if err := readKVStatsFile(w.cgroupPath, "memory.events", out); err != nil {
128 // When cgroup is deleted read may return -ENODEV instead of -ENOENT from open.
129 if _, statErr := os.Lstat(filepath.Join(w.cgroupPath, "memory.events")); !os.IsNotExist(statErr) {
130 w.errCh <- err
131 }
132 return
133 }
134
135 if v := out["oom_kill"]; v > oomKills {
136 oomKills = v
137 w.eventFn(w.cid)
138 }
139 }
140 }()
141}
142
143func (w *watcher) stop() error {
144 cerr := w.eventFD.Close()

Callers 1

AddMethod · 0.95

Calls 4

readKVStatsFileFunction · 0.85
LstatMethod · 0.80
CloseMethod · 0.65
ReadMethod · 0.65

Tested by

no test coverage detected