kata-containers / cgroups-rs

Native Rust library for managing control groups under Linux
https://crates.io/crates/cgroups-rs
Other
116 stars 47 forks source link

Add native Tokio support for oom events of the memory controller #52

Closed flxo closed 2 years ago

flxo commented 3 years ago

Is your feature request related to a problem? Please describe.

The functions events::notify_on_oom_v1 and events::notify_on_oom_v2 return a std::sync::mpsc::Receiver. Using the std channels in a tokio environment is cumbersome because it requires to spawn a thread that blocks on Receiver::recv. There's an additional thread spawned inside those functions that block on reading the eventfd and sending the notification via the channel.

Describe the solution you'd like

Add a feature tokio that returns a Result<tokio::sync::mpsc::Receiver> or a Result<impl Stream<Item = Stream>>> that seamlessly integrates into tokio applications. For the implementation the tokio eventfd can be used that uses a non blocking event_fd.

Additional context

The dependency list of cgroups-rs is very small which is nice. Adding tokio as a dependency must definitely be hidden behind a feature.

I can come up with a proposal PR if wanted. :-)

jodh-intel commented 3 years ago

Thanks for raising @flxo.

This makes sense to me. wdyt @lifupan / @Tim-Zhang ?

lifupan commented 3 years ago

Hi @flxo @jodh-intel

Yeah,It's reasonable to add an async version of oom event watcher and use a feature to control it. The PR is welcomed, thanks.

flxo commented 3 years ago

Thanks for your feedback! I pushed #53 and will continue with some tests in my environment.

flxo commented 2 years ago

Closing due to #53