---
name: "io_uring_setup"
section: "2"
platform: "linux"
package: "liburing"
version: "2.15-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/io_uring_setup"
---

# io\_uring\_setup(2)

setup a context for performing asynchronous I/O

## NAME

io\_uring\_setup - setup a context for performing asynchronous I/O

## SYNOPSIS

```
#include <liburing.h>
```

**int io\_uring\_setup(u32** *entries***, struct io\_uring\_params \****params***);**

## DESCRIPTION

The [**io\_uring\_setup**(2)](/io_uring_setup/2.md) system call sets up a submission queue (SQ) and completion queue (CQ) with at least *entries* entries, and returns a file descriptor which can be used to perform subsequent operations on the io\_uring instance. The submission and completion queues are shared between userspace and the kernel, which eliminates the need to copy data when initiating and completing I/O.

*params* is used by the application to pass options to the kernel, and by the kernel to convey information about the ring buffers.

```
struct io_uring_params {
    __u32 sq_entries;
    __u32 cq_entries;
    __u32 flags;
    __u32 sq_thread_cpu;
    __u32 sq_thread_idle;
    __u32 features;
    __u32 wq_fd;
    __u32 resv[3];
    struct io_sqring_offsets sq_off;
    struct io_cqring_offsets cq_off;
};
```

The *flags*, *sq\_thread\_cpu*, and *sq\_thread\_idle* fields are used to configure the io\_uring instance. *flags* is a bit mask of 0 or more of the following values ORed together:

- **IORING\_SETUP\_IOPOLL**

  Perform busy-waiting for an I/O completion, as opposed to getting notifications via an asynchronous IRQ (Interrupt Request). The file system (if any) and block device must support polling in order for this to work. Busy-waiting provides lower latency, but may consume more CPU resources than interrupt driven I/O. Currently, this feature is usable only on a file descriptor opened using the **O\_DIRECT** flag (if using the **IORING\_OP\_{READ,WRITE}(V)(\_FIXED)** opcodes). When a read or write is submitted to a polled context, the application must poll for completions on the CQ ring by calling [**io\_uring\_enter**(2)](/io_uring_enter/2.md). Most non-polled I/O requests are forbidden on **IORING\_SETUP\_IOPOLL** io\_uring instances (see [**io\_uring\_setup\_flags**(7)](/io_uring_setup_flags/7.md) for the allowed opcodes).

  This is only applicable for storage devices for now, and the storage device must be configured for polling. How to do that depends on the device type in question. For NVMe devices, the nvme driver must be loaded with the *poll\_queues* parameter set to the desired number of polling queues. The polling queues will be shared appropriately between the CPUs in the system, if the number is less than the number of online CPU threads.

- **IORING\_SETUP\_HYBRID\_IOPOLL**

  This flag must be used with **IORING\_SETUP\_IOPOLL** flag. Hybrid io polling is a feature based on iopoll, it differs from strict polling in that it will delay a bit before doing completion side polling, to avoid wasting too much CPU resources. Like **IOPOLL** , it requires that devices support polling.

- **IORING\_SETUP\_SQPOLL**

  When this flag is specified, a kernel thread is created to perform submission queue polling. An io\_uring instance configured in this way enables an application to issue I/O without ever context switching into the kernel. By using the submission queue to fill in new submission queue entries and watching for completions on the completion queue, the application can submit and reap I/Os without doing a single system call.

  If the kernel thread is idle for more than *sq\_thread\_idle* milliseconds, it will set the **IORING\_SQ\_NEED\_WAKEUP** bit in the *flags* field of the *struct io\_sq\_ring*. When this happens, the application must call [**io\_uring\_enter**(2)](/io_uring_enter/2.md) to wake the kernel thread. If I/O is kept busy, the kernel thread will never sleep. An application making use of this feature will need to guard the [**io\_uring\_enter**(2)](/io_uring_enter/2.md) call with the following code sequence:

  ```
  /*
   * Ensure that the wakeup flag is read after the tail pointer
   * has been written. It's important to use memory load acquire
   * semantics for the flags read, as otherwise the application
   * and the kernel might not agree on the consistency of the
   * wakeup flag.
   */
  unsigned flags = atomic_load_relaxed(sq_ring->flags);
  if (flags & IORING_SQ_NEED_WAKEUP)
      io_uring_enter(fd, 0, 0, IORING_ENTER_SQ_WAKEUP);
  ```

  where *sq\_ring* is a submission queue ring setup using the *struct io\_sqring\_offsets* described below.

