# \[PITCH\] io\_uring support in Swift System on Linux

**URL:** <https://forums.swift.org/t/pitch-io-uring-support-in-swift-system-on-linux/78340>\
**Category:** Pitches\
**Tags:** linux, server, io, swift-system\
**Created:** [March 6, 2025, 8:23pm UTC](https://forums.swift.org/t/pitch-io-uring-support-in-swift-system-on-linux/78340 "2025-03-06T20:23:06Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![lukeh](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lukeh/32/31648_2.png) [@lukeh](https://forums.swift.org/u/lukeh)\
**Post date:** [March 7, 2025, 8:28pm UTC](https://forums.swift.org/t/pitch-io-uring-support-in-swift-system-on-linux/78340/17 "2025-03-07T20:28:47Z")

</div>

> [@ktoso](#):
>
> Very nice to see this, it'll be nice to have a Swift wrapper around the io\_uring APIs!

[IORingSwift](https://github.com/PADL/IORingSwift) has been around for a couple of years now ;) We're using it in our embedded audio product for UART, SPI and I2C as well as socket and file I/O.

Public API provides structured concurrency wrappers around common operations such as reading and writing. Multishot APIs, such as `accept(2)`, which can return multiple completions over time return an `AnyAsyncSequence`. Internally, wrappers allocate a concrete instance of `Submission<T>`, representing an initialized Submission Queue Entry (SQE), which is then submitted to the `io_uring`. Completion handlers are handled by having `libdispatch` monitor an `eventfd(2)` representing available completions. The `user_data` in each queue entry is a block, which executes the `onCompletion(cqe:)` method of the `Submission<T>` instance in the ring's isolated context.

```swift
let clients: AnyAsyncSequence<Socket> = try await socket.accept()
for try await client in clients {
    Task {
        repeat {
            let data = try await client.receive(count: bufferSize)
            try await client.send(data)
        } while true
    }
}

```

Plenty of other examples [here](https://github.com/PADL/IORingSwift/tree/main/Examples). Original discussion [here](https://forums.swift.org/t/blocking-i-o-and-concurrency/67276).

Things I would do differently? The use of classes does cause a lot of allocations (although this hasn't been a bottleneck for us). And, [SE-0461](https://forums.swift.org/t/se-0461-run-nonisolated-async-functions-on-the-callers-actor-by-default/77987) will make it easier to avoid the global actor.

---

_[View the full topic](https://forums.swift.org/t/pitch-io-uring-support-in-swift-system-on-linux/78340)._
