一. Android下用户态swap的意义
二. Android下用户态swap的实现方法
1. 首先实现系统调用swap_process
(在Andriod的内核层实现系统调用,可以参考我前面的文章。)
2. $kernel/mm/swap_state.c
定义系统调用函数swap_process,参数为pid(用户层传过来的进程id)
/**
* swap inactive pages of process with pid
*/
SYSCALL_DEFINE1(swap_process, pid_t, pid)
{
struct task_struct* p = NULL;
LIST_HEAD(pagelist);
unsigned long nr_reclaimed_pages = 0;
//1. find the process ds() through pid
printk(KERN_INFO "user pid: %d\n", pid);
p = find_task_by_pid_ns(pid, current->nsproxy->pid_ns);
if(NULL == p)
{
printk(KERN_ERR "+++could not find task_struct with the pid+++\n");
return 0;
}
//2. filter the inactive pages and add them to swap cache
traverse_pages(p, &pagelist);
//3. swap out pages
if(!list_empty(&pagelist)){
//path: mm/vmscan.c
nr_reclaimed_pag

本文探讨了在Android系统中实现用户态swap的重要性,并详细介绍了实现步骤,包括在内核层创建系统调用swap_process,以及如何遍历进程地址空间进行页面换出操作,重点关注与Linux内核和Android操作系统的交互。
最低0.47元/天 解锁文章
2011

被折叠的 条评论
为什么被折叠?



