1e5818a53SJeff Roberson.\" Copyright (c) 2018 Jeffrey Roberson <jeff@FreeBSD.org> 2e5818a53SJeff Roberson.\" All rights reserved. 3e5818a53SJeff Roberson.\" 4e5818a53SJeff Roberson.\" Redistribution and use in source and binary forms, with or without 5e5818a53SJeff Roberson.\" modification, are permitted provided that the following conditions 6e5818a53SJeff Roberson.\" are met: 7e5818a53SJeff Roberson.\" 1. Redistributions of source code must retain the above copyright 8e5818a53SJeff Roberson.\" notice, this list of conditions and the following disclaimer. 9e5818a53SJeff Roberson.\" 2. Redistributions in binary form must reproduce the above copyright 10e5818a53SJeff Roberson.\" notice, this list of conditions and the following disclaimer in the 11e5818a53SJeff Roberson.\" documentation and/or other materials provided with the distribution. 12e5818a53SJeff Roberson.\" 13e5818a53SJeff Roberson.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 14e5818a53SJeff Roberson.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 15e5818a53SJeff Roberson.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16e5818a53SJeff Roberson.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE 17e5818a53SJeff Roberson.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18e5818a53SJeff Roberson.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19e5818a53SJeff Roberson.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20e5818a53SJeff Roberson.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21e5818a53SJeff Roberson.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22e5818a53SJeff Roberson.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 23e5818a53SJeff Roberson.\" POSSIBILITY OF SUCH DAMAGE. 24e5818a53SJeff Roberson.\" 25e5818a53SJeff Roberson.\" $FreeBSD$ 26e5818a53SJeff Roberson.\" 279978bd99SMark Johnston.Dd October 30, 2018 28e5818a53SJeff Roberson.Dt DOMAINSET 9 29e5818a53SJeff Roberson.Os 30e5818a53SJeff Roberson.Sh NAME 31e5818a53SJeff Roberson.Nm domainset(9) 32e5818a53SJeff Roberson.Nd domainset functions and operation 33e5818a53SJeff Roberson.Sh SYNOPSIS 34e5818a53SJeff Roberson.In sys/_domainset.h 35e5818a53SJeff Roberson.In sys/domainset.h 36e5818a53SJeff Roberson.\" 37e5818a53SJeff Roberson.Bd -literal -offset indent 38e5818a53SJeff Robersonstruct domainset { 39e5818a53SJeff Roberson domainset_t ds_mask; 40e5818a53SJeff Roberson uint16_t ds_policy; 41e5818a53SJeff Roberson domainid_t ds_prefer; 42e5818a53SJeff Roberson ... 43e5818a53SJeff Roberson}; 44e5818a53SJeff Roberson.Ed 45e5818a53SJeff Roberson.Pp 469978bd99SMark Johnston.Ft struct domainset * 479978bd99SMark Johnston.Fn DOMAINSET_FIXED domain 489978bd99SMark Johnston.Ft struct domainset * 49662e7fa8SMark Johnston.Fn DOMAINSET_RR 509978bd99SMark Johnston.Ft struct domainset * 51662e7fa8SMark Johnston.Fn DOMAINSET_PREF domain 52e5818a53SJeff Roberson.Ft struct domainset * 53e5818a53SJeff Roberson.Fn domainset_create "const struct domainset *key" 54e5818a53SJeff Roberson.Ft int 55e5818a53SJeff Roberson.Fn sysctl_handle_domainset "SYSCTL_HANDLER_ARGS" 56e5818a53SJeff Roberson.Sh DESCRIPTION 57e5818a53SJeff RobersonThe 58e5818a53SJeff Roberson.Nm 59e5818a53SJeff RobersonAPI provides memory domain allocation policy for NUMA machines. 60e5818a53SJeff RobersonEach 61e5818a53SJeff Roberson.Vt domainset 62e5818a53SJeff Robersoncontains a bitmask of allowed domains, an integer policy, and an optional 63e5818a53SJeff Robersonpreferred domain. 64e5818a53SJeff RobersonTogether, these specify a search order for memory allocations as well as 65e5818a53SJeff Robersonthe ability to restrict threads and objects to a subset of available 66e5818a53SJeff Robersonmemory domains for system partitioning and resource management. 67e5818a53SJeff Roberson.Pp 68e5818a53SJeff RobersonEvery thread in the system and optionally every 69e5818a53SJeff Roberson.Vt vm_object_t , 70e5818a53SJeff Robersonwhich is used to represent files and other memory sources, has 71e5818a53SJeff Robersona reference to a 72e5818a53SJeff Roberson.Vt struct domainset . 73e5818a53SJeff RobersonThe domainset associated with the object is consulted first and the system 74e5818a53SJeff Robersonfalls back to the thread policy if none exists. 75e5818a53SJeff Roberson.Pp 76e5818a53SJeff RobersonThe allocation policy has the following possible values: 77e5818a53SJeff Roberson.Bl -tag -width "foo" 78e5818a53SJeff Roberson.It Dv DOMAINSET_POLICY_ROUNDROBIN 79e5818a53SJeff RobersonMemory is allocated from each domain in the mask in a round-robin fashion. 80e5818a53SJeff RobersonThis distributes bandwidth evenly among available domains. 81e5818a53SJeff RobersonThis policy can specify a single domain for a fixed allocation. 82e5818a53SJeff Roberson.It Dv DOMAINSET_POLICY_FIRSTTOUCH 83e5818a53SJeff RobersonMemory is allocated from the node that it is first accessed on. 84e5818a53SJeff RobersonAllocation falls back to round-robin if the current domain is not in the 85e5818a53SJeff Robersonallowed set or is out of memory. 86e5818a53SJeff RobersonThis policy optimizes for locality but may give pessimal results if the 87e5818a53SJeff Robersonmemory is accessed from many CPUs that are not in the local domain. 88e5818a53SJeff Roberson.It Dv DOMAINSET_POLICY_PREFER 89e5818a53SJeff RobersonMemory is allocated from the node in the 90e5818a53SJeff Roberson.Vt prefer 91*6f563a6fSGordon Berglingmember. 92*6f563a6fSGordon BerglingThe preferred node must be set in the allowed mask. 93e5818a53SJeff RobersonIf the preferred node is out of memory the allocation falls back to 94e5818a53SJeff Robersonround-robin among allowed sets. 95e5818a53SJeff Roberson.It Dv DOMAINSET_POLICY_INTERLEAVE 96e5818a53SJeff RobersonMemory is allocated in a striped fashion with multiple pages 97e5818a53SJeff Robersonallocated to each domain in the set according to the offset within 98e5818a53SJeff Robersonthe object. 99e5818a53SJeff RobersonThe strip width is object dependent and may be as large as a 100e5818a53SJeff Robersonsuper-page (2MB on amd64). 101e5818a53SJeff RobersonThis gives good distribution among memory domains while keeping system 102e5818a53SJeff Robersonefficiency higher and is preferential to round-robin for general use. 103e5818a53SJeff Roberson.El 104e5818a53SJeff Roberson.Pp 105e5818a53SJeff RobersonThe 1069978bd99SMark Johnston.Fn DOMAINSET_FIXED , 107662e7fa8SMark Johnston.Fn DOMAINSET_RR 108662e7fa8SMark Johnstonand 109662e7fa8SMark Johnston.Fn DOMAINSET_PREF 1109978bd99SMark Johnstonmacros provide pointers to global pre-defined policies for use when the 111662e7fa8SMark Johnstondesired policy is known at compile time. 1129978bd99SMark Johnston.Fn DOMAINSET_FIXED 1139978bd99SMark Johnstonis a policy which only permits allocations from the specified domain. 1149978bd99SMark Johnston.Fn DOMAINSET_RR 1159978bd99SMark Johnstonprovides round-robin selection among all domains in the system. 1169978bd99SMark JohnstonThe 1179978bd99SMark Johnston.Fn DOMAINSET_PREF 1189978bd99SMark Johnstonpolicies attempt allocation from the specified domain, but unlike 1199978bd99SMark Johnston.Fn DOMAINSET_FIXED 1209978bd99SMark Johnstonwill fall back to other domains to satisfy the request. 1219978bd99SMark JohnstonThese policies should be used in preference to 1229978bd99SMark Johnston.Fn DOMAINSET_FIXED 1239978bd99SMark Johnstonto avoid blocking indefinitely on a 1249978bd99SMark Johnston.Dv M_WAITOK 1259978bd99SMark Johnstonrequest. 126662e7fa8SMark JohnstonThe 127e5818a53SJeff Roberson.Fn domainset_create 128e5818a53SJeff Robersonfunction takes a partially filled in domainset as a key and returns a 129e5818a53SJeff Robersonvalid domainset or NULL. 130e5818a53SJeff RobersonIt is critical that consumers not use domainsets that have not been 131e5818a53SJeff Robersonreturned by this function. 132*6f563a6fSGordon Bergling.Vt domainset 133e5818a53SJeff Robersonis an immutable type that is shared among all matching keys and must 134e5818a53SJeff Robersonnot be modified after return. 135e5818a53SJeff Roberson.Pp 136e5818a53SJeff RobersonThe 137e5818a53SJeff Roberson.Fn sysctl_handle_domainset 138e5818a53SJeff Robersonfunction is provided as a convenience for modifying or viewing domainsets 139e5818a53SJeff Robersonthat are not accessible via 140e5818a53SJeff Roberson.Xr cpuset 2 . 141e5818a53SJeff RobersonIt is intended for use with 142e5818a53SJeff Roberson.Xr sysctl 9 . 143e5818a53SJeff Roberson.Sh SEE ALSO 144e5818a53SJeff Roberson.Xr cpuset 1 , 145e5818a53SJeff Roberson.Xr cpuset 2 , 146e5818a53SJeff Roberson.Xr cpuset_setdomain 2 , 147e5818a53SJeff Roberson.Xr bitset 9 148e5818a53SJeff Roberson.Sh HISTORY 149e5818a53SJeff Roberson.In sys/domainset.h 150e5818a53SJeff Robersonfirst appeared in 151e5818a53SJeff Roberson.Fx 12.0 . 152