我目前正在为学校制作一个项目,我们必须在 linux 内核中实现一个新的 sys 调用来计算这样的结构中的页面错误数
struct pfstat {
int stack_low; //Number of times the stack was expanded after a page fault
int transparent_hugepage_fault; //Number of huge page transparent PMD fault
int anonymous_fault; //Normal anonymous page fault
int file_fault; //Normal file-backed page fault
int swapped_back; //Number of fault that produced a read-from swap to put back the page online
int copy_on_write; //Normal of fault which backed a copy-on-write;
int fault_alloced_page; //Number of normal pages allocated due to a page fault (no matter the code path if it was for an anonymous fault, a cow, ...).
}
并使用 PID 访问它。我也应该能够在 pfstat 模式下设置任务。我已经通过在其中插入 pfstat 并添加 pfmode 来修改 task_struct。我的问题是我真的不明白在哪里可以找到处理这些不同页面错误的代码,从而增加那里的值。
我在arch/x86/mm/fault.c中找到了do_page_fault ,但它似乎无法处理所有这些错误。我是否还应该修改一些功能,例如do_anonymous_page、do_linear_fault、do_swap_page、do_nonlinear_fault、do_wp_page还是我错过了一些理解?
总而言之,我只是找不到应该增加所有结构成员的代码。
编辑:我使用的是内核版本 4.4.50。