Expand description
Vfs abstraction for Pigeonhole: files, aligned buffers, completions, pread pool and fault-injecting simulated backend.
Every byte any other crate reads or writes goes through a Vfs, so the simulator can
inject faults and control time. Backends:
pread::PreadVfs: real files, apread/pwritethread pool for submitted I/O. The safe reference backend on every platform.sim::SimVfs: in-memory, deterministic from a seed, with torn writes, reordered fsyncs, ENOSPC and crashes. Withsim::FaultPlan::noneit is the plain in-memory mock other crates test against.uring::UringVfs(Linux only, so not linked here): real files with submitted I/O on io_uring (#402).
This crate also owns the other OS-facing unsafe the engine needs: shared-memory mappings
(SharedRegion), byte-range locks, thread pinning and NUMA binding (sys).
Part of Pigeonhole. See the crate README.
Re-exports§
pub use own::OwnIoWaker;pub use own::in_inline_io;pub use own::inline_io;pub use own::own_io_fd;pub use own::own_io_in_flight;pub use own::own_io_waker;pub use own::reap_orphan_io;pub use own::reap_own_io;
Modules§
- pread
- The
preadthread-pool backend: real files on every platform, the safe reference. - sim
- The simulated backend: in-memory files and shared memory, deterministic from a seed, with
fault injection.
pigeonhole-simbuilds its scheduler, crash points and model on top. - sys
- Thread placement: CPU pinning and topology. Lives here because it needs
unsafeFFI and this is one of the three crates allowed it. - uring
- The io_uring backend (Linux, #402): real files whose submitted I/O goes through an io_uring ring instead of a thread pool.
Structs§
- BufPool
- A bounded pool of heap
IoBufs (ICR 0026): a buffer taken from it goes back when it is dropped, wherever that happens, unless the pool is full. A reader that decodes block after block reuses a few allocations instead of allocating and zero-filling one per block (#372). - Completion
- The pending result of a submitted operation: a read or write (resolving to its buffer),
a sync (resolving to
()), or a higher-level operation built on them (a WAL group sync resolving to anLsn, a root commit). - Error
- An I/O error: a kind for branching, a static context and the OS error if any.
- File
Identity - Device and inode of a file: the same on every process however the path is spelled.
- IoBuf
- An owned, page-aligned (4096-byte) buffer for file I/O.
- IoCounters
- One database’s bytes read and written by its files since the counters were given to them.
- Open
Options - How to open a file.
- OwnIo
Waker - Interrupts its thread’s wait in
reap_own_io(an io_uring ring’s wait for completions, #402) from any thread: the scheduler’s wakeup for a shard thread that waits on its ring rather than parking. - Process
Id - A process as recorded in a reader slot: its id plus its start time, so a recycled pid is not mistaken for the original process.
- Resolver
- Resolves a
Completioncreated withCompletion::pair. - Ring
Stats - A backend’s io_uring rings now (
Vfs::ring_stats). - Shared
Region - A mapped shared-memory region (or a heap stand-in), cheap to clone.
Enums§
- Error
Kind - Broad classes of I/O failure that callers branch on.
- Locality
- The kind of filesystem a file lives on (
File::locality). - Lock
Mode - Mode of a byte-range lock.
- Shared
Open - How
Vfs::open_sharedtreats an existing region.
Traits§
- File
- An open file. Shared across threads; all methods take
&selfand use positional I/O. - Vfs
- The environment: files, shared memory, clocks and process liveness.
Functions§
- in_
inline_ io - Whether the calling thread is inside an
inline_ioscope. - inline_
io - Runs
fwith every operation the calling thread submits run inline, synchronously, on this thread (D284): never on a ring of its own (an io_uring thread ring is not used, nor is one attached), never on the backend’s shared ring or its I/O threads. On the real backends (io_uring andPreadVfs) each submitted operation has completed when itssubmit_*call returns, so whenfreturns nothing it submitted is in flight, whichever thread reaps what. - own_
io_ fd - A file descriptor that turns readable when the calling thread has completions to reap
(an io_uring ring’s registered eventfd, #408), for a thread that waits in its own event
loop (
poll,epoll) rather than inreap_own_io: wait until it is readable, then reap. Reaping resets it.Nonewhen the thread’s backends offer no such descriptor (the thread then has to reap again soon whileown_io_in_flightsays it has I/O in flight). - own_
io_ in_ flight - Whether the calling thread has submitted operations in flight that only it can complete
(by
reap_own_io). Alwaysfalseon backends whose completions arrive on other threads, such asPreadVfs. - own_
io_ waker - A handle that interrupts the calling thread’s waits in
reap_own_io, from the first of its backends that offers one (Nonewhen no backend’s wait can be interrupted: a scheduler then parks the thread as usual). - reap_
orphan_ io - Reaps every backend no thread reaps (the simulator under deferred I/O), waiting up to
waitfor something to complete: for a thread blocked on an outcome chained after I/O it holds no completion of, such as a WAL sync waiting for the stream’s older syncs (ICR 0028), which would otherwise wait for ever.Nonewhen no such backend is registered (one relaxed load: then wait as usual); otherwise whether anything completed. - reap_
own_ io - Completes the calling thread’s finished operations on every backend that leaves them to
it, waiting up to
waitfor one to finish when none has.Nonetakes only what has already finished, without waiting (a shard’s turn); the simulator’s device finishes its operations only for a thread that waits. Their completions resolve, and their continuations run, on this thread. Returns whether any completed.