Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

current->mm gives NULL in linux kernel

I would like to walk the page table, so I have accessed the current->mm, but it gives NULL value.

I'm working on linux kernel 3.9 and I don't understand how could current->mm is zero.

Is there something I miss here?

like image 888
jaeyong Avatar asked Jun 07 '13 02:06

jaeyong


2 Answers

It means you are in a kernel thread.

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.


More details:

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);
    ...
}

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.

like image 120
Naruil Avatar answered Nov 14 '22 20:11

Naruil


Need for active_mm assignment : The call to switch_mm(), which results in a TLB flush, is avoided by “borrowing” the mm_struct used by the previous task and placing it in task_struct→active_mm. This technique has made large improvements to context switches times.

like image 1
ayyappa ch Avatar answered Nov 14 '22 21:11

ayyappa ch