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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With