Current-> mm gives NULL in linux kernel

I would like to go through the page table, so I got access to current-> mm, but it gives a NULL value.

I am working on linux kernel 3.9 and I do not understand how the current → mm is zero.

Is there something I missed here?

+4
source share
2 answers

This means that you are in the kernel thread.

In linux, kernel threads do not have a mm structure. The kernel thread takes mm from the previous user thread and writes it to 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 does not have mm (kernel thread). The scheduler would not switch the millimeter and would simply reuse the millimeter of the previous thread.

+11
source

Assignment of active_mm is required: a call to switch_mm() , which causes the TLB to be mm_struct , is eliminated by "borrowing" the mm_struct used by the previous task and putting it in task_ struct→active_mm . This method has greatly improved context switching time.

+1
source

Source: https://habr.com/ru/post/1484950/


All Articles