- Note that, when using a ring setup with

  **IORING\_SETUP\_SQPOLL**, you never directly call the [**io\_uring\_enter**(2)](/io_uring_enter/2.md) system call. That is usually taken care of by liburing's [**io\_uring\_submit**(3)](/io_uring_submit/3.md) function. It automatically determines if you are using polling mode or not and deals with when your program needs to call [**io\_uring\_enter**(2)](/io_uring_enter/2.md) without you having to bother about it.

- Note that while this may sound immediately appealing

  as an automatic "go faster" flag, evaluations should be done on a case-by-case basis to check if it makes sense for the application.

- Before version 5.11 of the Linux kernel, to successfully use this feature, the

  application must register a set of files to be used for IO through [**io\_uring\_register**(2)](/io_uring_register/2.md) using the **IORING\_REGISTER\_FILES** opcode. Failure to do so will result in submitted IO being errored with **EBADF**. The presence of this feature can be detected by the **IORING\_FEAT\_SQPOLL\_NONFIXED** feature flag. In version 5.11 and later, it is no longer necessary to register files to use this feature. 5.11 also allows using this as non-root, if the user has the **CAP\_SYS\_NICE** capability. In 5.13 this requirement was also relaxed, and no special privileges are needed for SQPOLL in newer kernels. Certain stable kernels older than 5.13 may also support unprivileged SQPOLL.

- **IORING\_SETUP\_SQ\_AFF**

  If this flag is specified, then the poll thread will be bound to the cpu set in the *sq\_thread\_cpu* field of the *struct io\_uring\_params*. This flag is only meaningful when **IORING\_SETUP\_SQPOLL** is specified. When cgroup setting *cpuset.cpus* changes (typically in container environment), the bounded cpu set may be changed as well.

- **IORING\_SETUP\_CQSIZE**

  Create the completion queue with *struct io\_uring\_params.cq\_entries* entries. The value must be greater than *entries*, and may be rounded up to the next power-of-two.

- **IORING\_SETUP\_CLAMP**

  If this flag is specified, and if *entries* exceeds **IORING\_MAX\_ENTRIES**, then *entries* will be clamped at **IORING\_MAX\_ENTRIES**. If the flag **IORING\_SETUP\_CQSIZE** is set, and if the value of *struct io\_uring\_params.cq\_entries* exceeds **IORING\_MAX\_CQ\_ENTRIES**, then it will be clamped at **IORING\_MAX\_CQ\_ENTRIES**.

- **IORING\_SETUP\_ATTACH\_WQ**

  This flag should be set in conjunction with *struct io\_uring\_params.wq\_fd* being set to an existing io\_uring ring file descriptor. When set, the io\_uring instance being created will share the asynchronous worker thread backend of the specified io\_uring ring, rather than create a new separate thread pool. Additionally the sq polling thread will be shared, if **IORING\_SETUP\_SQPOLL** is set.

- **IORING\_SETUP\_R\_DISABLED**

  If this flag is specified, the io\_uring ring starts in a disabled state. In this state, restrictions can be registered, but submissions are not allowed. See [**io\_uring\_register**(2)](/io_uring_register/2.md) for details on how to enable the ring. Available since 5.10.

- **IORING\_SETUP\_SUBMIT\_ALL**

  Normally io\_uring stops submitting a batch of requests, if one of these requests results in an error. This can cause submission of less than what is expected, if a request ends in error while being submitted. If the ring is created with this flag, [**io\_uring\_enter**(2)](/io_uring_enter/2.md) will continue submitting requests even if it encounters an error submitting a request. CQEs are still posted for errored request regardless of whether or not this flag is set at ring creation time, the only difference is if the submit sequence is halted or continued when an error is observed. Available since 5.18.

