mm/khugepaged.c
Source file repositories/reference/linux-study-clean/mm/khugepaged.c
File Facts
- System
- Linux kernel
- Corpus path
mm/khugepaged.c- Extension
.c- Size
- 77249 bytes
- Lines
- 2919
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/sched.hlinux/sched/mm.hlinux/mmu_notifier.hlinux/rmap.hlinux/swap.hlinux/mm_inline.hlinux/kthread.hlinux/khugepaged.hlinux/freezer.hlinux/mman.hlinux/hashtable.hlinux/userfaultfd_k.hlinux/page_idle.hlinux/page_table_check.hlinux/rcupdate_wait.hlinux/leafops.hlinux/shmem_fs.hlinux/dax.hlinux/ksm.hlinux/pgalloc.hlinux/backing-dev.hasm/tlb.hinternal.hmm_slot.htrace/events/huge_memory.h
Detected Declarations
struct collapse_controlstruct khugepaged_scanenum scan_resultfunction scan_sleep_millisecs_showfunction __sleep_millisecs_storefunction scan_sleep_millisecs_storefunction alloc_sleep_millisecs_showfunction alloc_sleep_millisecs_storefunction pages_to_scan_showfunction pages_to_scan_storefunction pages_collapsed_showfunction full_scans_showfunction defrag_showfunction defrag_storefunction max_ptes_none_showfunction max_ptes_none_storefunction max_ptes_swap_showfunction max_ptes_swap_storefunction max_ptes_shared_showfunction max_ptes_shared_storefunction pte_none_or_zerofunction hugepage_madvisefunction khugepaged_initfunction khugepaged_destroyfunction collapse_test_exitfunction collapse_test_exit_or_disablefunction hugepage_pmd_enabledfunction __khugepaged_enterfunction khugepaged_enter_vmafunction __khugepaged_exitfunction release_pte_foliofunction release_pte_pagesfunction list_for_each_entry_safefunction __collapse_huge_page_isolatefunction list_for_each_entryfunction GUPfunction __collapse_huge_page_copy_succeededfunction list_for_each_entry_safefunction __collapse_huge_page_copy_failedfunction __collapse_huge_page_copyfunction khugepaged_alloc_sleepfunction collapse_scan_abortfunction alloc_hugepage_khugepaged_gfpmaskfunction collapse_find_target_nodefunction for_each_online_nodefunction collapse_find_target_nodefunction hugepage_vma_revalidatefunction check_pmd_state
Annotated Snippet
struct collapse_control {
bool is_khugepaged;
/* Num pages scanned per node */
u32 node_load[MAX_NUMNODES];
/* Num pages scanned (see khugepaged_pages_to_scan) */
unsigned int progress;
/* nodemask for allocation fallback */
nodemask_t alloc_nmask;
};
/**
* struct khugepaged_scan - cursor for scanning
* @mm_head: the head of the mm list to scan
* @mm_slot: the current mm_slot we are scanning
* @address: the next address inside that to be scanned
*
* There is only the one khugepaged_scan instance of this cursor structure.
*/
struct khugepaged_scan {
struct list_head mm_head;
struct mm_slot *mm_slot;
unsigned long address;
};
static struct khugepaged_scan khugepaged_scan = {
.mm_head = LIST_HEAD_INIT(khugepaged_scan.mm_head),
};
#ifdef CONFIG_SYSFS
static ssize_t scan_sleep_millisecs_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%u\n", khugepaged_scan_sleep_millisecs);
}
static ssize_t __sleep_millisecs_store(const char *buf, size_t count,
unsigned int *millisecs)
{
unsigned int msecs;
int err;
err = kstrtouint(buf, 10, &msecs);
if (err)
return -EINVAL;
*millisecs = msecs;
khugepaged_sleep_expire = 0;
wake_up_interruptible(&khugepaged_wait);
return count;
}
static ssize_t scan_sleep_millisecs_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
return __sleep_millisecs_store(buf, count, &khugepaged_scan_sleep_millisecs);
}
static struct kobj_attribute scan_sleep_millisecs_attr =
__ATTR_RW(scan_sleep_millisecs);
static ssize_t alloc_sleep_millisecs_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%u\n", khugepaged_alloc_sleep_millisecs);
}
static ssize_t alloc_sleep_millisecs_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
{
return __sleep_millisecs_store(buf, count, &khugepaged_alloc_sleep_millisecs);
}
static struct kobj_attribute alloc_sleep_millisecs_attr =
__ATTR_RW(alloc_sleep_millisecs);
static ssize_t pages_to_scan_show(struct kobject *kobj,
struct kobj_attribute *attr,
char *buf)
{
return sysfs_emit(buf, "%u\n", khugepaged_pages_to_scan);
}
static ssize_t pages_to_scan_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
Annotation
- Immediate include surface: `linux/mm.h`, `linux/sched.h`, `linux/sched/mm.h`, `linux/mmu_notifier.h`, `linux/rmap.h`, `linux/swap.h`, `linux/mm_inline.h`, `linux/kthread.h`.
- Detected declarations: `struct collapse_control`, `struct khugepaged_scan`, `enum scan_result`, `function scan_sleep_millisecs_show`, `function __sleep_millisecs_store`, `function scan_sleep_millisecs_store`, `function alloc_sleep_millisecs_show`, `function alloc_sleep_millisecs_store`, `function pages_to_scan_show`, `function pages_to_scan_store`.
- 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.