pub(super) struct SharedWatcher {
inotify: Arc<Inotify>,
watches: Arc<Mutex<Watches>>,
failed: Arc<AtomicBool>,
given_up: AtomicBool,
reader: JoinHandle<()>,
next_id: AtomicU64,
}Expand description
A single inotify instance shared by all OOM watchers.
Creating an inotify instance per container does not scale with the number of containers in a pod. All memory event files are watched through this instance instead, a task reads its events and dispatches them to the subscribers of their path. Adding and removing a watch does not block, the subscribers do that right away.
Fields§
§inotify: Arc<Inotify>§watches: Arc<Mutex<Watches>>The subscribers and the watches. The reader of the events takes this lock as well, it never waits while holding it.
failed: Arc<AtomicBool>Set once the reader of the events stopped, the next subscription gets a new watcher then.
given_up: AtomicBoolSet once a subscriber gave up watching after the reader stopped, see
Subscription::give_up.
reader: JoinHandle<()>The task which reads the events, it ends with the watcher.
next_id: AtomicU64Source of unique subscription identifiers.
Implementations§
Sourcepub(super) fn get() -> Result<Arc<Self>>
pub(super) fn get() -> Result<Arc<Self>>
Retrieve the shared watcher, creating it if necessary.
Sourcefn get_in(slot: &Mutex<Weak<SharedWatcher>>) -> Result<Arc<Self>>
fn get_in(slot: &Mutex<Weak<SharedWatcher>>) -> Result<Arc<Self>>
Retrieve the watcher kept in the slot, or create one there.
fn slot(_: &Handle) -> &'static Mutex<Weak<SharedWatcher>>
fn new() -> Result<Self>
Sourceasync fn read_events(
registered: AsyncFd<Fd<Arc<Inotify>>>,
watches: Arc<Mutex<Watches>>,
failed: Arc<AtomicBool>,
)
async fn read_events( registered: AsyncFd<Fd<Arc<Inotify>>>, watches: Arc<Mutex<Watches>>, failed: Arc<AtomicBool>, )
Read the events of the kernel and dispatch them, until the watcher got dropped or reading failed.
After a dispatch, the events which come meanwhile get dispatched
together once MIN_DISPATCH_INTERVAL passed. The instance gets
deregistered until then: tokio registers it edge triggered, and
every new event would wake the runtime while it stays registered,
even if nothing reads it.
Sourcefn read_queued(inotify: &Inotify) -> Result<Vec<InotifyEvent>>
fn read_queued(inotify: &Inotify) -> Result<Vec<InotifyEvent>>
Read all queued events, which a single read takes up to 4 KiB of.
Fails with WouldBlock only if there is none.
Sourcefn stopped(watches: &Mutex<Watches>, failed: &AtomicBool)
fn stopped(watches: &Mutex<Watches>, failed: &AtomicBool)
The reader stopped. The next subscription gets a new watcher. The watches get dropped with their senders, so that the channels of the subscribers end once they took the events so far, they watch again then.
Sourcepub(super) fn subscribe(
self: &Arc<Self>,
path: &Path,
tx: Sender<WatchEvent>,
) -> Result<Subscription>
pub(super) fn subscribe( self: &Arc<Self>, path: &Path, tx: Sender<WatchEvent>, ) -> Result<Subscription>
Start watching path on behalf of tx. The watch gets removed when the
returned subscription is dropped and no other subscriber of the watch
is left.
fn unsubscribe(&self, id: u64, wd: WatchDescriptor)
Trait Implementations§
Auto Trait Implementations§
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].