- **IORING\_SETUP\_COOP\_TASKRUN**

  By default, io\_uring will interrupt a task running in userspace when a completion event comes in. This is to ensure that completions run in a timely manner. For a lot of use cases, this is overkill and can cause reduced performance from both the inter-processor interrupt used to do this, the kernel/user transition, the needless interruption of the tasks userspace activities, and reduced batching if completions come in at a rapid rate. Most applications don't need the forceful interruption, as the events are processed at any kernel/user transition. The exception are setups where the application uses multiple threads operating on the same ring, where the application waiting on completions isn't the one that submitted them. For most other use cases, setting this flag will improve performance. Available since 5.19.

- **IORING\_SETUP\_TASKRUN\_FLAG**

  Used in conjunction with **IORING\_SETUP\_COOP\_TASKRUN** or **IORING\_SETUP\_DEFER\_TASKRUN**, this provides a flag, **IORING\_SQ\_TASKRUN**, which is set in the SQ ring *flags* whenever completions are pending that should be processed. liburing will check for this flag even when doing [**io\_uring\_peek\_cqe**(3)](/io_uring_peek_cqe/3.md) and enter the kernel to process them, and applications can do the same. This makes **IORING\_SETUP\_TASKRUN\_FLAG** safe to use even when applications rely on a peek style operation on the CQ ring to see if anything might be pending to reap. Available since 5.19.

- **IORING\_SETUP\_SQE128**

  If set, io\_uring will use 128-byte SQEs rather than the normal 64-byte sized variant. This is a requirement for using certain request types, as of 5.19 only the **IORING\_OP\_URING\_CMD** passthrough command for NVMe passthrough needs this. Available since 5.19.

- **IORING\_SETUP\_CQE32**

  If set, io\_uring will use 32-byte CQEs rather than the normal 16-byte sized variant. This is a requirement for using certain request types, as of 5.19 only the **IORING\_OP\_URING\_CMD** passthrough command for NVMe passthrough needs this. Also see **IORING\_SETUP\_CQE\_MIXED** for an alternative to this flag. Available since 5.19.

- **IORING\_SETUP\_SINGLE\_ISSUER**

  A hint to the kernel that only a single task (or thread) will submit requests, which is used for internal optimisations. The submission task is either the task that created the ring, or if **IORING\_SETUP\_R\_DISABLED** is specified then it is the task that enables the ring through [**io\_uring\_register**(2)](/io_uring_register/2.md)**.** The kernel enforces this rule, failing requests with **-EEXIST** if the restriction is violated. Note that when **IORING\_SETUP\_SQPOLL** is set it is considered that the polling task is doing all submissions on behalf of the userspace and so it always complies with the rule disregarding how many userspace tasks do [**io\_uring\_enter**(2)](/io_uring_enter/2.md). Available since 6.0.

- **IORING\_SETUP\_DEFER\_TASKRUN**

  By default, io\_uring will process all outstanding work at the end of any system call or thread interrupt. This can delay the application from making other progress. Setting this flag will hint to io\_uring that it should defer work until an [**io\_uring\_enter**(2)](/io_uring_enter/2.md) call with the  **IORING\_ENTER\_GETEVENTS** flag set. This allows the application to request work to run just before it wants to process completions. This flag requires the **IORING\_SETUP\_SINGLE\_ISSUER** flag to be set, and also enforces that the call to [**io\_uring\_enter**(2)](/io_uring_enter/2.md) is called from the same thread that submitted requests. Note that if this flag is set then it is the application's responsibility to periodically trigger work (for example via any of the CQE waiting functions) or else completions may not be delivered. Available since 6.1.

