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

# process\_madvise(2)

give advice about use of memory to a process

## NAME

process\_madvise - give advice about use of memory to a process

## LIBRARY

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

## SYNOPSIS

```
#include <sys/mman.h>
```

**ssize\_t process\_madvise(size\_t** *n***;**                         **int** *pidfd***, const struct iovec** *iovec***\[***n***\],**                         **size\_t** *n***, int** *advice***, unsigned int** *flags***);**

## DESCRIPTION

The **process\_madvise**() system call is used to give advice or directions to the kernel about the address ranges of another process or of the calling process. It provides the advice for the address ranges described by *iovec* and *n*. The goal of such advice is to improve system or application performance.

The *pidfd* argument is a PID file descriptor (see [**pidfd\_open**(2)](/pidfd_open/2.md)) that specifies the process to which the advice is to be applied.

The pointer *iovec* points to an array of *iovec* structures, described in [**iovec**(3type)](/iovec/3type.md).

*n* specifies the number of elements in the array of *iovec* structures. This value must be less than or equal to **IOV\_MAX** (defined in *\<limits.h\>* or accessible via the call *sysconf(\_SC\_IOV\_MAX)*).

If manipulating another process, or before Linux 6.13, the *advice* argument is one of the following values:

- **MADV\_COLD**

  See [**madvise**(2)](/madvise/2.md).

- **MADV\_COLLAPSE**

  See [**madvise**(2)](/madvise/2.md).

- **MADV\_PAGEOUT**

  See [**madvise**(2)](/madvise/2.md).

- **MADV\_WILLNEED**

  See [**madvise**(2)](/madvise/2.md).

Since Linux 6.13, when manipulating the calling process, any advice flag is permitted.

The *flags* argument is reserved for future use; currently, this argument must be specified as 0.

The *n* and *iovec* arguments are checked before applying any advice. If *n* is too big, or *iovec* is invalid, then an error will be returned immediately and no advice will be applied.

The advice might be applied to only a part of *iovec* if one of its elements points to an invalid memory region in the remote process. No further elements will be processed beyond that point. (See the discussion regarding partial advice in RETURN VALUE.)

Since Linux 5.12, permission to apply advice to another process is governed by ptrace access mode **PTRACE\_MODE\_READ\_FSCREDS** check (see [**ptrace**(2)](/ptrace/2.md)); in addition, because of the performance implications of applying the advice, the caller must have the **CAP\_SYS\_NICE** capability (see [**capabilities**(7)](/capabilities/7.md)).

## RETURN VALUE

On success, **process\_madvise**() returns the number of bytes advised. This return value may be less than the total number of requested bytes, if an error occurred after some *iovec* elements were already processed. The caller should check the return value to determine whether a partial advice occurred.

On error, -1 is returned and *errno* is set to indicate the error.

## ERRORS

- **EBADF**

  *pidfd* is not a valid PID file descriptor.

- **EFAULT**

  The memory described by *iovec* is outside the accessible address space of the process referred to by *pidfd*.

- **EINVAL**

  *flags* is not 0.

- **EINVAL**

  The sum of the *iov\_len* values of *iovec* overflows a *ssize\_t* value.

- **EINVAL**

  *n* is too large.

- **ENOMEM**

  Could not allocate memory for internal copies of the *iovec* structures.

- **EPERM**

  The caller does not have permission to access the address space of the process *pidfd*.

- **ESRCH**

  The target process does not exist (i.e., it has terminated and been waited on).

See [**madvise**(2)](/madvise/2.md) for *advice*-specific errors.

## STANDARDS

Linux.

## HISTORY

Linux 5.10, glibc 2.36.

Support for this system call is optional, depending on the setting of the **CONFIG\_ADVISE\_SYSCALLS** configuration option.

When this system call first appeared in Linux 5.10, permission to apply advice to another process was entirely governed by ptrace access mode **PTRACE\_MODE\_ATTACH\_FSCREDS** check (see [**ptrace**(2)](/ptrace/2.md)). This requirement was relaxed in Linux 5.12 so that the caller didn't require full control over the target process.

## SEE ALSO

[**madvise**(2)](/madvise/2.md), [**pidfd\_open**(2)](/pidfd_open/2.md), [**process\_vm\_readv**(2)](/process_vm_readv/2.md), **process\_vm\_write**(2)
