agave_io_uring/
lib.rs

1#![cfg_attr(
2    not(feature = "agave-unstable-api"),
3    deprecated(
4        since = "3.1.0",
5        note = "This crate has been marked for formal inclusion in the Agave Unstable API. From \
6                v4.0.0 onward, the `agave-unstable-api` crate feature must be specified to \
7                acknowledge use of an interface that may break without warning."
8    )
9)]
10#![cfg(target_os = "linux")]
11mod ring;
12mod slab;
13use {
14    io_uring::IoUring,
15    std::{io, sync::Once},
16};
17pub use {ring::*, slab::FixedSlab};
18
19pub fn io_uring_supported() -> bool {
20    static mut IO_URING_SUPPORTED: bool = false;
21    static IO_URING_SUPPORTED_ONCE: Once = Once::new();
22    IO_URING_SUPPORTED_ONCE.call_once(|| {
23        fn check() -> io::Result<()> {
24            let ring = IoUring::new(1)?;
25            if !ring.params().is_feature_nodrop() {
26                return Err(io::Error::other("no IORING_FEAT_NODROP"));
27            }
28            if !ring.params().is_feature_sqpoll_nonfixed() {
29                return Err(io::Error::other("no IORING_FEAT_SQPOLL_NONFIXED"));
30            }
31            Ok(())
32        }
33        unsafe {
34            IO_URING_SUPPORTED = match check() {
35                Ok(_) => {
36                    log::info!("io_uring supported");
37                    true
38                }
39                Err(e) => {
40                    log::info!("io_uring NOT supported: {e}");
41                    false
42                }
43            };
44        }
45    });
46    unsafe { IO_URING_SUPPORTED }
47}