- **IORING\_SETUP\_NO\_MMAP**

  By default, io\_uring allocates kernel memory that callers must subsequently [**mmap**(2)](/mmap/2.md). If this flag is set, io\_uring instead uses caller-allocated buffers; *p-\>cq\_off.user\_addr* must point to the memory for the sq/cq rings, and *p-\>sq\_off.user\_addr* must point to the memory for the sqes. Each allocation must be contiguous memory. Typically, callers should allocate this memory by using [**mmap**(2)](/mmap/2.md) to allocate a huge page. If this flag is set, a subsequent attempt to [**mmap**(2)](/mmap/2.md) the io\_uring file descriptor will fail. Available since 6.5.

- **IORING\_SETUP\_REGISTERED\_FD\_ONLY**

  If this flag is set, io\_uring will register the ring file descriptor, and return the registered descriptor index, without ever allocating an unregistered file descriptor. The caller will need to use **IORING\_REGISTER\_USE\_REGISTERED\_RING** when calling [**io\_uring\_register**(2)](/io_uring_register/2.md). This flag only makes sense when used alongside with **IORING\_SETUP\_NO\_MMAP**, which also needs to be set. Available since 6.5.

- **IORING\_SETUP\_NO\_SQARRAY**

  If this flag is set, entries in the submission queue will be submitted in order, wrapping around to the first entry after reaching the end of the queue. In other words, there will be no more indirection via the array of submission entries, and the queue will be indexed directly by the submission queue tail and the range of indexed represented by it modulo queue size. Subsequently, the user should not map the array of submission queue entries, and the corresponding offset in *struct io\_sqring\_offsets* will be set to zero. Available since 6.6.

- **IORING\_SETUP\_CQE\_MIXED**

  If this flag is set, the ring supports posting both the normal 16b sized CQEs as well as the larger 32b CQEs. Normally a ring is setup to only allow posting of normal 16b CQEs, or if **IORING\_SETUP\_CQE32** has been set, only 32b CQEs. With this flag, the kernel may post both types. If a 32b CQE is posted, the CQE *flags* member will have **IORING\_CQE\_F\_32** set to indicate that this CQE is of the larger type. The kernel may also set **IORING\_CQE\_F\_SKIP** in the CQE *flags* member, in case it needs to post a filler 16b CQE. This will happen if a 32b CQE needs posting and the current CQ ring offset is such that the 32b CQE would wrap around. Applications should simply skip/ignore such CQEs, they contain no information and serve only as placeholder to facilitate advancing the CQ ring such that a large CQE can get posted. The use case of the **IORING\_SETUP\_CQE\_MIXED** flag is to allow more efficient setups of workloads that may post both normal and large CQEs. Opcodes that previously required the use of **IORING\_SETUP\_CQE32** may now use this flag instead, and potentially save some memory for the CQ ring. If used with liburing 2.12 or newer, the handling of variably sized CQEs is fully transparent. Available since 6.18.

- **IORING\_SETUP\_SQ\_REWIND**

  If this flag is set, the kernel ignores the submission queue head and tail and instead fetches SQEs starting from index 0. The application places all SQEs at the beginning of the SQ ring before each submit call, and the *sq\_entries* parameter to [**io\_uring\_enter**(2)](/io_uring_enter/2.md) determines how many SQEs are submitted. This is a non-circular queue mode where the kernel always starts from the beginning.

This flag requires **IORING\_SETUP\_NO\_SQARRAY** to be set. It is not compatible with **IORING\_SETUP\_SQPOLL**.

This mode helps keep SQEs hot in cache by always accessing the same memory locations at the start of the ring, which can improve performance for workloads that submit small batches frequently. Available since 7.0.

If no flags are specified, the io\_uring instance is setup for interrupt driven I/O. I/O may be submitted using [**io\_uring\_enter**(2)](/io_uring_enter/2.md) and can be reaped by polling the completion queue.

The *resv* array must be initialized to zero.

*features* is filled in by the kernel, which specifies various features supported by current kernel version.

