我正在开发一个需要在Linux内核中进行大量修改的项目。在其中一个修改中,我必须改变页面错误处理程序的工作方式。我希望拦截来自特定进程的页面错误,并通过从另一台机器复制数据来满足它们。
作为第一步,我想写一些实验代码,可以帮助我理解Linux如何满足页面错误,以及它如何告诉进程现在无法提供页面错误,它需要做一个稍后重试。
所以,我想以一种帮助我理解上述所有内容的方式修改handle_mm_fault
。像这样:
int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long address, unsigned int flags)
{
/* some code */
if(current->pid == my_target_pid)
{
/*
1. Chose randomly between 1 and 2 -> rand_num
2. if rand_num from (1) is 1 then allocate a block of memory, write 'X's to it and then give it to the process and then return.
3. if rand_num from (1) is 2 then tell process to come back later and then return.
*/
}
/* rest of handle_mm_fault for all other process here */
}
答案 0 :(得分:1)
您可以查看struct vm_operations_struct
。其功能成员'故障'用于处理页面故障情况
答案 1 :(得分:0)
您描述的问题听起来像是要求数据中止的页面。 首先,由于来自内核空间或用户空间的无效页面映射,可能会发生数据中止。 handle_mm_fault是修复linux中用户空间页表的子例程。根据我的理解,您的设计必须涵盖以下内容。