Skip to main content

OOMWatcher

Struct OOMWatcher 

Source
pub(crate) struct OOMWatcher;
Expand description

Watches the cgroup of a process for OOM kills, see OOMWatcher::watch.

Implementations§

Source§

impl OOMWatcher

Source

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.

Source

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.

Source

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.

Source

fn strip_cgroup_root(path: Option<&str>) -> Result<&str>

The cgroup path relative to the root of its hierarchy.

Source

fn try_open_cgroup_path(pid: Pid) -> Result<Option<StdFile>>

Source§

impl OOMWatcher

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn check_for_oom( memory_events_file_path: &Path, last: OomCounters, ) -> Result<(OomCounters, bool)>

Source

fn read_oom_counters(path: &Path) -> Result<OomCounters>

Read the oom and oom_kill counters of a memory events file.

Source

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.

Source

fn file_not_found(f: impl AsRef<Path>) -> bool

Checks if a file does not exist on disk.

Source§

impl OOMWatcher

Source

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.

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more