- **IORING\_FEAT\_SINGLE\_MMAP**

  If this flag is set, the two SQ and CQ rings can be mapped with a single [**mmap**(2)](/mmap/2.md) call. The SQEs must still be allocated separately. This brings the necessary [**mmap**(2)](/mmap/2.md) calls down from three to two. Available since kernel 5.4.

- **IORING\_FEAT\_NODROP**

  If this flag is set, io\_uring supports almost never dropping completion events. A dropped event can only occur if the kernel runs out of memory, in which case you have worse problems than a lost event. Your application and others will likely get OOM killed anyway. If a completion event occurs and the CQ ring is full, the kernel stores the event internally until such a time that the CQ ring has room for more entries. In earlier kernels, if this overflow condition is entered, attempting to submit more IO would fail with the **-EBUSY** error value, if it can't flush the overflown events to the CQ ring. If this happens, the application must reap events from the CQ ring and attempt the submit again. If the kernel has no free memory to store the event internally it will be visible by an increase in the overflow value on the cqring. Available since kernel 5.5. Additionally [**io\_uring\_enter**(2)](/io_uring_enter/2.md) will return **-EBADR** the next time it would otherwise sleep waiting for completions (since kernel 5.19).

- **IORING\_FEAT\_SUBMIT\_STABLE**

  If this flag is set, applications can be certain that any data for async offload has been consumed when the kernel has consumed the SQE. Available since kernel 5.5.

- **IORING\_FEAT\_RW\_CUR\_POS**

  If this flag is set, applications can specify *offset* == **-1** with **IORING\_OP\_{READV,WRITEV}**, **IORING\_OP\_{READ,WRITE}\_FIXED**, and **IORING\_OP\_{READ,WRITE}** to mean current file position, which behaves like [**preadv2**(2)](/preadv2/2.md) and [**pwritev2**(2)](/pwritev2/2.md) with *offset* == **-1**. It'll use (and update) the current file position. This obviously comes with the caveat that if the application has multiple reads or writes in flight, then the end result will not be as expected. This is similar to threads sharing a file descriptor and doing IO using the current file position. Available since kernel 5.6.

- **IORING\_FEAT\_CUR\_PERSONALITY**

  If this flag is set, then io\_uring guarantees that both sync and async execution of a request assumes the credentials of the task that called [**io\_uring\_enter**(2)](/io_uring_enter/2.md) to queue the requests. If this flag isn't set, then requests are issued with the credentials of the task that originally registered the io\_uring. If only one task is using a ring, then this flag doesn't matter as the credentials will always be the same. Note that this is the default behavior, tasks can still register different personalities through [**io\_uring\_register**(2)](/io_uring_register/2.md) with **IORING\_REGISTER\_PERSONALITY** and specify the personality to use in the sqe. Available since kernel 5.6.

- **IORING\_FEAT\_FAST\_POLL**

  If this flag is set, then io\_uring supports using an internal poll mechanism to drive data/space readiness. This means that requests that cannot read or write data to a file no longer need to be punted to an async thread for handling, instead they will begin operation when the file is ready. This is similar to doing poll + read/write in userspace, but eliminates the need to do so. If this flag is set, requests waiting on space/data consume a lot less resources doing so as they are not blocking a thread. Available since kernel 5.7.

- **IORING\_FEAT\_POLL\_32BITS**

  If this flag is set, the **IORING\_OP\_POLL\_ADD** command accepts the full 32-bit range of epoll based flags. Most notably **EPOLLEXCLUSIVE** which allows exclusive (waking single waiters) behavior. Available since kernel 5.9.

- **IORING\_FEAT\_SQPOLL\_NONFIXED**

  If this flag is set, the **IORING\_SETUP\_SQPOLL** feature no longer requires the use of fixed files. Any normal file descriptor can be used for IO commands without needing registration. Available since kernel 5.11.

- **IORING\_FEAT\_EXT\_ARG**

  If this flag is set, then the [**io\_uring\_enter**(2)](/io_uring_enter/2.md) system call supports passing in an extended argument instead of just the *sigset\_t* of earlier kernels. This extended argument is of type *struct io\_uring\_getevents\_arg* and allows the caller to pass in both a *sigset\_t* and a timeout argument for waiting on events. The struct layout is as follows:

