History

Merge tag 'io_uring-2019-03-06' of git://git.kernel.dk/linux-block

Pull io_uring IO interface from Jens Axboe: "Second attempt at adding the io_uring interface. Since the first one, we've added basic unit testing of the three system calls, that resides in liburing like the other unit tests that we have so far. It'll take a while to get full coverage of it, but we're working towards it. I've also added two basic test programs to tools/io_uring. One uses the raw interface and has support for all the various features that io_uring supports outside of standard IO, like fixed files, fixed IO buffers, and polled IO. The other uses the liburing API, and is a simplified version of cp(1). This adds support for a new IO interface, io_uring. io_uring allows an application to communicate with the kernel through two rings, the submission queue (SQ) and completion queue (CQ) ring. This allows for very efficient handling of IOs, see the v5 posting for some basic numbers: https://lore.kernel.org/linux-block/20190116175003.17880-1-axboe@kernel.dk/ Outside of just efficiency, the interface is also flexible and extendable, and allows for future use cases like the upcoming NVMe key-value store API, networked IO, and so on. It also supports async buffered IO, something that we've always failed to support in the kernel. Outside of basic IO features, it supports async polled IO as well. This particular feature has already been tested at Facebook months ago for flash storage boxes, with 25-33% improvements. It makes polled IO actually useful for real world use cases, where even basic flash sees a nice win in terms of efficiency, latency, and performance. These boxes were IOPS bound before, now they are not. This series adds three new system calls. One for setting up an io_uring instance (io_uring_setup(2)), one for submitting/completing IO (io_uring_enter(2)), and one for aux functions like registrating file sets, buffers, etc (io_uring_register(2)). Through the help of Arnd, I've coordinated the syscall numbers so merge on that front should be painless. Jon did a writeup of the interface a while back, which (except for minor details that have been tweaked) is still accurate. Find that here: https://lwn.net/Articles/776703/ Huge thanks to Al Viro for helping getting the reference cycle code correct, and to Jann Horn for his extensive reviews focused on both security and bugs in general. There's a userspace library that provides basic functionality for applications that don't need or want to care about how to fiddle with the rings directly. It has helpers to allow applications to easily set up an io_uring instance, and submit/complete IO through it without knowing about the intricacies of the rings. It also includes man pages (thanks to Jeff Moyer), and will continue to grow support helper functions and features as time progresses. Find it here: git://git.kernel.dk/liburing Fio has full support for the raw interface, both in the form of an IO engine (io_uring), but also with a small test application (t/io_uring) that can exercise and benchmark the interface" * tag 'io_uring-2019-03-06' of git://git.kernel.dk/linux-block: io_uring: add a few test tools io_uring: allow workqueue item to handle multiple buffered requests io_uring: add support for IORING_OP_POLL io_uring: add io_kiocb ref count io_uring: add submission polling io_uring: add file set registration net: split out functions related to registering inflight socket files io_uring: add support for pre-mapped user IO buffers block: implement bio helper to add iter bvec pages to bio io_uring: batch io_kiocb allocation io_uring: use fget/fput_many() for file references fs: add fget_many() and fput_many() io_uring: support for IO polling io_uring: add fsync support Add io_uring IO interface

Linus Torvalds committed 7 years ago

Commit 38e75712 parents 80201fe 21b4aa532 files · +4783 −146Browse files

Showing the changes to include/uapi/linux (1 of 32 files). Show all

Unified · Split

include/uapi/linux/io_uring.h+137−0
@@ -0,0 +1,137 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Header file for the io_uring interface.
4 *
5 * Copyright (C) 2019 Jens Axboe
6 * Copyright (C) 2019 Christoph Hellwig
7 */
8#ifndef LINUX_IO_URING_H
9#define LINUX_IO_URING_H
10
11#include <linux/fs.h>
12#include <linux/types.h>
13
14/*
15 * IO submission data structure (Submission Queue Entry)
16 */
17struct io_uring_sqe {
18 __u8 opcode; /* type of operation for this sqe */
19 __u8 flags; /* IOSQE_ flags */
20 __u16 ioprio; /* ioprio for the request */
21 __s32 fd; /* file descriptor to do IO on */
22 __u64 off; /* offset into file */
23 __u64 addr; /* pointer to buffer or iovecs */
24 __u32 len; /* buffer size or number of iovecs */
25 union {
26 __kernel_rwf_t rw_flags;
27 __u32 fsync_flags;
28 __u16 poll_events;
29 };
30 __u64 user_data; /* data to be passed back at completion time */
31 union {
32 __u16 buf_index; /* index into fixed buffers, if used */
33 __u64 __pad2[3];
34 };
35};
36
37/*
38 * sqe->flags
39 */
40#define IOSQE_FIXED_FILE (1U << 0) /* use fixed fileset */
41
42/*
43 * io_uring_setup() flags
44 */
45#define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */
46#define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */
47#define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */
48
49#define IORING_OP_NOP 0
50#define IORING_OP_READV 1
51#define IORING_OP_WRITEV 2
52#define IORING_OP_FSYNC 3
53#define IORING_OP_READ_FIXED 4
54#define IORING_OP_WRITE_FIXED 5
55#define IORING_OP_POLL_ADD 6
56#define IORING_OP_POLL_REMOVE 7
57
58/*
59 * sqe->fsync_flags
60 */
61#define IORING_FSYNC_DATASYNC (1U << 0)
62
63/*
64 * IO completion data structure (Completion Queue Entry)
65 */
66struct io_uring_cqe {
67 __u64 user_data; /* sqe->data submission passed back */
68 __s32 res; /* result code for this event */
69 __u32 flags;
70};
71
72/*
73 * Magic offsets for the application to mmap the data it needs
74 */
75#define IORING_OFF_SQ_RING 0ULL
76#define IORING_OFF_CQ_RING 0x8000000ULL
77#define IORING_OFF_SQES 0x10000000ULL
78
79/*
80 * Filled with the offset for mmap(2)
81 */
82struct io_sqring_offsets {
83 __u32 head;
84 __u32 tail;
85 __u32 ring_mask;
86 __u32 ring_entries;
87 __u32 flags;
88 __u32 dropped;
89 __u32 array;
90 __u32 resv1;
91 __u64 resv2;
92};
93
94/*
95 * sq_ring->flags
96 */
97#define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */
98
99struct io_cqring_offsets {
100 __u32 head;
101 __u32 tail;
102 __u32 ring_mask;
103 __u32 ring_entries;
104 __u32 overflow;
105 __u32 cqes;
106 __u64 resv[2];
107};
108
109/*
110 * io_uring_enter(2) flags
111 */
112#define IORING_ENTER_GETEVENTS (1U << 0)
113#define IORING_ENTER_SQ_WAKEUP (1U << 1)
114
115/*
116 * Passed in for io_uring_setup(2). Copied back with updated info on success
117 */
118struct io_uring_params {
119 __u32 sq_entries;
120 __u32 cq_entries;
121 __u32 flags;
122 __u32 sq_thread_cpu;
123 __u32 sq_thread_idle;
124 __u32 resv[5];
125 struct io_sqring_offsets sq_off;
126 struct io_cqring_offsets cq_off;
127};
128
129/*
130 * io_uring_register(2) opcodes and arguments
131 */
132#define IORING_REGISTER_BUFFERS 0
133#define IORING_UNREGISTER_BUFFERS 1
134#define IORING_REGISTER_FILES 2
135#define IORING_UNREGISTER_FILES 3
136
137#endif