v1
2026-08-01
引入Page Alloc Hogger调试工具 · v1
引入Page Alloc Hogger,通过debugfs分配内存页面以模拟低内存条件。
原始补丁链接
子 Patch(16)
1/16
mm: Page Alloc Hogger module
创建Page Alloc Hogger模块骨架,在debugfs下建立mm目录,用于后续暴露页面分配器状态。
2/16
mm: Define structs for allocation requests and store allocations
定义req_alloc和page_alloc结构体,分别保存分配请求信息和已分配页的元数据及关联文件。
3/16
mm: Define the caches for the structs req_alloc and page_alloc
为req_alloc和page_alloc结构体定义并初始化kmem_cache,用于管理动态分配的内存对象。
4/16
mm: Define function to create a dir for each online node
实现函数为每个在线NUMA节点在debugfs下创建目录,用于按节点组织分配信息。
5/16
mm: Define function to create a dir for populated zone
实现函数为每个有内存的zone在节点目录下创建子目录,排除ZONE_DEVICE。
6/16
mm: Define function to create a dir for each page order
实现函数在zone目录下为每个页面阶数创建子目录,用于按阶数组织分配。
7/16
mm: Define function to create a dir for each migrate type
实现函数在order目录下为每个迁移类型创建子目录,排除MIGRATE_ISOLATE和暂不支持MIGRATE_CMA。
8/16
mm: Define function that creates the "nr_pages_allocs" file
实现nr_pages_allocs文件,用户写入数量后触发指定阶数/zone/迁移类型的页面分配。
9/16
mm: Read the nr_pages_allocs value given by user
读取用户写入nr_pages_allocs的值并验证为unsigned long,分配数组存储分配ID用于后续释放。
10/16
mm: Set the selected zone in gfp_t flags
根据用户选择的zone设置GFP flags中的__GFP_HIGHMEM和__GFP_DMA等标志,确保分配来自正确zone。
11/16
mm: Sets the migrate type in gfp_t flags
根据用户选择的迁移类型设置GFP flags中的迁移类型标志,确保分配来自正确迁移列表。
12/16
mm: Define the make_alloc() function
实现make_alloc()核心函数,调用Buddy分配器分配页面,存储元数据至xarray,失败时清理。
13/16
mm: Create the file asociated with an allocation
为每个成功分配创建debugfs文件,文件名由原子计数器生成,用户通过删除文件触发页面释放。
14/16
mm: Free pages, remove files and clean cache when one alloc fails
当批量分配中任一分配失败时,释放已分配页面、删除已创建文件、清理kmem cache和xarray条目。
15/16
mm: Create the "free" file to release the previously allocated pages
创建free文件,用户写入文件名即可释放对应分配,通过file_operations实现页面释放逻辑。
16/16
mm: Release resources when the page alloc hogger module exits
模块退出时释放所有已分配页面、清除xarray条目,确保资源完全回收。