---
name: "numa_getaffinity"
section: "2freebsd"
platform: "linux"
package: "freebsd-manpages"
version: "11.0-1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/numa_getaffinity"
---

# numa\_getaffinity(2freebsd)

manage NUMA affinity

## NAME

**numa\_getaffinity**, **numa\_setaffinity** – manage NUMA affinity

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/numa.h\>**

*int*\

**numa\_getaffinity**(*cpuwhich\_t which*, *id\_t id*, *struct vm\_domain\_policy\_entry \*policy*);

*int*\

**numa\_setaffinity**(*cpuwhich\_t which*, *id\_t id*, *const struct vm\_domain\_policy\_entry \*policy*);

## DESCRIPTION

**numa\_getaffinity**() and **numa\_setaffinity**() allow the manipulation of NUMA policies available to processes and threads. These functions may manipulate NUMA policies that contain many processes or affect only a single object.

Valid values for the *which* argument are documented in [cpuset(2)](/cpuset/2.md). These arguments specify which object set are used. Only CPU\_WHICH\_TID and CPU\_WHICH\_PID can be manipulated.

The *policy* entry contains a vm\_domain\_policy\_entry with the following fields:

```
struct vm_domain_policy_entry {
    vm_domain_policy_type_t policy;   /* VM policy */
    int domain;   /* VM domain, if applicable */
}
```

*vm\_domain\_policy\_type\_t*, *policy* is one these:

- VM\_POLICY\_NONE

  Reset the domain back to none. Any parent object NUMA domain policy will apply. The only valid value for domain is -1.

- VM\_POLICY\_ROUND\_ROBIN

  Select round-robin policy. Pages will be allocated round-robin from each VM domain in order. The only valid value for domain is -1.

- VM\_POLICY\_FIXED\_DOMAIN

  Select fixed-domain only policy. Pages will be allocated from the given domain which must be set to a valid VM domain. Pages will not be allocated from another domain if domain is out of free pages.

- VM\_POLICY\_FIXED\_DOMAIN\_ROUND\_ROBIN

  Select fixed-domain only policy. Pages will be allocated from domain which must be set to a valid VM domain. If page allocation fails, pages will be round-robin allocated from another domain if domain is out of free pages.

- VM\_POLICY\_FIRST\_TOUCH

  Select first-touch policy. Pages will be allocated from the NUMA domain which the thread is currently scheduled upon. Pages will not be allocated from another domain if the current domain is out of free pages. The only valid value for domain is -1.

- VM\_POLICY\_FIRST\_TOUCH\_ROUND\_ROBIN

  Select first-touch policy. Pages will be allocated from the NUMA domain which the thread is currently scheduled upon. Pages will be allocated round-robin from another domain if the current domain is out of free pages. The only valid value for domain is -1.

Note that the VM might assign some pages from other domains. For example, if an existing page allocation is covered by a superpage allocation.

**numa\_getaffinity**() retrieves the NUMA policy from the object specified by *which* and *id* and stores it in the space provided by *policy*.

**numa\_setaffinity**() attempts to set the NUMA policy for the object specified by *which* and *id* to the policy in *policy*.

## RETURN VALUES

The **numa\_getaffinity()** function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## ERRORS

*errno* can contain these error codes:

- \[EINVAL\]

  The *level* or *which* argument was not a valid value.

- \[EINVAL\]

  The *policy* argument specified when calling **numa\_setaffinity**() did not contain a valid policy.

- \[EFAULT\]

  The policy pointer passed was invalid.

- \[ESRCH\]

  The object specified by the *id* and *which* arguments could not be found.

- \[ERANGE\]

  The *domain* in the given policy was out of the range of possible VM domains available.

- \[EPERM\]

  The calling process did not have the credentials required to complete the operation.

## SEE ALSO

[cpuset(1)](/cpuset/1.md), numactl(1), [cpuset(2)](/cpuset/2.md), [cpuset\_getaffinity(2)](/cpuset_getaffinity/2.md), [cpuset\_getid(2)](/cpuset_getid/2.md), [cpuset\_setaffinity(2)](/cpuset_setaffinity/2.md), [cpuset\_setid(2)](/cpuset_setid/2.md), [pthread\_affinity\_np(3)](/pthread_affinity_np/3.md), [pthread\_attr\_affinity\_np(3)](/pthread_attr_affinity_np/3.md), [numa(4)](/numa/4.md)

## HISTORY

The **numa\_getaffinity** family of system calls first appeared in FreeBSD 11.0.

## AUTHORS

Adrian Chadd ⟨*adrian@FreeBSD.org*⟩