- struct io\_uring\_getevents\_arg {

  ```
      __u64 sigmask;
      __u32 sigmask_sz;
      __u32 pad;
      __u64 ts;
  };
  ```

  and a pointer to this struct must be passed in if **IORING\_ENTER\_EXT\_ARG** is set in the flags for the enter system call. Available since kernel 5.11.

- **IORING\_FEAT\_NATIVE\_WORKERS**

  If this flag is set, io\_uring is using native workers for its async helpers. Previous kernels used kernel threads that assumed the identity of the original io\_uring owning task, but later kernels will actively create what looks more like regular process threads instead. Available since kernel 5.12.

- **IORING\_FEAT\_RSRC\_TAGS**

  If this flag is set, then io\_uring supports a variety of features related to fixed files and buffers. In particular, it indicates that registered buffers can be updated in-place, whereas before the full set would have to be unregistered first. Available since kernel 5.13.

- **IORING\_FEAT\_CQE\_SKIP**

  If this flag is set, then io\_uring supports setting **IOSQE\_CQE\_SKIP\_SUCCESS** in the submitted SQE, indicating that no CQE should be generated for this SQE if it executes normally. If an error happens processing the SQE, a CQE with the appropriate error value will still be generated. Available since kernel 5.17.

- **IORING\_FEAT\_LINKED\_FILE**

  If this flag is set, then io\_uring supports sane assignment of files for SQEs that have dependencies. For example, if a chain of SQEs are submitted with **IOSQE\_IO\_LINK**, then kernels without this flag will prepare the file for each link upfront. If a previous link opens a file with a known index, e.g. if direct descriptors are used with open or accept, then file assignment needs to happen post execution of that SQE. If this flag is set, then the kernel will defer file assignment until execution of a given request is started. Available since kernel 5.17.

- **IORING\_FEAT\_REG\_REG\_RING**

  If this flag is set, then io\_uring supports calling [**io\_uring\_register**(2)](/io_uring_register/2.md) using a registered ring fd, via **IORING\_REGISTER\_USE\_REGISTERED\_RING**. Available since kernel 6.3.

- **IORING\_FEAT\_MIN\_TIMEOUT**

  If this flag is set, then io\_uring supports passing in a minimum batch wait timeout. See [**io\_uring\_submit\_and\_wait\_min\_timeout**(3)](/io_uring_submit_and_wait_min_timeout/3.md) for more details.

- **IORING\_FEAT\_RECVSEND\_BUNDLE**

  If this flag is set, then io\_uring supports bundled send and recv operations. See [**io\_uring\_prep\_send\_bundle**(3)](/io_uring_prep_send_bundle/3.md) for more information. Also implies support for provided buffers in send operations.

The rest of the fields in the *struct io\_uring\_params* are filled in by the kernel, and provide the information necessary to memory map the submission queue, completion queue, and the array of submission queue entries. *sq\_entries* specifies the number of submission queue entries allocated. *sq\_off* describes the offsets of various ring buffer fields:

```
struct io_sqring_offsets {
    __u32 head;
    __u32 tail;
    __u32 ring_mask;
    __u32 ring_entries;
    __u32 flags;
    __u32 dropped;
    __u32 array;
    __u32 resv1;
    __u64 user_addr;
};
```

Taken together, *sq\_entries* and *sq\_off* provide all of the information necessary for accessing the submission queue ring buffer and the submission queue entry array. The submission queue can be mapped with a call like:

```
ptr = mmap(0, sq_off.array + sq_entries * sizeof(__u32),
           PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE,
           ring_fd, IORING_OFF_SQ_RING);
```

where *sq\_off* is the *io\_sqring\_offsets* structure, and *ring\_fd* is the file descriptor returned from [**io\_uring\_setup**(2)](/io_uring_setup/2.md). The addition of *sq\_off.array* to the length of the region accounts for the fact that the ring is located at the end of the data structure. As an example, the ring buffer head pointer can be accessed by adding *sq\_off.head* to the address returned from [**mmap**(2)](/mmap/2.md):

```
head = ptr + sq_off.head;
```

The *flags* field is used by the kernel to communicate state information to the application. Currently, it is used to inform the application when a call to [**io\_uring\_enter**(2)](/io_uring_enter/2.md) is necessary. See the documentation for the **IORING\_SETUP\_SQPOLL** flag above. The *dropped* member is incremented for each invalid submission queue entry encountered in the ring buffer.

The head and tail track the ring buffer state. The tail is incremented by the application when submitting new I/O, and the head is incremented by the kernel when the I/O has been successfully submitted. Determining the index of the head or tail into the ring is accomplished by applying a mask:

```
index = tail & ring_mask;
```

The array of submission queue entries is mapped with:

```
sqentries = mmap(0, sq_entries * sizeof(struct io_uring_sqe),
                 PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE,
                 ring_fd, IORING_OFF_SQES);
```

The completion queue is described by *cq\_entries* and *cq\_off* shown here:

```
struct io_cqring_offsets {
    __u32 head;
    __u32 tail;
    __u32 ring_mask;
    __u32 ring_entries;
    __u32 overflow;
    __u32 cqes;
    __u32 flags;
    __u32 resv1;
    __u64 user_addr;
};
```

The completion queue is simpler, since the entries are not separated from the queue itself, and can be mapped with:

```
ptr = mmap(0, cq_off.cqes + cq_entries * sizeof(struct io_uring_cqe),
           PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE, ring_fd,
           IORING_OFF_CQ_RING);
```

Closing the file descriptor returned by [**io\_uring\_setup**(2)](/io_uring_setup/2.md) will free all resources associated with the io\_uring context. Note that this may happen asynchronously within the kernel, so it is not guaranteed that resources are freed immediately.

## RETURN VALUE

[**io\_uring\_setup**(2)](/io_uring_setup/2.md) returns a new file descriptor on success. The application may then provide the file descriptor in a subsequent [**mmap**(2)](/mmap/2.md) call to map the submission and completion queues, or to the [**io\_uring\_register**(2)](/io_uring_register/2.md) or [**io\_uring\_enter**(2)](/io_uring_enter/2.md) system calls.

On error, a negative error code is returned. The caller should not rely on *errno* variable.

## ERRORS

- **EFAULT**

  *params* is outside your accessible address space.

- **EINVAL**

  The resv array contains non-zero data, p.flags contains an unsupported flag, *entries* is out of bounds, **IORING\_SETUP\_SQ\_AFF** was specified, but **IORING\_SETUP\_SQPOLL** was not, or **IORING\_SETUP\_CQSIZE** was specified, but *io\_uring\_params.cq\_entries* was invalid. **IORING\_SETUP\_REGISTERED\_FD\_ONLY** was specified, but **IORING\_SETUP\_NO\_MMAP** was not.

- **EMFILE**

  The per-process limit on the number of open file descriptors has been reached (see the description of **RLIMIT\_NOFILE** in [**getrlimit**(2)](/getrlimit/2.md)).

- **ENFILE**

  The system-wide limit on the total number of open files has been reached.

- **ENOMEM**

  Insufficient kernel resources are available.

- **EPERM**

  **IORING\_SETUP\_SQPOLL** was specified, but the effective user ID of the caller did not have sufficient privileges.

- **EPERM**

  */proc/sys/kernel/io\_uring\_disabled* has the value 2, or it has the value 1 and the calling process does not hold the **CAP\_SYS\_ADMIN** capability or is not a member of */proc/sys/kernel/io\_uring\_group*.

- **ENXIO**

  **IORING\_SETUP\_ATTACH\_WQ** was set, but *params.wq\_fd* did not refer to an io\_uring instance or refers to an instance that is in the process of shutting down.

## SEE ALSO

[**io\_uring\_register**(2)](/io_uring_register/2.md), [**io\_uring\_enter**(2)](/io_uring_enter/2.md)
