mm/damon/ops-common.c
Source file repositories/reference/linux-study-clean/mm/damon/ops-common.c
File Facts
- System
- Linux kernel
- Corpus path
mm/damon/ops-common.c- Extension
.c- Size
- 10214 bytes
- Lines
- 433
- 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/migrate.hlinux/mmu_notifier.hlinux/page_idle.hlinux/pagemap.hlinux/rmap.hlinux/swap.hlinux/leafops.h../internal.hops-common.h
Detected Declarations
function damon_ptep_mkoldfunction damon_pmdp_mkoldfunction damon_hot_scorefunction damon_cold_scorefunction damon_folio_mkold_onefunction damon_folio_mkoldfunction damon_folio_young_onefunction damon_folio_youngfunction damos_folio_filter_matchfunction __damon_migrate_folio_listfunction damon_migrate_folio_listfunction damon_migrate_pagesfunction damos_ops_has_filter
Annotated Snippet
if (pvmw.pte) {
pte = ptep_get(pvmw.pte);
/*
* PFN swap PTEs, such as device-exclusive ones, that
* actually map pages are "old" from a CPU perspective.
* The MMU notifier takes care of any device aspects.
*/
*accessed = (pte_present(pte) && pte_young(pte)) ||
!folio_test_idle(folio) ||
mmu_notifier_test_young(vma->vm_mm, addr);
} else {
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
pmd_t pmd = pmdp_get(pvmw.pmd);
*accessed = (pmd_present(pmd) && pmd_young(pmd)) ||
!folio_test_idle(folio) ||
mmu_notifier_test_young(vma->vm_mm, addr);
#else
WARN_ON_ONCE(1);
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
}
if (*accessed) {
page_vma_mapped_walk_done(&pvmw);
break;
}
}
/* If accessed, stop walking */
return *accessed == false;
}
bool damon_folio_young(struct folio *folio)
{
bool accessed = false;
struct rmap_walk_control rwc = {
.arg = &accessed,
.rmap_one = damon_folio_young_one,
.anon_lock = folio_lock_anon_vma_read,
};
if (!folio_mapped(folio) || !folio_raw_mapping(folio)) {
if (folio_test_idle(folio))
return false;
else
return true;
}
if (!folio_trylock(folio))
return false;
rmap_walk(folio, &rwc);
folio_unlock(folio);
return accessed;
}
bool damos_folio_filter_match(struct damos_filter *filter, struct folio *folio)
{
bool matched = false;
struct mem_cgroup *memcg;
size_t folio_sz;
switch (filter->type) {
case DAMOS_FILTER_TYPE_ANON:
matched = folio_test_anon(folio);
break;
case DAMOS_FILTER_TYPE_ACTIVE:
matched = folio_test_active(folio);
break;
case DAMOS_FILTER_TYPE_MEMCG:
rcu_read_lock();
memcg = folio_memcg_check(folio);
if (!memcg)
matched = false;
else
matched = filter->memcg_id == mem_cgroup_id(memcg);
rcu_read_unlock();
break;
case DAMOS_FILTER_TYPE_YOUNG:
matched = damon_folio_young(folio);
if (matched)
damon_folio_mkold(folio);
break;
case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE:
folio_sz = folio_size(folio);
matched = filter->sz_range.min <= folio_sz &&
folio_sz <= filter->sz_range.max;
break;
case DAMOS_FILTER_TYPE_UNMAPPED:
Annotation
- Immediate include surface: `linux/migrate.h`, `linux/mmu_notifier.h`, `linux/page_idle.h`, `linux/pagemap.h`, `linux/rmap.h`, `linux/swap.h`, `linux/leafops.h`, `../internal.h`.
- Detected declarations: `function damon_ptep_mkold`, `function damon_pmdp_mkold`, `function damon_hot_score`, `function damon_cold_score`, `function damon_folio_mkold_one`, `function damon_folio_mkold`, `function damon_folio_young_one`, `function damon_folio_young`, `function damos_folio_filter_match`, `function __damon_migrate_folio_list`.
- 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.