Where is task_struct stored?

Task_struct is used to store the necessary process information by the kernel. Thanks to this structure, the kernel can pause the process and continue to implement it after some time. But my question is: where is this task_struct stored in memory (I read about the kernel stack, is it the one that is in the kernel space of the virtual address space?)? where does the kernel store a pointer to this structure and this structure after the process is paused?

I would appreciate if you would give some links to the resources where he described.

PS. I forgot to say that we are talking about the Linux kernel.

+4
source share
4 answers

Linux task_struct kmem_cache. , fork.c , :

#define alloc_task_struct_node(node) \
             kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node)
static struct kmem_cache *task_struct_cachep;

, , . , x86 (arch/x86/include/asm/current.h):

static __always_inline struct task_struct *get_current(void)
{
    return percpu_read_stable(current_task);
}

PowerPC (arch/powerpc/include/asm/current.h):

static inline struct task_struct *get_current(void)
{
    struct task_struct *task;

    __asm__ __volatile__("ld %0,%1(13)"
        : "=r" (task)
        : "i" (offsetof(struct paca_struct, __current)));

    return task;
}

Elixir Cross Reference, .

+4

task_struct slab. 8kb 4kb, .

0x86, thread_info, / task_struct. task_struct , 8kb, .

+1

Kernel structures that handle the context of a thread and a process are OS dependent. As a rule, they will be allocated from an incomprehensible pool, as well as collections of pointers for them, which are used to manage them.

0
source

From the point of view of the virtual memory system, task_struct is allocated by the Slab allocator, so that it is in kernel space . More specifically, slab memory can be directly mapped to the cache.

0
source

All Articles