mm_struct 中的 mm和active_mm

Hello Roy
> I fail to understand the difference between task->mm and
> task->active_mm. I've noticed that upon forking a task, both mm and
> active_mm get the same memory descriptor.

Well, here is my understanding. task_struct->mm points to memory 
descriptor which is unique to each process (unless they are on the same 
thread group, forked with CLONE_VM). active_mm points to the *actual* 
memory descriptor used by the process when it is executed.

So why it is separated? IMHO the reason is to identify which process is 
kernel thread (doesn't own a process address space) and which one is 
normal process (owns a process address space). 

As you can see on functions related with context switching, by checking task_struct->mm, 
the scheduler can decide whether it is going to switch onto kernel 
thread or not. if it is NULL, then the process doesn't have process address space, in 
other word this is a kernel thread. But you also aware that even kernel 
threads don't acess user space memory, it still needs to access kernel 
space. because kernel space is 100% identical for every process, kernel 
thread can freely use memory descriptor (mm) owned by previously 
running process. All the kernel thread needed is page tables 
referencing toward virtual address bigger than PAGE_OFFSET, other are 
simply ignored by it is assumed that kernel thread doesn't need to 
access user space (perhaps it is somehow can be abused?)

Hope it helps answering your question

regards

Mulyadi

 

转载至:http://www.voidcn.com/article/p-nnejnvzg-bqh.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值