tools/testing/selftests/kvm/include/numaif.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/include/numaif.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/include/numaif.h- Extension
.h- Size
- 2165 bytes
- Lines
- 84
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dirent.hlinux/mempolicy.hkvm_syscalls.h
Detected Declarations
function get_max_numa_nodefunction is_numa_availablefunction is_multi_numa_node_system
Annotated Snippet
#ifndef SELFTEST_KVM_NUMAIF_H
#define SELFTEST_KVM_NUMAIF_H
#include <dirent.h>
#include <linux/mempolicy.h>
#include "kvm_syscalls.h"
KVM_SYSCALL_DEFINE(get_mempolicy, 5, int *, policy, const unsigned long *, nmask,
unsigned long, maxnode, void *, addr, int, flags);
KVM_SYSCALL_DEFINE(set_mempolicy, 3, int, mode, const unsigned long *, nmask,
unsigned long, maxnode);
KVM_SYSCALL_DEFINE(set_mempolicy_home_node, 4, unsigned long, start,
unsigned long, len, unsigned long, home_node,
unsigned long, flags);
KVM_SYSCALL_DEFINE(migrate_pages, 4, int, pid, unsigned long, maxnode,
const unsigned long *, frommask, const unsigned long *, tomask);
KVM_SYSCALL_DEFINE(move_pages, 6, int, pid, unsigned long, count, void *, pages,
const int *, nodes, int *, status, int, flags);
KVM_SYSCALL_DEFINE(mbind, 6, void *, addr, unsigned long, size, int, mode,
const unsigned long *, nodemask, unsigned long, maxnode,
unsigned int, flags);
static inline int get_max_numa_node(void)
{
struct dirent *de;
int max_node = 0;
DIR *d;
/*
* Assume there's a single node if the kernel doesn't support NUMA,
* or if no nodes are found.
*/
d = opendir("/sys/devices/system/node");
if (!d)
return 0;
while ((de = readdir(d)) != NULL) {
int node_id;
char *endptr;
if (strncmp(de->d_name, "node", 4) != 0)
continue;
node_id = strtol(de->d_name + 4, &endptr, 10);
if (*endptr != '\0')
continue;
if (node_id > max_node)
max_node = node_id;
}
closedir(d);
return max_node;
}
static bool is_numa_available(void)
{
/*
* Probe for NUMA by doing a dummy get_mempolicy(). If the syscall
* fails with ENOSYS, then the kernel was built without NUMA support.
* if the syscall fails with EPERM, then the process/user lacks the
* necessary capabilities (CAP_SYS_NICE).
*/
return !get_mempolicy(NULL, NULL, 0, NULL, 0) ||
(errno != ENOSYS && errno != EPERM);
}
static inline bool is_multi_numa_node_system(void)
{
return is_numa_available() && get_max_numa_node() >= 1;
}
#endif /* SELFTEST_KVM_NUMAIF_H */
Annotation
- Immediate include surface: `dirent.h`, `linux/mempolicy.h`, `kvm_syscalls.h`.
- Detected declarations: `function get_max_numa_node`, `function is_numa_available`, `function is_multi_numa_node_system`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.