pub(crate) struct OOMWatcher;Expand description
Watches the cgroup of a process for OOM kills, see
OOMWatcher::watch.
Implementations§
Source§impl OOMWatcher
impl OOMWatcher
Sourcepub(super) fn process_cgroup_subsystem_path_cgroup_v2(
pid: Pid,
) -> Result<Option<PathBuf>>
pub(super) fn process_cgroup_subsystem_path_cgroup_v2( pid: Pid, ) -> Result<Option<PathBuf>>
The cgroup v2 path of a process, none if the process is gone.
Sourcepub(super) fn unified_cgroup_path(cgroup_file: impl BufRead) -> Result<PathBuf>
pub(super) fn unified_cgroup_path(cgroup_file: impl BufRead) -> Result<PathBuf>
The cgroupfs path of the unified hierarchy from a /proc/<pid>/cgroup
file. Named cgroup v1 hierarchies, like the one of systemd, are
listed as well and may come first.
Sourcepub(super) fn cgroup_v2_path(line: &str) -> Result<PathBuf>
pub(super) fn cgroup_v2_path(line: &str) -> Result<PathBuf>
The cgroupfs path of the unified hierarchy line 0::cgroup-path of
/proc/<pid>/cgroup. The path may contain colons itself.
Sourcefn strip_cgroup_root(path: Option<&str>) -> Result<&str>
fn strip_cgroup_root(path: Option<&str>) -> Result<&str>
The cgroup path relative to the root of its hierarchy.
fn try_open_cgroup_path(pid: Pid) -> Result<Option<StdFile>>
Source§impl OOMWatcher
impl OOMWatcher
Sourceconst MAX_WATCHER_RESTARTS: u32 = 3
const MAX_WATCHER_RESTARTS: u32 = 3
How often an OOM watcher watches its files again on a new shared watcher, after the reader of the events failed.
Sourcepub(super) async fn oom_handling_cgroup_v2(
token: &CancellationToken,
pid: Pid,
) -> Result<Option<OOMEvent>>
pub(super) async fn oom_handling_cgroup_v2( token: &CancellationToken, pid: Pid, ) -> Result<Option<OOMEvent>>
Watch the cgroup of a process with cgroup v2, see
OOMWatcher::watch.
Sourceasync fn watch_cgroup_v2(token: &CancellationToken, leaf: &Path) -> OOMEvent
async fn watch_cgroup_v2(token: &CancellationToken, leaf: &Path) -> OOMEvent
Wait for an OOM of the cgroup v2 leaf until token gets cancelled
and return what was found.
An OOM counts once the counters of the leaf went up. The leaf may be
gone at the exit, the systemd cgroup manager removes the scope of a
container once its processes exited. Then the hierarchical oom_kill
counter of the nearest ancestor which outlives it tells whether a kill
happened meanwhile, see OOMEvent::possible_oom. A removal is no OOM
on its own. cgroupfs reports it with IN_IGNORED only, which ends the
watch without an event.
Sourcefn watch_failed(message: &str, e: &Error)
fn watch_failed(message: &str, e: &Error)
Log a failure to watch memory events. A file which is gone, like the
one of a cgroup which got removed already, is expected. Others, like
running out of inotify instances or watches, get a warning, only the
first one until a watch works again, see WATCH_FAILING.
Sourcefn is_not_found(e: &Error) -> bool
fn is_not_found(e: &Error) -> bool
Whether watching or reading failed because the file does not exist.
cgroupfs fails with ENODEV instead for a file whose cgroup got
removed while it got opened or read.
Sourcefn initial_oom_counters(path: &Path) -> OomCounters
fn initial_oom_counters(path: &Path) -> OomCounters
Read the current OOM counters of a memory events file to establish a baseline, so that only OOMs during this container’s lifetime count.
fn check_for_oom( memory_events_file_path: &Path, last: OomCounters, ) -> Result<(OomCounters, bool)>
Sourcefn read_oom_counters(path: &Path) -> Result<OomCounters>
fn read_oom_counters(path: &Path) -> Result<OomCounters>
Read the oom and oom_kill counters of a memory events file.
Sourcepub(super) fn parse_oom_counters(content: &str) -> Result<OomCounters>
pub(super) fn parse_oom_counters(content: &str) -> Result<OomCounters>
Parse the oom and oom_kill counters of the content of a memory
events file.
Sourcefn file_not_found(f: impl AsRef<Path>) -> bool
fn file_not_found(f: impl AsRef<Path>) -> bool
Checks if a file does not exist on disk.
Source§impl OOMWatcher
impl OOMWatcher
Sourcepub(crate) async fn watch(
token: &CancellationToken,
pid: Pid,
exit_paths: &[PathBuf],
) -> Option<OOMEvent>
pub(crate) async fn watch( token: &CancellationToken, pid: Pid, exit_paths: &[PathBuf], ) -> Option<OOMEvent>
Watch the cgroup of the process for an OOM until token gets
cancelled, which the exit of the process does, and return what was
found. The OOM files get written for an OOM found on its own. None if
the cgroup could not be watched, like without cgroup v2, or the
process was gone already.
Sourcefn supported(cgroup_v2: bool, warned: &AtomicBool) -> bool
fn supported(cgroup_v2: bool, warned: &AtomicBool) -> bool
Whether the OOM kills of the host can be watched, which takes the
unified hierarchy of cgroup v2 at the cgroup root. Without it, like
with cgroup v1 or a hybrid setup, the containers run without the OOM
detection, which a warning tells once per server, as noted in
warned, instead of with every container.
Sourcefn counters(
content: &str,
) -> impl Iterator<Item = (&str, Result<u64, ParseIntError>)>
fn counters( content: &str, ) -> impl Iterator<Item = (&str, Result<u64, ParseIntError>)>
The counters of a cgroup file of key value lines, like
memory.events, by their key.
Sourcepub(crate) async fn write_oom_files(exit_paths: &[PathBuf])
pub(crate) async fn write_oom_files(exit_paths: &[PathBuf])
Create the empty OOM files, like conmon does. A failure is only logged, the exit gets reported either way, only without the OOM. A symlink at the path does not get followed, like for the log files.
Auto Trait Implementations§
impl Freeze for OOMWatcher
impl RefUnwindSafe for OOMWatcher
impl Send for OOMWatcher
impl Sync for OOMWatcher
impl Unpin for OOMWatcher
impl UnsafeUnpin for OOMWatcher
impl UnwindSafe for OOMWatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].