From 3048e4fa97c45ff67a9d0246518501f4a5de7ef4 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Fri, 1 Aug 2025 14:54:26 -0400 Subject: [PATCH 1/3] Add optional register_fixed_buffer method to IO trait --- core/io/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/io/mod.rs b/core/io/mod.rs index 8560216e8..a822cf832 100644 --- a/core/io/mod.rs +++ b/core/io/mod.rs @@ -2,6 +2,7 @@ use crate::Result; use bitflags::bitflags; use cfg_block::cfg_block; use std::fmt; +use std::ptr::NonNull; use std::sync::Arc; use std::{ cell::{Cell, Ref, RefCell, RefMut}, @@ -89,6 +90,12 @@ pub trait IO: Clock + Send + Sync { fn generate_random_number(&self) -> i64; fn get_memory_io(&self) -> Arc; + + fn register_fixed_buffer(&self, _ptr: NonNull, _len: usize) -> Result<()> { + Err(crate::LimboError::InternalError( + "unsupported operation".to_string(), + )) + } } pub type Complete = dyn Fn(Arc>, i32); From 9289dd7e9a8f9be491d993672c4987a2f38a511d Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Fri, 1 Aug 2025 14:55:35 -0400 Subject: [PATCH 2/3] Implement register_fixed_buffer for io_uring IO backend --- core/io/io_uring.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/io/io_uring.rs b/core/io/io_uring.rs index b2afeb652..1fc74cf1e 100644 --- a/core/io/io_uring.rs +++ b/core/io/io_uring.rs @@ -460,6 +460,29 @@ impl IO for UringIO { fn get_memory_io(&self) -> Arc { Arc::new(MemoryIO::new()) } + + fn register_fixed_buffer(&self, ptr: std::ptr::NonNull, len: usize) -> Result<()> { + turso_assert!( + len % 512 == 0, + "fixed buffer length must be logical block aligned" + ); + let inner = self.inner.borrow_mut(); + let default_id = 0; + unsafe { + // RL_MEMLOCK cap is typically 8MB, the current design is to have one large arena + // registered at startup and therefore we can simply use the zero index, falling back + // to similar logic as the existing buffer pool for cases where it is over capacity. + inner.ring.ring.submitter().register_buffers_update( + default_id, + &[libc::iovec { + iov_base: ptr.as_ptr() as *mut libc::c_void, + iov_len: len, + }], + None, + )? + }; + Ok(()) + } } impl Clock for UringIO { From b8ed4358f1cb97fa23255e003e5f5a789eceb2a3 Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Fri, 1 Aug 2025 14:56:43 -0400 Subject: [PATCH 3/3] register buffers sparse on ring initiate to support fixed operations --- core/io/io_uring.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/io/io_uring.rs b/core/io/io_uring.rs index 1fc74cf1e..ff0c7c793 100644 --- a/core/io/io_uring.rs +++ b/core/io/io_uring.rs @@ -105,6 +105,10 @@ impl UringIO { }; // we only ever have 2 files open at a time for the moment ring.submitter().register_files_sparse(FILES)?; + // RL_MEMLOCK cap is typically 8MB, the current design is to have one large arena + // registered at startup and therefore we can simply use the zero index, falling back + // to similar logic as the existing buffer pool for cases where it is over capacity. + ring.submitter().register_buffers_sparse(1)?; let inner = InnerUringIO { ring: WrappedIOUring { ring, @@ -469,9 +473,6 @@ impl IO for UringIO { let inner = self.inner.borrow_mut(); let default_id = 0; unsafe { - // RL_MEMLOCK cap is typically 8MB, the current design is to have one large arena - // registered at startup and therefore we can simply use the zero index, falling back - // to similar logic as the existing buffer pool for cases where it is over capacity. inner.ring.ring.submitter().register_buffers_update( default_id, &[libc::iovec {