Follow the work.
Both have read and write queues. What happens before, between, and after those queues is different.
01 / SEPARATE RINGSFeuer Independent read and write workers, optionally shared across cache files. Async I/O admission; best-effort background disk writes. Read queue · 64Read ring · 64 active Write queue · 8Write ring · 8 active 2 workers / 2 rings per queue setExplore the path →Close overview ↑
Lookup → memory → disk → callback
Memory misses read from disk when disk caching is enabled. Zero disk capacity skips disk and creates no I/O queues.
Read path
A memory miss joins or starts a shared in-flight fetch (keyed by object key hash and error type). If disk has the object, the fetch acquires payload-read admission and waits for an integrity-checked disk read.
Payload-read admission & fallthrough
PayloadReadQueue limits concurrent cached payload reads to 64 permits across all files sharing an IoQueues instance.
When waiting payload reads reach IoQueuesConfig::fallthrough_waiters (default 64, independent of the 64 active permits), all unchecked waiters are notified to evaluate their fallthrough predicate (such as get_or_fetch_with_disk_fallthrough) before starting any disk I/O.
Channel admission
A Tokio mpsc::channel(64) reserves waiting-channel capacity with reserve().await. A full channel yields the submitting task rather than blocking its executor thread.
Reserved capacity for preparing requests and queued requests share the channel's 64-position limit. The worker has 64 additional active slots. Channel capacity is freed as soon as the worker receives a request. Callers waiting to reserve are outside these counts and trigger write pacing while waiting.
There is no raw-I/O byte budget. A multi-MiB read reserves initial channel capacity before allocating its aligned buffer, then queues disjoint 1-MiB pieces concurrently into that allocation with fresh reservations. Request counts do not cap read-buffer memory.
Startup recovery reads metadata with blocking direct I/O outside these io_uring queues before the cache begins serving lookups.
Code · async channel reservation
feuer-storage/src/uring.rs · IoQueueHandle::reserve_channel_capacityself.sender
.as_ref()
.unwrap()
.reserve()
.await
.map_err(|_| queue_stopped_error())
feuer-storage/src/uring.rs · ReadQueue::read
Channel → active
Submission sends through the reserved channel permit without another admission wait, signals the worker's eventfd, and returns a oneshot reply receiver. Multi-piece reads submit all 1-MiB pieces before awaiting their replies.
The worker moves requests in channel order into io_uring's submission queue while the active request array has room. It discards requests whose callers canceled. When the array is full, requests stay in the channel. The array retains requests and their buffers through completion.
Code · enqueue and wake the worker
feuer-storage/src/uring.rs · IoQueueHandle::submit_requestlet (result_sender, result_receiver) = oneshot::channel();
permit.send(IoRequest::new(files, offset, buffers, buffer_range, result_sender));
wake_queue(&self.wake_fd);
result_receiver
Same file · queue_requests_for_submission
Verification → memory promotion
For a persisted entry, the disk cache reads and checksum-verifies the entire object without reading metadata or neighboring entries. Concurrent readers for the same object share one disk read and verification through a OnceCell. Hits still sitting in a shard's small-entry RAM buffer return a copy directly without any disk I/O.
Readers carry an address, length, and expected checksum rather than blocking disk reuse. If eviction reuses a chunk while a read is in flight, checksum verification catches the mismatch and turns it into a cache miss so the lookup can fall back to the source callback. I/O errors also become misses without removing the entry, while checksum mismatches remove the indexed entry. A disk hit never schedules another disk write.
Verified bytes pass through the optional memory admission filter and move into the memory cache by reusing the pooled AlignedBuffer without copying, charging its backing capacity against the memory target.
Disk-write queue
After a fetch (or explicit insert) passes the optional disk admission filter, Feuer queues a background disk write. DiskCache owns this queue above the raw write-I/O queue so lookups never block on SSD writeback.
Skip disk writes when full
Each cache's channel holds up to 512 queued entries. try_reserve() returns immediately, so a full or closed queue simply skips the disk write while the lookup succeeds.
Queued and active payload bytes are tracked by metrics, with no separate byte cap or memory-cache charge. The queue can keep a payload alive in RAM briefly even after its memory-cache entry is evicted.
Code · best-effort disk-write admission
feuer-storage/src/disk_cache/write_queue.rs · enqueue_if_space_available (excerpt)let permit = match self.write_sender.try_reserve() {
Ok(permit) => permit,
Err(error) => {
metrics.record_queue(match error {
TrySendError::Full(_) => DiskWriteQueueOutcome::Full,
TrySendError::Closed(_) => DiskWriteQueueOutcome::Closed,
});
return;
}
};
One worker, small-entry packing
SSDs perform better with large writes than scattered small ones, so each disk shard packs small objects (under 512 KiB after 4-KiB alignment) into a 1-MiB RAM buffer before writing. Larger objects bypass the buffer and write directly to consecutive whole 1-MiB chunks.
A shard's buffer flushes as a single 1-MiB write when it fills up, when the next small object does not fit, or after a 60-second timer. While objects sit in the RAM buffer, lookups can already serve them without disk I/O (briefly missing only while a chunk is mid-flush before publication). When a cache closes, the worker drains queued writes and discards any remaining partial buffers.
feuer-storage/src/disk_cache/write_queue.rs · background writes feuer-storage/src/disk_cache/small_entry_buffer.rs · buffering and timerPublish after payload writes finish
Entries are added to the in-memory disk index only after their payload bytes finish writing to disk. A separate background task persists dirty metadata pages once per second without fsync or shutdown flushes, keeping recovery fast and best-effort rather than crash-durable.
Written payload chunks are immutable. Once every entry in a chunk has been evicted from the index, the chunk immediately returns to the free list without waiting for in-flight readers or metadata writes. If an in-flight read overlaps with a reused chunk, payload checksum verification catches it and turns the read into a miss.
feuer-storage/src/disk_cache/writer.rs · payload then publication feuer-storage/src/allocation.rs · hold_chunks_until_payloads_released / release_payloadWrite-I/O queue
Same admission and worker machinery as reads, with its own channel, active slots, thread, and ring. All disk-cache shards share these queues, and multiple caches can share one IoQueues instance across files. When reads saturate the read queue, the write worker throttles new writes to protect read latency.
Throttling writes under read pressure
Heavy background writes compete with foreground reads inside the SSD and spike read tail latency. Whenever reads are waiting for read-channel capacity, the write worker switches from 8 concurrent writes to one write at a time and paces submissions at 1 GiB/s (charging each write's full byte length with no idle burst credit).
The throttle stays active for 100 ms after the last waiting read clears so bursts of reads stay protected, and restarts if reads back up again. Active writes already submitted finish normally, and pending writes stay in the write channel to apply backpressure upstream. With shared IoQueues, read pressure on any attached cache throttles writes across all of them.
Why eight active writes?
When reads are not backed up, active writes are capped at 8 with a separate 8-request waiting channel. On local NVMe, 1-MiB writes saturated near 1.83 GB/s at QD8. Raising depth to QD64 added no write-only throughput and raised write p99 from 4.6 to 47 ms while worsening small-read latency.
This is hardware/workload-specific evidence, not a universal optimal depth or a measurement of the current metadata-write pipeline.
experiments/ssd/uring-20260928/RESULT.mdCode · current limits
feuer-storage/src/uring.rs · request-size and active-slot limits (excerpt)pub(crate) const MAX_IO_REQUEST_BYTES: usize = 1024 * 1024;
const MAX_IN_FLIGHT_READS: usize = 64;
const MAX_IN_FLIGHT_WRITES: usize = 8;
Same file · IoQueueHandle::new
Two kinds of write pressure
Disk-write queue full: the lookup skips scheduling a disk copy.
Raw write channel full: the background work awaits a channel reservation. The successful lookup does not wait for that disk write.
Preparing and queued writes share eight channel positions, with up to eight more writes active. Shared queues apply these limits across all attached files, in arrival order without per-cache fairness. Each physical operation transfers at most 1 MiB, and input slices can share larger backing allocations. There is no byte-budget semaphore.
Independent caches, shared I/O
Passing clones of one IoQueues instance shares the read/write rings, payload-read permits, and pacing limits across multiple caches. Each cache still keeps its own contents, capacities, eviction, history, buffer pool, file lock, and 512-entry background-write queue.
Each queued or active I/O request retains its target file and lock through completion, including after caller cancellation. Idle queues retain no files, and returned bytes retain only RAM. Dropping one cache does not stop the others. The last queue owner drains submitted I/O and joins both workers.
feuer-storage/src/uring.rs · IoQueues / IoRequest feuer/examples/shared_io_objects.rs · shared queues and independent filesInside each I/O worker
Each direction has one thread owning its ring. Physical I/O requests are aligned to 4 KiB and at most 1 MiB. A logical cache read can queue multiple 1-MiB pieces concurrently.
Sleep without stalling new work
The loop collects completions, moves requests from the channel into io_uring's submission queue while the active request array has room, and submits. Interrupted and short submissions are retried before sleeping. Temporary resource pressure (EAGAIN) waits up to 1 ms before retrying, even if no accepted request can produce a completion. Once all prepared submissions have reached the kernel, it sleeps in poll watching both the ring and an eventfd.
New submissions signal the eventfd, so fresh work can wake the worker even while a slow operation is outstanding. Write pacing sets a poll timeout so admission resumes even when no request is active. Pending writes remain in the channel and preserve backpressure.
Code · wait for completion or wakeup
feuer-storage/src/uring.rs · wait_for_completion_or_wakeup (excerpt)let mut fds = [
libc::pollfd {
fd: self.ring.as_raw_fd(),
events: libc::POLLIN, revents: 0,
},
libc::pollfd {
fd: self.wake_fd.as_raw_fd(),
events: libc::POLLIN, revents: 0,
},
];
let result = unsafe {
libc::poll(fds.as_mut_ptr(), fds.len() as libc::nfds_t, timeout_millis)
};
Completion and cancellation
A completion identifies its active slot. Full completion sends buffers or an error through the request's oneshot channel and frees that active slot. Channel capacity was already released when the worker received the request.
- Still queued: requests whose reply receiver is closed are discarded when the worker receives them.
- Already active: buffers stay owned through completion, even if the caller has gone away.
- Interrupted or aligned short I/O: retry the remaining work. Invalid short completion becomes an error.
- Normal shutdown: drain outstanding work, then join the worker.
- Unrecoverable queue failure or thread unwind: retain uncertain active buffers, files, and locks until process exit. Closing the ring alone does not prove the kernel has stopped using them. Per-request error completions release resources normally.
Optional access-trace queue
with_trace(callback) adds a separate event queue shared by that handle and its clones. Lookups attempt to enqueue a start before fetching and an outcome before returning using try_send. Cancellation can leave an unmatched start. A full queue drops events rather than waiting, so trace delivery never delays lookups.
One worker delivers binary packages serially at 8 MiB or when all trace handles are dropped, with no timed delivery. Trace buffers are outside cache capacity. Receiver errors stop delivery without changing lookup results. Persistence and retries belong to the receiver. Dropping the last trace handle drains the tail asynchronously without waiting, so runtime shutdown can lose it.
access-trace.md · queue, delivery, and persistence contract feuer/src/access_trace.rs · AccessTrace
02 / SHARED RING PER SHARDFoyer
Separate input queues, one shared I/O budget per shard. A weighted scheduler chooses the next direction.
Read queueWrite queueShared ring
64 by default
1 worker / ring per shardExplore the path →Close overview ↑
Scope: Foyer's io_uring backend
Read & write input queues
Each worker receives two standard-library synchronous channels: one for reads, one for writes. Requests are routed by partition.id() % threads.
What happens when a channel fills?
Submission calls SyncSender::send before returning the asynchronous completion handle. If the channel is full, the calling thread can block until a worker receives an item.
Queue admission uses a synchronous send; completion is awaited asynchronously.
Code · channel capacity and synchronous send
foyer/foyer-storage/src/io/engine/uring.rs:188–200 (excerpt)// Created separately for reads and writes, per worker:
let (tx, rx) = mpsc::sync_channel(4096);
Same file:394 / 427 · read / write submission (excerpt)
let _ = shard.send(UringIoCtx {
tx,
io_type: UringIoType::Read,
rbuf,
addr,
// Optional tracing span omitted.
});
Waiting-channel and in-flight limits
The two channels can each hold 4,096 waiting requests. Separately, the ring limits combined in-flight reads and writes to the configured depth, 64 by default.
Like Feuer's waiting-channel limits, these capacities exclude operations already removed for submission. Feuer separately allows 64 active reads and 8 active writes; Foyer's active limit is shared between directions.
These request-count limits impose no payload-byte cap. Memory limits in Foyer's upper storage layers are outside this comparison's scope.
Weighted scheduler
One worker chooses between both input queues and submits to one ring. Reads and writes share the same in-flight limit.
How does it choose?
When read_inflight < write_inflight × weight, try reads first; otherwise try writes first. If the preferred channel is empty, try the other.
Default weight is 1.0. This is a target in-flight ratio—not a fixed 32/32 partition, a bandwidth guarantee, or preemption of already-submitted work.
Code · shared cap and direction selection
foyer/foyer-storage/src/io/engine/uring.rs:284–317 (condensed)if self.read_inflight + self.write_inflight
>= self.io_depth {
break 'prepare;
}
// Check the read queue first, then try the other queue as a fallback:
(self.read_inflight as f64)
< self.write_inflight as f64 * self.weight
What is configurable?
with_threads: number of workers/rings; default 1.with_io_depth: shared ring depth per worker; default 64.with_weight: desired read/write in-flight ratio; default 1.0.- CPU affinity, SQPOLL, and IOPOLL are also available. Both polling flags default to false.
Worker loop & completions
The worker tries to fill the ring, submits when there is in-flight work, drains completion entries, and repeats. The shown loop has no sleep or blocking wait when idle.
Worker-thread polling and kernel polling
This continuous loop runs in Foyer's worker thread even with SQPOLL and IOPOLL disabled. Those optional flags control separate kernel-side behavior.
Feuer instead blocks in poll until a ring completion or eventfd wakeup. That avoids idle spinning, but wakeup cost versus polling latency remains a measurement question.
Code · worker loop
foyer/foyer-storage/src/io/engine/uring.rs:283–365 (condensed)loop {
// Try both channels and prepare up to io_depth requests.
if self.read_inflight + self.write_inflight > 0 {
self.uring.submit().unwrap();
}
for cqe in self.uring.completion() {
// Decrement the direction's in-flight count.
// Send the result through the request's oneshot.
}
// Repeat immediately without sleeping.
}
Returning to the caller
Completion data identifies the request context. The worker decrements the appropriate in-flight counter and sends its result through a oneshot channel.
The caller's asynchronous I/O handle awaits that channel and returns the buffer with the result. Read and write requests use separate completion channels and share one ring per shard.
foyer/foyer-storage/src/io/engine/uring.rs:344–362 · completions Same file:403–412 · caller awaits replyWhere does pressure go?Disk-write, raw-I/O, and optional tracing admission.
| Boundary | When full | Who pays? |
|---|---|---|
| Feuer payload-read admission | Await permit, or fall through at threshold | Foreground disk reads wait for one of 64 permits. At fallthrough_waiters (default 64) waiting reads, eligible callers can fall through to the source callback before any disk I/O. |
| Feuer write throttling | Drop to QD1 at 1 GiB/s | When reads wait for read-channel capacity (plus a 100 ms hold after), new writes serialize one at a time at 1 GiB/s to protect foreground read latency. |
| Feuer disk-write queue | Skip the disk copy | The cache skips a disk write. The successful lookup continues. |
| Feuer raw I/O | Await channel reservation | The submitting task waits: foreground on reads, background for disk-cache writes. Startup recovery uses blocking direct I/O outside these queues. |
| Feuer access-trace queue | Drop the event | try_send drops the event when all 262,144 slots are full. Slow trace delivery never delays lookups. |
| Foyer io_uring input | Blocking channel send | The calling thread can wait for channel space. Later completion is awaited asynchronously. |
Feuer's separate read and write rings compete for the same SSD. Foyer's shared ring offers configurable weighted scheduling. Neither topology alone proves better throughput or latency.