---
name: "io_setup"
section: "2"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/io_setup"
---

# io\_setup(2)

create an asynchronous I/O context

## NAME

io\_setup - create an asynchronous I/O context

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <linux/aio_abi.h>
#include <sys/syscall.h>    /* Definition of SYS_* constants */
#include <unistd.h>
```

**long syscall(SYS\_io\_setup, unsigned int** *n***, aio\_context\_t \****ctx\_idp***);**

## DESCRIPTION

*Note*: you probably want to use the [**io\_setup**(3)](/io_setup/3.md) wrapper function provided by *libaio*; see VERSIONS.

The **io\_setup**() system call creates an asynchronous I/O context suitable for concurrently processing *n* operations. The *ctx\_idp* argument must not point to an AIO context that already exists, and must be initialized to 0 prior to the call. On successful creation of the AIO context, *\*ctx\_idp* is filled in with the resulting handle.

## RETURN VALUE

On success, **io\_setup**() returns 0. On error, -1 is returned, and *errno* is set to indicate the error.

## ERRORS

- **EAGAIN**

  The specified *n* exceeds the limit of available events, as defined in */proc/sys/fs/aio-max-nr* (see [**proc\_sys\_fs**(5)](/proc_sys_fs/5.md)).

- **EFAULT**

  An invalid pointer is passed for *ctx\_idp*.

- **EINVAL**

  *\*ctx\_idp* is not initialized to 0.

- **EINVAL**

  The specified *n* exceeds internal limits. *n* should be greater than 0.

- **ENOMEM**

  Insufficient kernel resources are available.

- **ENOSYS**

  **io\_setup**() is not implemented on this architecture.

## VERSIONS

*libaio* ⟨https://pagure.io/libaio⟩ provides a wrapper function with the same name, but different prototype and return value. You probably want to use that wrapper.

## STANDARDS

Linux.

## HISTORY

Linux 2.5.

## SEE ALSO

[**io\_cancel**(2)](/io_cancel/2.md), [**io\_destroy**(2)](/io_destroy/2.md), [**io\_getevents**(2)](/io_getevents/2.md), [**io\_submit**(2)](/io_submit/2.md), [**io\_setup**(3)](/io_setup/3.md), [**aio**(7)](/aio/7.md)
