MCPcopy Create free account
hub / github.com/axboe/liburing / init_ring

Function init_ring

examples/proxy.c:2137–2289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2135}
2136
2137static int init_ring(struct io_uring *ring, int nr_files)
2138{
2139 struct io_uring_params params;
2140 int ret;
2141
2142 /*
2143 * By default, set us up with a big CQ ring. Not strictly needed
2144 * here, but it's very important to never overflow the CQ ring.
2145 * Events will not be dropped if this happens, but it does slow
2146 * the application down in dealing with overflown events.
2147 *
2148 * Set SINGLE_ISSUER, which tells the kernel that only one thread
2149 * is doing IO submissions. This enables certain optimizations in
2150 * the kernel.
2151 */
2152 memset(&params, 0, sizeof(params));
2153 params.flags |= IORING_SETUP_SINGLE_ISSUER | IORING_SETUP_CLAMP;
2154 params.flags |= IORING_SETUP_CQSIZE;
2155 params.cq_entries = 1024;
2156
2157 /*
2158 * If use_huge is set, setup the ring with IORING_SETUP_NO_MMAP. This
2159 * means that the application allocates the memory for the ring, and
2160 * the kernel maps it. The alternative is having the kernel allocate
2161 * the memory, and then liburing will mmap it. But we can't really
2162 * support huge pages that way. If this fails, then ensure that the
2163 * system has huge pages set aside upfront.
2164 */
2165 if (use_huge)
2166 params.flags |= IORING_SETUP_NO_MMAP;
2167
2168 /*
2169 * DEFER_TASKRUN decouples async event reaping and retrying from
2170 * regular system calls. If this isn't set, then io_uring uses
2171 * normal task_work for this. task_work is always being run on any
2172 * exit to userspace. Real applications do more than just call IO
2173 * related system calls, and hence we can be running this work way
2174 * too often. Using DEFER_TASKRUN defers any task_work running to
2175 * when the application enters the kernel anyway to wait on new
2176 * events. It's generally the preferred and recommended way to setup
2177 * a ring.
2178 */
2179 if (defer_tw) {
2180 params.flags |= IORING_SETUP_DEFER_TASKRUN;
2181 sqpoll = 0;
2182 }
2183
2184 /*
2185 * SQPOLL offloads any request submission and retry operations to a
2186 * dedicated thread. This enables an application to do IO without
2187 * ever having to enter the kernel itself. The SQPOLL thread will
2188 * stay busy as long as there's work to do, and go to sleep if
2189 * sq_thread_idle msecs have passed. If it's running, submitting new
2190 * IO just needs to make them visible to the SQPOLL thread, it needs
2191 * not enter the kernel. For submission, the application will only
2192 * enter the kernel if the SQPOLL has been idle long enough that it
2193 * has gone to sleep.
2194 *

Callers 2

thread_mainFunction · 0.85
mainFunction · 0.85

Calls 4

io_uring_register_napiFunction · 0.85

Tested by

no test coverage detected