mm/hugetlb_sysfs.c
Source file repositories/reference/linux-study-clean/mm/hugetlb_sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
mm/hugetlb_sysfs.c- Extension
.c- Size
- 11979 bytes
- Lines
- 503
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/swap.hlinux/page_owner.hlinux/page-isolation.hhugetlb_vmemmap.hhugetlb_internal.h
Detected Declarations
struct node_hstatefunction nr_hugepages_show_commonfunction nr_hugepages_store_commonfunction nr_hugepages_showfunction nr_hugepages_storefunction nr_hugepages_mempolicy_showfunction nr_hugepages_mempolicy_storefunction nr_overcommit_hugepages_showfunction nr_overcommit_hugepages_storefunction free_hugepages_showfunction resv_hugepages_showfunction surplus_hugepages_showfunction demote_storefunction demote_size_showfunction demote_size_storefunction hugetlb_sysfs_add_hstatefunction hugetlb_unregister_nodefunction for_each_hstatefunction hugetlb_register_nodefunction for_each_hstatefunction hugetlb_register_all_nodesfunction hugetlb_register_all_nodesfunction for_each_hstate
Annotated Snippet
struct node_hstate {
struct kobject *hugepages_kobj;
struct kobject *hstate_kobjs[HUGE_MAX_HSTATE];
};
static struct node_hstate node_hstates[MAX_NUMNODES];
/*
* A subset of global hstate attributes for node devices
*/
static struct attribute *per_node_hstate_attrs[] = {
&nr_hugepages_attr.attr,
&free_hugepages_attr.attr,
&surplus_hugepages_attr.attr,
NULL,
};
static const struct attribute_group per_node_hstate_attr_group = {
.attrs = per_node_hstate_attrs,
};
/*
* kobj_to_node_hstate - lookup global hstate for node device hstate attr kobj.
* Returns node id via non-NULL nidp.
*/
static struct hstate *kobj_to_node_hstate(struct kobject *kobj, int *nidp)
{
int nid;
for (nid = 0; nid < nr_node_ids; nid++) {
struct node_hstate *nhs = &node_hstates[nid];
int i;
for (i = 0; i < HUGE_MAX_HSTATE; i++)
if (nhs->hstate_kobjs[i] == kobj) {
if (nidp)
*nidp = nid;
return &hstates[i];
}
}
BUG();
return NULL;
}
/*
* Unregister hstate attributes from a single node device.
* No-op if no hstate attributes attached.
*/
void hugetlb_unregister_node(struct node *node)
{
struct hstate *h;
struct node_hstate *nhs = &node_hstates[node->dev.id];
if (!nhs->hugepages_kobj)
return; /* no hstate attributes */
for_each_hstate(h) {
int idx = hstate_index(h);
struct kobject *hstate_kobj = nhs->hstate_kobjs[idx];
if (!hstate_kobj)
continue;
if (h->demote_order)
sysfs_remove_group(hstate_kobj, &hstate_demote_attr_group);
sysfs_remove_group(hstate_kobj, &per_node_hstate_attr_group);
kobject_put(hstate_kobj);
nhs->hstate_kobjs[idx] = NULL;
}
kobject_put(nhs->hugepages_kobj);
nhs->hugepages_kobj = NULL;
}
/*
* Register hstate attributes for a single node device.
* No-op if attributes already registered.
*/
void hugetlb_register_node(struct node *node)
{
struct hstate *h;
struct node_hstate *nhs = &node_hstates[node->dev.id];
int err;
if (!hugetlb_sysfs_initialized)
return;
if (nhs->hugepages_kobj)
return; /* already allocated */
nhs->hugepages_kobj = kobject_create_and_add("hugepages",
Annotation
- Immediate include surface: `linux/swap.h`, `linux/page_owner.h`, `linux/page-isolation.h`, `hugetlb_vmemmap.h`, `hugetlb_internal.h`.
- Detected declarations: `struct node_hstate`, `function nr_hugepages_show_common`, `function nr_hugepages_store_common`, `function nr_hugepages_show`, `function nr_hugepages_store`, `function nr_hugepages_mempolicy_show`, `function nr_hugepages_mempolicy_store`, `function nr_overcommit_hugepages_show`, `function nr_overcommit_hugepages_store`, `function free_hugepages_show`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.