v7
2026-07-30
优化 ZONE_DEVICE memmap 初始化 · v7
补丁系列通过模板和memcpy_nontemporal减少ZONE_DEVICE memmap初始化开销,需补充用户态收益细节。
原始补丁链接
子 Patch(9)
1/9
mm: fix stale ZONE_DEVICE refcount comment
修正 _init_zone_device_page() 注释中过时的 MEMORY_TYPE* 命名,更新为当前策略:GENERIC 类型在 free 路径恢复 refcount 为 1,其他类型从 0 开始。
2/9
mm: factor zone-device page init helpers out of __init_zone_device_page
从 __init_zone_device_page() 中拆分出 pagemap_requires_refcount_reset()、__zone_device_page_init() 和 zone_device_page_init_slow(),为后续 patch 提供可复用的 helper 边界。
3/9
mm: add a set_page_section_from_pfn() helper
添加 set_page_section_from_pfn() helper,封装 #ifdef SECTION_IN_PAGE_FLAGS 的 section 位更新逻辑,避免调用者重复开写该条件编译。
4/9
mm: add a template-based fast path for zone-device page init
通过模板化加速 ZONE_DEVICE head-page 初始化:先用 slow path 生成模板,刷新 PFN 相关字段后 memcpy 到目标页,减少重复初始化开销。
5/9
mm: extend the template fast path to zone-device compound tails
扩展模板化 fast path 到 compound tail 页:分别构建 head/tail 模板,tail 模板复用跨 compound 范围,避免逐个调用 zone_device_page_init_slow()。
6/9
string: introduce memcpy_nontemporal()
引入 memcpy_nontemporal() 用于写一次拷贝场景,x86 上包装 memcpy_flushcache(),通用后备为 memcpy() 以保留 FORTIFY 覆盖。
7/9
x86/string: extend memcpy_flushcache() fixed-size fastpaths
为 memcpy_flushcache() 添加 32/48/64/80/96 字节的 MOVNTI 内联路径,使 ZONE_DEVICE 模板拷贝的固定大小 struct page 拷贝避免回退到 __memcpy_flushcache()。
8/9
mm: use memcpy_nontemporal() in zone-device template copies
将 ZONE_DEVICE 模板拷贝路径从 memcpy() 切换为 memcpy_nontemporal(),减少写分配流量和缓存污染,因为 memmap 初始化是写一次模式。
9/9
mm: always use the zone-device template init path
无条件使用模板化初始化路径,移除 page_ref_set tracepoint 的 opt-out 分支,简化代码;tracepoint 不再观察初始化时的 refcount 赋值。