Sphinx docs: Design Document for NUMA node-affine claim sets
cover Sphinx docs: Design Document for NUMA node-affine claim sets
Dear reviewers,
This updated design document forms the basis of the NUMA claims v7 series and is intended to serve as a reference during review.
It extends Xen's memory claim design to support installing claim sets spanning multiple NUMA nodes atomically. As Roger Pau Monné suggested:
Ideally, we would need to introduce a new hypercall that allows making claims from multiple nodes in a single locked region, as to ensure success or failure in an atomic way.
This design documents that model in detail and is integrated into the Sphinx site below Hypervisor Guide -> Design Documents -> NUMA Claims.
The rendered design document is available here for review:
https://xen.kaindl.dev/claims-v7-design-master/designs/claims/
The Sphinx site can be built and viewed locally as follows:
git pull [email protected]:bernhardkaindl/xen.git claims-v7-design-master make -C docs sphinx-env-build # xdg-open docs/sphinx/html/index.html or start a minimal HTTP server:
(cd docs/sphinx/html; python -m http.server)
Changes since v6
----------------
The review comments from v6 have been incorporated.
In particular, Jan noted that "global" is ambiguous in this context, and following his suggestion, this series adopts the term host claims (short for host-wide claims) found here:
https://lists.xen.org/archives/html/xen-devel/2026-05/msg00026.html
The helper names have also been adjusted to make domain scope explicit and to keep the release/set/get operations named consistently:
- deduct_global_claims() -> domain_release_host_claims()
- deduct_node_claims() -> domain_release_node_claims()
- domain_set_outstanding_pages() -> domain_set_claim_entries()
- new: domain_get_claim_entries()
This version also keeps the new code minimal for review and avoids functional duplication. domain_set_claim_entries() now also handles the legacy XENMEM_claim_pages interface for backwards compatibility, replacing domain_set_outstanding_pages().
Best regards,
Bernhard
Bernhard Kaindl (3):
Sphinx docs: Rearrange the design docs into a new dedicated design
index
Sphinx docs: Enable autosectionlabels and Mermaid support Sphinx docs: Design Document for NUMA node affine claim sets
.readthedocs.yaml | 2 +-
docs/conf.py | 21 +
docs/{misc => designs}/cache-coloring.rst | 4 +-
docs/designs/claims/accounting.rst | 331 +++++++++++++++
docs/designs/claims/design.rst | 243 +++++++++++
docs/designs/claims/development.rst | 197 +++++++++
docs/designs/claims/implementation.rst | 393 ++++++++++++++++++
docs/designs/claims/index.rst | 48 +++
docs/designs/claims/installation.rst | 70 ++++
docs/designs/claims/invariants.mmd | 35 ++
docs/designs/claims/performance.rst | 33 ++
docs/designs/claims/protection.rst | 200 +++++++++
docs/designs/claims/redeeming.rst | 71 ++++
docs/designs/claims/terminology.rst | 138 ++++++
docs/designs/claims/use-cases.rst | 39 ++
docs/designs/index.rst | 17 +
docs/designs/launch/hyperlaunch.rst | 4 +-
docs/designs/launch/index.rst | 10 +
docs/glossary.rst | 12 +-
.../dom/DOMCTL_claim_memory-data.mmd | 43 ++
.../dom/DOMCTL_claim_memory-seqdia.mmd | 23 +
.../dom/DOMCTL_claim_memory-workflow.mmd | 23 +
docs/guest-guide/dom/DOMCTL_claim_memory.rst | 221 ++++++++++
docs/guest-guide/dom/index.rst | 14 +
docs/guest-guide/index.rst | 23 +
docs/guest-guide/mem/XENMEM_claim_pages.rst | 102 +++++
docs/guest-guide/mem/index.rst | 12 +
docs/hypervisor-guide/index.rst | 12 +-
docs/index.rst | 2 -
29 files changed, 2331 insertions(+), 12 deletions(-)
rename docs/{misc => designs}/cache-coloring.rst (99%)
create mode 100644 docs/designs/claims/accounting.rst
create mode 100644 docs/designs/claims/design.rst
create mode 100644 docs/designs/claims/development.rst
create mode 100644 docs/designs/claims/implementation.rst
create mode 100644 docs/designs/claims/index.rst
create mode 100644 docs/designs/claims/installation.rst
create mode 100644 docs/designs/claims/invariants.mmd
create mode 100644 docs/designs/claims/performance.rst
create mode 100644 docs/designs/claims/protection.rst
create mode 100644 docs/designs/claims/redeeming.rst
create mode 100644 docs/designs/claims/terminology.rst
create mode 100644 docs/designs/claims/use-cases.rst
create mode 100644 docs/designs/index.rst
create mode 100644 docs/designs/launch/index.rst
create mode 100644 docs/guest-guide/dom/DOMCTL_claim_memory-data.mmd
create mode 100644 docs/guest-guide/dom/DOMCTL_claim_memory-seqdia.mmd
create mode 100644 docs/guest-guide/dom/DOMCTL_claim_memory-workflow.mmd
create mode 100644 docs/guest-guide/dom/DOMCTL_claim_memory.rst
create mode 100644 docs/guest-guide/dom/index.rst
create mode 100644 docs/guest-guide/mem/XENMEM_claim_pages.rst
create mode 100644 docs/guest-guide/mem/index.rstSignature · 1 line
2.39.5
PATCH 1/3 Sphinx docs: Rearrange the design docs into a new dedicated design index
The Hyperlaunch Design Documents were stated as needing rearranging. Rearrange them inside the Hypervisor Guide and fix the bug where one got the title "1 Hypervisor Design Document".
This also serves as first small step to clean up the main menu of the Sphinx documentation.
---
Preview of the improved menu structure for design documents:
https://xen.kaindl.dev/arrange-hyperlaunch-design/
---
docs/{misc => designs}/cache-coloring.rst | 4 ++--
docs/designs/index.rst | 16 ++++++++++++++++
docs/designs/launch/hyperlaunch.rst | 4 ++--
docs/designs/launch/index.rst | 10 ++++++++++
docs/hypervisor-guide/index.rst | 12 ++++++++++--
docs/index.rst | 2 --
6 files changed, 40 insertions(+), 8 deletions(-)
rename docs/{misc => designs}/cache-coloring.rst (99%)
create mode 100644 docs/designs/index.rst
create mode 100644 docs/designs/launch/index.rstdocs/designs/cache-coloring.rst renamed from docs/misc/cache-coloring.rst +2 -2
@@ -1,7 +1,7 @@ .. SPDX-License-Identifier: CC-BY-4.0 -Xen cache coloring user guide -============================= +Cache Coloring +============== The cache coloring support in Xen allows to reserve Last Level Cache (LLC) partitions for Dom0, DomUs and Xen itself. Currently only ARM64 is supported.
docs/designs/index.rst new file +16 -0
@@ -0,0 +1,16 @@ +.. SPDX-License-Identifier: CC-BY-4.0 + +Design documents +================ + +Design documents and implementation details for the Xen hypervisor. + +These are intended for developers working on the Xen hypervisor, +and for those interested in the internal workings of Xen. + +.. toctree:: + :maxdepth: 2 + :numbered: 4 + + launch/index + cache-coloring
docs/designs/launch/hyperlaunch.rst +2 -2
@@ -2,8 +2,6 @@ Hyperlaunch Design Document ########################### -.. sectnum:: :depth: 4 - This post is a Request for Comment on the included v4 of a design document that describes Hyperlaunch: a new method of launching the Xen hypervisor, relating to dom0less and work from the Hyperlaunch project. We invite discussion of this
@@ -13,6 +11,8 @@ Xen Development mailing list. .. contents:: :depth: 3 + :backlinks: entry + :local: Introduction
docs/designs/launch/index.rst new file +10 -0
@@ -0,0 +1,10 @@ +.. SPDX-License-Identifier: CC-BY-4.0 + +Hyperlaunch +=========== + +.. toctree:: + :maxdepth: 2 + + hyperlaunch + hyperlaunch-devicetree
docs/hypervisor-guide/index.rst +10 -2
@@ -1,11 +1,19 @@ .. SPDX-License-Identifier: CC-BY-4.0 -Hypervisor documentation -======================== +Hypervisor Guide +================ + +The Hypervisor Guide provides an overview of the Xen hypervisor's +architecture and design, covering its core components, features, +and how it manages resources for :term:`guest` domains. + +It serves as a comprehensive reference for developers and users interested +in understanding the inner workings of the Xen hypervisor. .. toctree:: :maxdepth: 2 + ../designs/index code-coverage x86/index
docs/index.rst +0 -2
@@ -62,8 +62,6 @@ Documents in need of some rearranging. .. toctree:: :maxdepth: 2 - designs/launch/hyperlaunch - designs/launch/hyperlaunch-devicetree misc/xen-makefiles/makefiles misra/index fusa/index
Signature · 1 line
2.39.5
PATCH 2/3 Sphinx docs: Enable autosectionlabels and Mermaid support
In reply to Bernhard KaindlEnable sphinx.ext.autosectionlabel which allows referencing sections using their title, without needing to add explicit labels to each section and enable support for Mermaid diagrams for design documents.
--- .readthedocs.yaml | 2 +- docs/conf.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
.readthedocs.yaml +1 -1
@@ -12,7 +12,7 @@ build: jobs: post_install: # Instead of needing a separate requirements.txt - - python -m pip install --upgrade --no-cache-dir sphinx-rtd-theme + - python -m pip install --upgrade --no-cache-dir sphinx-rtd-theme sphinxcontrib-mermaid sphinx: configuration: docs/conf.py
docs/conf.py +21 -0
@@ -63,6 +63,27 @@ needs_sphinx = '1.4' # ones. extensions = [] + +# autosectionlabel allows referencing sections using their title, without +# needing to add explicit labels to each section. Used by design documents. +extensions.append("sphinx.ext.autosectionlabel") +# Setting autosectionlabel_prefix_document to True allows disambiguating +# between sections with the same title in different documents by prefixing +# the label with the document path. +autosectionlabel_prefix_document = True + + +# Mermaid diagrams are used in the design documents, so we try to +# load the extension if it's available, but don't fail if it's not: +try: + import sphinxcontrib.mermaid + + extensions.append("sphinxcontrib.mermaid") + # For included Mermaid diagram files, init the extension explicitly. + mermaid_init_js = "mermaid.initialize({ startOnLoad: true });" +except ImportError: + pass + # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates']
Signature · 1 line
2.39.5
PATCH 3/3 Sphinx docs: Design Document for NUMA node affine claim sets
In reply to Bernhard KaindlThis design extends Xen's memory claim handling to support claim sets spanning multiple NUMA nodes. Roger Pau Monné described it as:
Ideally, we would need to introduce a new hypercall that allows making claims from multiple nodes in a single locked region, as to ensure success or failure in an atomic way.
This design documents this model in detail and is integrated into the Sphinx site below Hypervisor Guide -> Design Documents -> NUMA Claims.
--- docs/designs/claims/accounting.rst | 331 +++++++++++++++ docs/designs/claims/design.rst | 243 +++++++++++ docs/designs/claims/development.rst | 197 +++++++++ docs/designs/claims/implementation.rst | 393 ++++++++++++++++++ docs/designs/claims/index.rst | 48 +++ docs/designs/claims/installation.rst | 70 ++++ docs/designs/claims/invariants.mmd | 35 ++ docs/designs/claims/performance.rst | 33 ++ docs/designs/claims/protection.rst | 200 +++++++++ docs/designs/claims/redeeming.rst | 71 ++++ docs/designs/claims/terminology.rst | 138 ++++++ docs/designs/claims/use-cases.rst | 39 ++ docs/designs/index.rst | 1 + docs/glossary.rst | 12 +- .../dom/DOMCTL_claim_memory-data.mmd | 43 ++ .../dom/DOMCTL_claim_memory-seqdia.mmd | 23 + .../dom/DOMCTL_claim_memory-workflow.mmd | 23 + docs/guest-guide/dom/DOMCTL_claim_memory.rst | 221 ++++++++++ docs/guest-guide/dom/index.rst | 14 + docs/guest-guide/index.rst | 23 + docs/guest-guide/mem/XENMEM_claim_pages.rst | 102 +++++ docs/guest-guide/mem/index.rst | 12 + 22 files changed, 2269 insertions(+), 3 deletions(-) create mode 100644 docs/designs/claims/accounting.rst create mode 100644 docs/designs/claims/design.rst create mode 100644 docs/designs/claims/development.rst create mode 100644 docs/designs/claims/implementation.rst create mode 100644 docs/designs/claims/index.rst create mode 100644 docs/designs/claims/installation.rst create mode 100644 docs/designs/claims/invariants.mmd create mode 100644 docs/designs/claims/performance.rst create mode 100644 docs/designs/claims/protection.rst create mode 100644 docs/designs/claims/redeeming.rst create mode 100644 docs/designs/claims/terminology.rst create mode 100644 docs/designs/claims/use-cases.rst create mode 100644 docs/guest-guide/dom/DOMCTL_claim_memory-data.mmd create mode 100644 docs/guest-guide/dom/DOMCTL_claim_memory-seqdia.mmd create mode 100644 docs/guest-guide/dom/DOMCTL_claim_memory-workflow.mmd create mode 100644 docs/guest-guide/dom/DOMCTL_claim_memory.rst create mode 100644 docs/guest-guide/dom/index.rst create mode 100644 docs/guest-guide/mem/XENMEM_claim_pages.rst create mode 100644 docs/guest-guide/mem/index.rst
docs/designs/claims/accounting.rst new file +331 -0
@@ -0,0 +1,331 @@ +.. SPDX-License-Identifier: CC-BY-4.0 + +Accounting +########## + +.. contents:: Table of Contents + :local: + +.. note:: + Claims accounting state is only updated while holding the :c:var:`heap_lock`. + See :ref:`designs/claims/accounting:Locking of the claims state` for details + on the locks used to protect the claims accounting state. + +This section formalises the internal state and invariants that Xen must +maintain to ensure correctness. + + +For readers following the design in order, the preceding sections are: + +1. :doc:`/designs/claims/design` introduces the overall model and goals. +2. :doc:`/designs/claims/installation` explains how claim sets are installed. +3. :doc:`/designs/claims/protection` describes how claimed memory is protected + during allocation. +4. :doc:`/designs/claims/redeeming` explains how claims are redeemed when + allocations succeed. + +Overview +^^^^^^^^ + +.. table:: Table 1: Claims accounting: All accesses, Aggregate state, + and invariants protected by :c:var:`heap_lock`. + :widths: auto + + ============ =========================================== ======================= + Level Claims must be lower or equal to the available memory + ============ =========================================== ======================= + Total :c:var:`outstanding_claims` = :c:var:`total_avail_pages` = + + = Aggregate state: + SUM() over all domains: Aggregate state: + SUM(:c:member:`domain.outstanding_pages`) SUM(:c:var:`node_avail_pages`) + + Also, it is the sum of claims + over all nodes: + + = Aggregate state: + SUM(:c:expr:`node_outstanding_claims[*]`) + Node :c:expr:`node_outstanding_claims[node]` :c:expr:`node_avail_pages[node]` + + Aggregate state over all domains: Aggregate of the free + SUM(:c:expr:`domain.claims[node]`) lists of all zones on node + Dom per-node :c:member:`domain.node_claims` = + SUM(:c:expr:`domain.claims[node]`) :c:expr:`node_avail_pages[node]` + Total claims :c:member:`domain.outstanding_pages` :c:var:`total_avail_pages` + Memory limit :c:member:`domain.outstanding_pages` Invariant: must be + + :c:func:`domain_tot_pages` lower or equal to + :c:member:`domain.max_pages` + ============ =========================================== ======================= + + +Total claims and available memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + These variables tracking the total claims and available memory in the system + are aggregates of the actual per-node and per-domain values. + + + They are only maintained for efficient checks in the allocator hot paths, to + quickly determine if an allocation can be satisfied from unclaimed memory or + if further checks are needed to determine if the claims of the domain can be + used to free up memory for the allocation. This also ensures that the sum of + all claims never exceeds the total free memory in the system. + + + The number of unclaimed pages across all nodes in the system is derived as + :c:var:`total_avail_pages` minus :c:var:`outstanding_claims`. + This number is then used to: + + - Permit allocation requests if they can be satisfied from unclaimed pages. + - Ensure that the sum of all claims never exceeds the total free memory. + + .. c:var:: unsigned long total_avail_pages + + Total available pages in the system across all NUMA nodes. + It is the aggregate of the per-node available pages: + :c:var:`total_avail_pages` = SUM(:c:expr:`node_avail_pages[MAX_NUMNODES]`) + + .. c:var:: unsigned long outstanding_claims + + The total sum of all claims across all domains. + :c:var:`outstanding_claims` = + SUM(:c:var:`domain.outstanding_pages`) + +Per-node claims and available memory +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + .. c:var:: unsigned long node_avail_pages[MAX_NUMNODES] + + Available pages for each NUMA node, including both free and claimed pages. + This is used for validating that node claims do not exceed the available + memory on the respective NUMA node. + + .. c:var:: unsigned long node_outstanding_claims[MAX_NUMNODES] + + The total claims across all domains for each NUMA node, indexed by node + ID. This is maintained for efficient checks in the allocator hot paths. + +This diagram illustrates the claims accounting state and the invariants: + +Accounting diagram +^^^^^^^^^^^^^^^^^^ + + .. mermaid:: invariants.mmd + :caption: Diagram: Claims accounting state and invariants + +Claims accounting state for each domain +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + .. c:struct:: domain + + The main structure representing a domain in Xen. It includes the + claims accounting state for the domain, including both host-wide + and node-specific claims, as well as the maximum page limits for the + domain and the lock protecting the domain's page allocation counts. + + While the domain's page counts are currently `unsigned int`, work is + underway to change them to `unsigned long` to support larger page counts + beyond 16 TB. The code is already designed to anticipate this change and + work with either `unsigned int` or `unsigned long` page counts equally well. + + .. c:member:: unsigned int outstanding_pages + + The domain's total claim, representing the number of pages claimed + for the domain. + + .. c:member:: unsigned int node_claims + + The total of the domain's node-affine claims, maintained for efficient + checks in the allocator hot paths without needing to sum over the + per-node claims each time. It is equal to the sum of + :c:expr:`claims[MAX_NUMNODES]` for all nodes. + + .. c:member:: unsigned int claims[MAX_NUMNODES] + + The domain's claims for each :term:`NUMA node`, indexed by node ID. + + As the storage for ``struct`` :c:struct:`domain` is allocated using a + dedicated page for each domain, this array allows for efficient and + fast storage with direct indexing, without consuming any additional + memory for an extra allocation. + + + The claims for each node are used for NUMA-affine domains to specify + the amount of memory claimed for each node, to ensure that the domain's + claims for each node do not exceed the available memory on that node, + and to allow the allocator to redeem claims from the appropriate nodes + when allocating memory for the domain. + + .. literalinclude:: ../../../xen/common/domain.c + :language: C + :caption: Allocation of the domain structure in ``xen/common/domain.c`` + :start-at: alloc_domain_struct + :end-at: } + :emphasize-lines: 7, 12, 14 + :linenos: + :lineno-match: + + The page allocated for ``struct`` :c:struct:`domain` is large enough + to accommodate this array several times, even beyond the current + :c:macro:`MAX_NUMNODES` limit of 64. It should be sufficient even for + future expansion of the maximum number of supported NUMA nodes if + needed. The allocation has a build-time assertion for safety to ensure + that ``struct`` :c:struct:`domain` fits within the allocated page. + + + The sum of these claims is stored in :c:member:`domain.node_claims` + for efficient checks in the allocator hot paths which need to know + the total number of node claims for the :term:`domain`. + + .. c:member:: unsigned int max_pages + + The maximum number of pages the domain is allowed to claim, set at + domain creation time. + + .. c:member:: rspinlock_t page_alloc_lock + + Lock for checking :c:func:`domain_tot_pages` on top of new claims + against :c:member:`domain.max_pages` when installing these new claims. + This is a recursive spinlock to allow for nested calls into the allocator + while holding it, such as when redeeming claims during page allocation. + It is taken before :c:var:`heap_lock` when installing claims to ensure a + consistent locking order and must not be taken while holding + :c:var:`heap_lock` to avoid deadlocks. + + .. c:member:: nodemask_t node_affinity + + A :c:type:`nodemask_t` representing the set of NUMA nodes the domain + is affine to. This is used for efficient checks in the allocator hot + paths to quickly get the set of nodes a domain is affine to for + memory allocation decisions. + +Claims accounting invariants +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Xen must maintain the following invariants at all times to ensure correctness + of claims accounting: + + - For all claims, including node-affine and host-wide claims: + :c:var:`outstanding_claims` :math:`\le` :c:var:`total_avail_pages` + + - For node-specific claims: + :c:expr:`node_outstanding_claims[alloc_node]` :math:`\le` + :c:expr:`node_avail_pages[alloc_node]` + + - For a domain's overall claims: + :c:var:`domain.outstanding_pages` + + :c:var:`domain_tot_pages` :math:`\le` :c:var:`domain.max_pages` + + See :doc:`redeeming` for more information on this invariant. + +Constants +^^^^^^^^^ + + .. c:macro:: MAX_NUMNODES + + The maximum number of NUMA nodes supported by Xen. Used for validating + node IDs in the :c:type:`memory_claim_t` entries of claim sets. + When Xen is built without NUMA support, it is 1. + + The default on x86_64 is 64 which is sufficient for current hardware and + allows for efficient storage of e.g. the :c:var:`node_online_map` for + online nodes and :c:member:`domain.node_affinity` in a single 64-bit value, + and in the :c:expr:`domain.claims[MAX_NUMNODES]` array. + + ``xen/arch/Kconfig`` limits the maximum number of NUMA nodes to 64. While + Xen can be compiled for up to 254 nodes, configuring machines to split + the installed memory into more than 64 nodes would be unusual. + For example, dual-socket servers, even when using multiple chips per CPU + package should typically be configured for 2 NUMA nodes by default. + + .. c:var:: nodemask_t node_online_map + + A bitmap representing which NUMA nodes are currently online in the system. + This is used for validating that claims are only made for online nodes and + for efficient checks in the allocator hot paths to quickly determine which + nodes are online. Currently, Xen does not support hotplug of NUMA nodes, + so this is set at boot time based on the platform firmware configuration + and does not change at runtime. + +Types +^^^^^ + + .. c:type:: uint8_t nodeid_t + + Type for :term:`NUMA node` IDs. It is passed to Xenctrl using the + :c:var:`mem_flags` argument of :c:func:`xc_domain_populate_physmap()` + and passed to Xen in this form. + + It allocates 8 bits in the flags for the node ID, which limits the + theoretical maximum value of :c:macro:`CONFIG_NR_NUMA_NODES` at 254 + (255 is :c:macro:`NUMA_NO_NODE`), which is far beyond the current + maximum of 64 supported by Xen and should be sufficient for all + practical purposes. This also allows for efficient storage of NUMA + nodes in arrays indexed by node ID and in :c:type:`nodemask_t` bitmaps + :c:var:`node_online_map` and :c:member:`domain.node_affinity` for + efficient checks in the allocator hot paths. + + .. c:type:: nodemask_t + + A bitmap representing a set of NUMA nodes, used for status information + like :c:var:`node_online_map` and the :c:member:`domain.node_affinity`, + and to track which nodes are online and which nodes are in a domain's + node affinity. + +Memflags +^^^^^^^^ + + .. c:type:: memflags + + Flags for memory allocation requests that can affect the allocation + behaviour, such as node preference and whether the request is for an + exact node. + + .. c:macro:: MEMF_no_owner + + Flag for memory allocation requests to indicate that the allocation + shall not be owned by a domain, and as part of that, + :c:macro:`MEMF_no_refcount` is also set. + + .. c:macro:: MEMF_no_refcount + + Flag for memory allocation requests to indicate that the request is not + reference-counted to a domain's memory allocation state, and as part of + that, claims of a domain cannot be used to protect and redeem the + allocation using claims. This is used for requests which are not for + domains or which explicitly bypass reference-counting for other reasons. + + .. c:macro:: MEMF_no_scrub + + Flag for memory allocation requests to indicate that the allocated memory + should not be scrubbed (zeroed) before being used. This is used for + performance reasons for certain types of allocations where the caller + guarantees that the memory will be properly initialized before use. + +Locking of the claims state +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + .. :c:member:: domain.page_alloc_lock + + If :c:var:`domain.page_alloc_lock` is needed, e.g. to check + :c:func:`domain_tot_pages` on top of new claims against + :c:var:`domain.max_pages` for the domain, it needs to be taken before + :c:var:`heap_lock` for consistent locking order to avoid deadlocks. + + .. c:var:: spinlock_t heap_lock + + Lock for all heap operations including claims. It protects the claims + state and invariants from concurrent updates and ensures that checks + in the allocator hot paths see a consistent view of the claims state. + +Helper functions +^^^^^^^^^^^^^^^^ + + .. c:function:: inline unsigned int domain_tot_pages(struct domain *d) + + :param d: The domain for which to calculate the total pages. + :type d: struct domain * + :returns: The total pages allocated to the domain. + + This function is used for validating that an allocation and the domain's + claims do not exceed :c:member:`domain.max_pages`.
docs/designs/claims/design.rst new file +243 -0
243 lines not on this page · raw message
docs/designs/claims/development.rst new file +197 -0
197 lines not on this page · raw message
docs/designs/claims/implementation.rst new file +393 -0
393 lines not on this page · raw message
docs/designs/claims/index.rst new file +48 -0
48 lines not on this page · raw message
docs/designs/claims/installation.rst new file +70 -0
70 lines not on this page · raw message
docs/designs/claims/invariants.mmd new file +35 -0
@@ -0,0 +1,35 @@ +%% SPDX-License-Identifier: CC-BY-4.0 +%% Claim variables and their Invariants +flowchart TD + +subgraph "Access under the <tt><b>heap_lock</b></tt> only:" + direction TB + Memory_of_Nodes --" Contribute to "--> Overall_Memory + Overall_Memory --" Available to "--> Memory_of_Domains +end + +subgraph Memory_of_Nodes["Per-node claims and available memory"] + direction LR + per_node_claims -->|" less or equal to "| node_avail_pages + per_node_claims["Claims on the node: + <tt>node_outstanding_claims[n]"] + node_avail_pages["Available pages on the node: + <tt>node_avail_pages[n]"] +end + +subgraph Overall_Memory["Overall claims and available memory"] + direction LR + outstanding -->|" less or equal to "| avail_pages + outstanding["Total claims on the host: + <tt>outstanding_claims"] + avail_pages["Available pages on the host: + <tt>total_avail_pages"] +end + +subgraph Memory_of_Domains["Per-domain claims and available memory"] + direction LR + claims -->|" less or equal to "| available_memory_for_domains + claims["Claims of the domain:<br><tt>d->outstanding_pages"] + available_memory_for_domains["Available pages:<br><tt>node_avail_pages[n] + total_avail_pages"] +end
docs/designs/claims/performance.rst new file +33 -0
@@ -0,0 +1,33 @@ +.. SPDX-License-Identifier: CC-BY-4.0 + +Performance +*********** + +The single-node claims implementation which is the basis of the +NUMA claims v4 series and the multi-node claim sets design forms +the groundwork for the NUMA design and implementation in XenServer 9. + +An early version of it is available as the XenServer XS9 preview +release: https://www.xenserver.com/downloads/xs9-preview. +The performance of this release has been tested in real +customer environments with customer workloads. + +On dual-socket Intel servers, the **average aggregate CPU usage across +all VMs at peak times** (peak user load) was **~16% less** than with +`XenServer 8.4` (overall average at all times **~8.5% less**) compared +to the previous release, which is a significant improvement in CPU +efficiency for memory-intensive workloads, attributed to the +improved NUMA placement enabled by `NUMA-aware claims`. + +The customer's response time metric from their application, which is the +key measure the customer uses for end user observed performance, showed +an ~8% improvement, matching the improvement in average CPU usage. + +These numbers were observed using `Intel dual-socket servers`. +The performance benefits with AMD servers (judging by preliminary tests) are +expected to be considerably higher than the results with dual-socket Intel +servers. + +The multi-node claim sets design is expected to extend these benefits +to configurations that require claiming memory from multiple NUMA nodes +adjacent to each other for optimal performance.
docs/designs/claims/protection.rst new file +200 -0
200 lines not on this page · raw message
docs/designs/claims/redeeming.rst new file +71 -0
71 lines not on this page · raw message
docs/designs/claims/terminology.rst new file +138 -0
139 lines not on this page · raw message
docs/designs/claims/use-cases.rst new file +39 -0
@@ -0,0 +1,39 @@ +.. SPDX-License-Identifier: CC-BY-4.0 + +######### +Use Cases +######### + +.. glossary:: + + Parallel :term:`domain builds` + + When many domains need to be created and built, many :term:`domain builders` + compete for the same pools of memory, which can lead to inefficient NUMA + placement of :term:`guest physical memory` and thus suboptimal performance + for the domains. + + NUMA-aware claims can help solve this problem and ensure that memory + is available on the appropriate NUMA nodes. + + Domain builds + + The process of constructing and configuring :term:`domains` by + :term:`domain builders`, which includes installing :term:`claims`, + :term:`populating` memory, and setting up other resources before the + :term:`domains` are started. When multiple :term:`domain builders` can + run in parallel, this is referred to as parallel domain builds, which can + benefit from NUMA-aware claims because the domain builders are competing for + the same pools of memory on the NUMA nodes. + + Boot storms + + It is common for many domains to be booted at the same time, such as during + system startup or when large numbers of domains need to be started. + + Parallel migrations + + Similar to :term:`boot storms`, except that the domains are being migrated + instead of booted, which can happen when other hosts are being drained + for maintenance (host evacuation) or when workloads are being rebalanced + across hosts.
docs/designs/index.rst +1 -0
@@ -14,3 +14,4 @@ and for those interested in the internal workings of Xen. launch/index cache-coloring + claims/index
docs/glossary.rst +9 -3
@@ -12,6 +12,7 @@ Glossary to create and manage other domains on the system. domain + domains A domain is Xen's unit of resource ownership, and generally has at the minimum some RAM and virtual CPUs.
@@ -58,13 +59,18 @@ Glossary In the code, "guest context" and "guest state" is considered in terms of the CPU architecture, and contrasted against hypervisor context/state. - In this case, it refers to all code running lower privilege privilege - level the hypervisor. As such, it covers all domains, including ones + In this case, it refers to all code running lower privilege level than + the hypervisor. As such, it covers all domains, including ones providing system services. hardware domain A :term:`domain`, commonly dom0, which shares responsibility with Xen about the system as a whole. - By default it gets all devices, including all disks and network cards, so + By default, it gets all devices, including all disks and network cards, and is responsible for multiplexing guest I/O. + + hypercall + hypercalls + A mechanism for a :term:`guest` to request services from the hypervisor. + Hypercalls are analogous to system calls in a traditional operating system.
docs/guest-guide/dom/DOMCTL_claim_memory-data.mmd new file +43 -0
43 lines not on this page · raw message
docs/guest-guide/dom/DOMCTL_claim_memory-seqdia.mmd new file +23 -0
@@ -0,0 +1,23 @@ +%% SPDX-License-Identifier: CC-BY-4.0 +sequenceDiagram + +actor DomainBuilder +participant OcamlStub as OCaml stub for<br>xc_domain<br>claim_memory +participant Libxc as xc_domain<br>claim_memory +participant Domctl as XEN_DOMCTL<br>claim_memory +#participant DomainLogic as claim_memory +participant Alloc as domain<br>set<br>outstanding_pages + +DomainBuilder->>OcamlStub: claims +OcamlStub->>OcamlStub: marshall claims -----> OCaml to C +OcamlStub->>Libxc: claims + +Libxc->>Domctl: do_domctl + +Domctl->>Domctl: copy_from_guest(claim) +Domctl->>Domctl: validate claim +Domctl->>Alloc: set<br>outstanding_pages +Alloc-->>Domctl: result +Domctl-->>Libxc: rc +Libxc-->>OcamlStub: rc +OcamlStub-->>DomainBuilder: claim_result
docs/guest-guide/dom/DOMCTL_claim_memory-workflow.mmd new file +23 -0
@@ -0,0 +1,23 @@ +%% SPDX-License-Identifier: CC-BY-4.0 +sequenceDiagram + +participant Toolstack +participant Xen +participant NUMA Node memory + +Toolstack->>Xen: XEN_DOMCTL_createdomain +Toolstack->>Xen: XEN_DOMCTL_max_mem(max_pages) + +Toolstack->>Xen: XEN_DOMCTL_claim_memory(pages, node) +Xen->>NUMA Node memory: Claim pages on node +Xen-->>Toolstack: Claim granted + +Toolstack->>Xen: XEN_DOMCTL_set_nodeaffinity(node) + +loop Populate domain memory + Toolstack->>Xen: XENMEM_populate_physmap(memflags:node) + Xen->>NUMA Node memory: alloc from claimed node +end + +Toolstack->>Xen: XEN_DOMCTL_claim_memory(0, NO_NODE) +Xen-->>Toolstack: Remaining claims released
docs/guest-guide/dom/DOMCTL_claim_memory.rst new file +221 -0
221 lines not on this page · raw message
docs/guest-guide/dom/index.rst new file +14 -0
@@ -0,0 +1,14 @@ +.. SPDX-License-Identifier: CC-BY-4.0 + +`DOMCTL Hypercalls` +=================== + +Through `DOMCTL` `hypercalls`, `toolstacks` in privileged domains can perform +operations related to domain management. This includes operations such as +creating, destroying, and modifying domains, as well as querying domain +information. + +.. toctree:: + :maxdepth: 2 + + DOMCTL_claim_memory
docs/guest-guide/index.rst +23 -0
@@ -3,6 +3,29 @@ Guest documentation =================== +Xen exposes a set of hypercalls that allow domains and toolstacks in +privileged contexts (such as Dom0) to request services from the hypervisor. + +Through these hypercalls, privileged domains can perform privileged operations +such as querying system information, memory and domain management, +and enabling inter-domain communication via shared memory and event channels. + +These hypercalls are documented in the following sections, grouped by their +functionality. Each section provides an overview of the hypercalls, their +parameters, and examples of how to use them. + +Hypercall API documentation +--------------------------- + +.. toctree:: + :maxdepth: 2 + + dom/index + mem/index + +Hypercall ABI documentation +--------------------------- + .. toctree:: :maxdepth: 2
docs/guest-guide/mem/XENMEM_claim_pages.rst new file +102 -0
102 lines not on this page · raw message
docs/guest-guide/mem/index.rst new file +12 -0
@@ -0,0 +1,12 @@ +.. SPDX-License-Identifier: CC-BY-4.0 + +`MEMCTL Hypercalls` +------------------- + +The XENMEM hypercall interface allows guests to perform various control +operations related to memory management. + +.. toctree:: + :maxdepth: 2 + + XENMEM_claim_pages
Signature · 1 line
2.39.5