---
name: "cpuset_setdomain"
section: "2freebsd"
platform: "linux"
package: "freebsd-manpages"
version: "12.2-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/cpuset_getdomain/2freebsd"
---

# cpuset\_setdomain(2freebsd)

manage memory domain policy

Part of [cpuset\_getdomain(2freebsd)](/cpuset_getdomain/2freebsd.md).

## NAME

**cpuset\_getdomain**, **cpuset\_setdomain** – manage memory domain policy

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

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

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

*int*\

**cpuset\_getdomain**(*cpulevel\_t level*, *cpuwhich\_t which*, *id\_t id*, *size\_t setsize*, *domainset\_t \*mask*, *int \*policy*);

*int*\

**cpuset\_setdomain**(*cpulevel\_t level*, *cpuwhich\_t which*, *id\_t id*, *size\_t setsize*, *const domainset\_t \*mask*, *int policy*);

## DESCRIPTION

**cpuset\_getdomain**() and **cpuset\_setdomain**() allow the manipulation of sets of memory domains and allocation policy available to processes, threads, jails and other resources. These functions may manipulate sets of memory domains that contain many processes or per-object anonymous masks that affect only a single object.

The valid values for the *level* and *which* arguments are documented in [cpuset(2)](/cpuset/2.md). These arguments specify which object and which set of the object we are referring to. Not all possible combinations are valid. For example, only processes may belong to a numbered set accessed by a *level* argument of CPU\_LEVEL\_CPUSET. All resources, however, have a mask which may be manipulated with CPU\_LEVEL\_WHICH.

Masks of type *domainset\_t* are composed using the DOMAINSET macros. The kernel tolerates large sets as long as all domains specified in the set exist. Sets smaller than the kernel uses generate an error on calls to **cpuset\_getdomain**() even if the result set would fit within the user supplied set. Calls to **cpuset\_setdomain**() tolerate small sets with no restrictions.

The supplied mask should have a size of *setsize* bytes. This size is usually provided by calling sizeof(mask) which is ultimately determined by the value of DOMAINSET\_SETSIZE as defined in ⟨sys/domainset.h⟩.

**cpuset\_getdomain**() retrieves the mask and policy from the object specified by *level*, *which* and *id* and stores it in the space provided by *mask* and *policy*.

**cpuset\_setdomain**() attempts to set the mask and policy for the object specified by *level*, *which* and *id* to the values in *mask* and *policy*.

## ALLOCATION POLICIES

Valid policy values are as follows:

- DOMAINSET\_POLICY\_ROUNDROBIN

  Memory is allocated on a round-robin basis by cycling through each domain in *mask*.

- DOMAINSET\_POLICY\_FIRSTTOUCH

  Memory is allocated on the domain local to the CPU the requesting thread is running on.  Failure to allocate from this domain will fallback to round-robin.

- DOMAINSET\_POLICY\_PREFER

  Memory is allocated preferentially from the single domain specified in the mask. If memory is unavailable the domains listed in the parent cpuset will be visited in a round-robin order.

## RETURN VALUES

The **cpuset\_getdomain()** 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

The following error codes may be set in *errno*:

- \[EINVAL\]

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

- \[EINVAL\]

  The *mask*, *or* *policy* argument specified when calling **cpuset\_setdomain**() was not a valid value.

- \[EDEADLK\]

  The **cpuset\_setdomain**() call would leave a thread without a valid CPU to run on because the set does not overlap with the thread's anonymous mask.

- \[EFAULT\]

  The mask pointer passed was invalid.

- \[ESRCH\]

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

- \[ERANGE\]

  The *domainsetsize* was either preposterously large or smaller than the kernel set size.

- \[EPERM\]

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

- \[ECAPMODE\]

  The calling process attempted to act on a process other than itself, while  in capability mode. See [capsicum(4)](/capsicum/4.md).

## SEE ALSO

[capsicum(4)](/capsicum/4.md), [cpuset(1)](/cpuset/1.md), [cpuset(2)](/cpuset/2.md), [cpuset\_getid(2)](/cpuset_getid/2.md), [cpuset\_setid(2)](/cpuset_setid/2.md), [cpuset\_getaffinity(2)](/cpuset_getaffinity/2.md), [cpuset\_setaffinity(2)](/cpuset_setaffinity/2.md), [cpuset(9)](/cpuset/9.md)

## HISTORY

The **cpuset\_getdomain** family of system calls first appeared in FreeBSD 12.0.

## AUTHORS

Jeffrey Roberson ⟨*jeff@FreeBSD.org*⟩
