current-> mm在Linux内核中为NULL [英] current->mm gives NULL in linux kernel
问题描述
我想遍历页面表,所以我已经访问了current-> mm,但是它给出了NULL值.
I would like to walk the page table, so I have accessed the current->mm, but it gives NULL value.
我正在使用Linux内核3.9,但我不知道current-> mm怎么可能为零.
I'm working on linux kernel 3.9 and I don't understand how could current->mm is zero.
在这里我想念什么吗?
推荐答案
这表示您在内核线程中.
It means you are in a kernel thread.
在Linux中,内核线程没有mm结构.内核线程从前一个用户线程借用mm,并将其记录在active_mm中.因此,您应该改用active_mm .
In Linux, kernel threads have no mm struct. A kernel thread borrows the mm from the previous user thread and records it in active_mm. So you should use active_mm instead.
更多详细信息:
在/kernel/sched/core.c
中,您可以找到以下代码:
in /kernel/sched/core.c
you can find the following code:
static inline void
context_switch(struct rq *rq, struct task_struct *prev,
struct task_struct *next)
{
...
if (!mm) {
next->active_mm = oldmm;
atomic_inc(&oldmm->mm_count);
enter_lazy_tlb(oldmm, next);
} else
switch_mm(oldmm, mm, next);
...
}
如果下一个线程没有mm(内核线程),则调度程序将不会切换mm,而只会重用上一个线程的mm.
If the next thread has no mm (a kernel thread), the scheduler would not switch mm and just reuse the mm of the previous thread.
这篇关于current-> mm在Linux内核中为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!