Categorygithub.com/ImVexed/iouring-go
modulepackage
0.0.0-20200507181224-8929d841ba1a
Repository: https://github.com/imvexed/iouring-go.git
Documentation: pkg.go.dev

# README

io_uring Go

WORK IN PROGRESS This library adds support for io_uring for Go. This library is similar to liburing. If you want to contribute feel free to send PRs or emails, there's plenty of things that need cleaned up.

General Steps

  1. Create the io_uring buffers
  2. Setup mmap for both ring buffers
  3. Submit requests, this is done through another system call.

Interacting with the Submit/Completion Queues

The submission and completion queues are both mmap'd as slices, the question then becomes how to design an efficient API that is also able to interact with many of the standard library interfaces. One choice is to run a background goroutine that manages all operations with the queues and use channels for enqueuing requests. The downside of this approach is that are outstanding issues with the design of channels may make it suboptimal for high throughput IO.

liburing uses memory barriers for interacting appropriately with the submission/completion queues of io_uring. One problem with the memory model of Go is that it uses weak atomics which can make it difficult to use sync/atomic in all situations. If certain IO operations are to be carriered out in a specific order then this becomes a real challenge.

The current approach is to use a FSM that uses atomics for synchronization. Once a ring is "filled" (no writes occuring to any memory locations in the mmap'd sumission queue) then the ring may be submitted. This design is not final and this library is far from ready for general use.

ring states

Example

Here is a minimal example to get started:

package main

import (
	"log"
	"os"

	"github.com/hodgesds/iouring-go"
)

func main() {
	r, err := iouring.New(1024)
	if err != nil {
		log.Fatal(err)
	}

	// Open a file for registring with the ring.
	f, err := os.OpenFile("hello.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
	if err != nil {
		log.Fatal(err)
	}

	// Register the file with the ring, which returns an io.WriteCloser.
	rw, err := r.FileReadWriter(f)
	if err != nil {
		log.Fatal(err)
	}

	if _, err := rw.Write([]byte("hello io_uring!")); err != nil {
		log.Fatal(err)
	}
}

Other References

https://cor3ntin.github.io/posts/iouring/

https://github.com/google/vectorio

https://github.com/shuveb/io_uring-by-example/blob/master/02_cat_uring/main.c

https://golang.org/pkg/syscall/#Iovec

# Packages

No description provided by the author

# Functions

Enter is used to submit to the queue.
MmapRing is used to configure the submit and completion queues, it should only be called after the Setup function has completed successfully.
New is used to create an iouring.Ring.
NewFileRegistry returns a configured file regisry for a ring.
RegisterFiles is used to register files to a ring.
ReregisterFiles is used to reregister files to a ring.
Setup is used to setup a io_uring using the io_uring_setup syscall.
UnregisterFiles is used to unregister files to a ring.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CqRingOffset is the offset of the completion queue.
EnterGetEvents ...
EnterSqWakeup ...
EnterSyscall defines the syscall number for io_uring_enter.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
* io_uring_params->features flags */.
No description provided by the author
No description provided by the author
No description provided by the author
FsyncDatasync ...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RegisterSyscall defines the syscall number for io_uring_register.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RingStateEmpty is when a ring is empty.
RingStateFilled is when a ring is filled and ready to be updated or entered.
RingStateUpdating is when a ring is preparing to be entered.
RingStateWriting is when a ring is being written to.
No description provided by the author
No description provided by the author
SetupAttachWq attach to existing wq.
SetupClamp clamp SQ/CQ ring sizes.
SetupCqSize app defines CQ size.
SetupIOPoll io_context is polled.
SetupSQAFF sq_thread_cpu is valid.
SetupSQPoll SQ poll thread.
SetupSyscall defines the syscall number for io_uring_setup.
No description provided by the author
SqeAsync is use to specify async io.
No description provided by the author
SqeBufferSelect is used to specify buffer select.
No description provided by the author
SqeFixedFile use fixed fileset.
* sqe->flags */.
SqeIoDrain issue after inflight IO.
No description provided by the author
SqeIoHardlink is a hard link to multiple SQEs.
No description provided by the author
SqeLink is used to link multiple SQEs.
No description provided by the author
SqeRingOffset is the offset of the submission queue entries.
SqNeedWakeup needs io_uring_enter wakeup.
SqRingOffset is the offset of the submission queue.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

CompletionEntry IO completion data structure (Completion Queue Entry).
CompletionQueue represents the completion queue ring buffer.
CQRingOffset describes the various completion queue offsets.
KernelTimespec is a kernel timespec.
Params are used to configured a io uring.
Ring contains an io_uring submit and completion ring.
SQRingOffset describes the various submit queue offsets.
SubmitEntry is an IO submission data structure (Submission Queue Entry).
SubmitQueue represents the submit queue ring buffer.

# Interfaces

FileRegistry is used to register files to a ring.
ReadWriteAtCloser supports reading, writing, and closing.
ReadWriteSeekerCloser is a ReadWriteCloser and ReadWriteSeeker.

# Type aliases

Opcode is an opcode for the ring.