Linux内核剖析第六周作业

比如进程的状态、进程的标识(PID)等,进程控制块(PCB),vfork和clone的系统调用的入口地址分别是sys,vfork和sys,进程本身不是基本运行单位,是计算机中已运行程序的实体,在Linux系统中fork()通过调用clone系统调用实现其功能,而clone()是通过调用do

澳门京葡网站 4

进度描述

进程描述符(task_struct)

用来说述进程的数据构造,能够清楚为经过的本性。举例进程的图景、进度的标记(PID)等,都被封装在了经过描述符那一个数据布局中,该数据布局被定义为task_struct

经过调节块(PCB)

是操作系统主题中一种数据构造,首要代表经过情状。

进程情状

澳门京葡网站 1

fork()

fork(卡塔尔(قطر‎在父、子进度各再次回到二遍。在父进度中重返子进度的
pid,在子进度中再次来到0。

fork一个子经过的代码

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char * argv[])
{
  int pid;
  /* fork another process */

  pid = fork();
  if (pid < 0) 
  { 
      /* error occurred */
      fprintf(stderr,"Fork Failed!");
      exit(-1);
  } 
  else if (pid == 0) 
  {
      /* child process */
      printf("This is Child Process!\n");
  } 
  else 
  {  
      /* parent process  */
      printf("This is Parent Process!\n");
      /* parent will wait for the child to complete*/
      wait(NULL);
      printf("Child Complete!\n");
  }
}

fork, vfork, clone系统调用的兑现


此文仅用于MOOCLinux内核分析作业

张依依+原创文章转发请注脚出处+《Linux内核深入分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000

新进程推行起源对应的库房状态解析

gdb调节和测量检验深入分析

澳门京葡网站 2

进度制造

总结


fork, vfork和clone的系统调用的入口地址分别是sys_fork,
sys_vfork和sys_clone, 而他们的定义是重视于系统结构的,
而他们最终都调用了_do_fork(linux-4.2在此之前的基本中是do_fork),在_do_fork中通过copy_process复制进度的音信,调用wake_up_new_task将子进度走入调整器中

fork系统调用对应的kernel函数是sys_fork,此函数简单的调用kernel函数_do_fork。三个简化版的_do_fork实施如下:

  1. copy_process(卡塔尔此函数会做fork的大相当多作业,它首要形成讲父进度的运行条件复制到新的子进度,举个例子频限信号管理、文件陈说符和进程的代码数据等。

  2. wake_up_new_task(卡塔尔国。总计此进度的优先级和别的调治参数,将新的经过步向到过程调节队列并设此进程为可被调整的,未来这几个进度能够被进程调整模块调整试行。

简化的copy_process()流程

  1. dup_task_struct(卡塔尔。分配二个新的进度调整块,包含新历程在kernel中的仓库。新的经过调控块会复制父进度的历程调节块,然而因为种种进度都有四个kernel仓库,新历程的旅舍将被设置成新分配的商旅。

  2. 最初化一些新进度的计算音信,如此进程的周转时刻

  3. copy_semundo(卡塔尔国复制父进程的semaphore undo_list到子进度。

  4. copy_files()、copy_fs(卡塔尔国。复制父进度文件系统相关的条件到子进度

  5. copy_sighand()、copy_signal(卡塔尔国。复制父进度频域信号管理有关的条件到子进度。

  6. copy_mm(卡塔尔国。复制父进度内存管理有关的条件到子进度,包含页表、地址空间和代码数据。

  7. copy_thread()/copy_thread_tls。设置子进度的进行蒙受,如子进度运营时各CPU贮存器的值、子进程的kernel栈的原初地址。

  8. sched_fork(卡塔尔。设置子进程调治相关的参数,即子进度的周转CPU、初步时间片长度和静态优先级等。

  9. 将子进程步向到全局的经过队列中

  10. 设置子进程的长河组ID和对话期ID等。

简易的说,copy_process(卡塔尔国便是将父进程的运行遭逢复制到子进程并对某个子进度特定的条件做相应的调动。

其余应用程序使用系统调用exit()来终结二个历程,此系统调用接纳多少个脱离原因代码,父进度能够应用wait()系统调用来取得此代码,进而知道子进度退出的缘由。对应到kernel,此系统调用sys_exit_group(State of Qatar,它的为主流程如下:

  1. 将复信号SIGKILL出席到任何线程的实信号队列中,并提示这一个线程。

  2. 此线程实行do_exit()来退出。

do_exit(卡塔尔(قطر‎实现线程退出的职务,其主要成效是将线程占用的系统能源释放,do_exit(卡塔尔(قطر‎的核心流程如下:

  1. 将经过内部存储器管理相关的能源自由

  2. 将经过ICP semaphore相关能源自由

  3. __exit_files()、__exit_fs(卡塔尔(قطر‎。将经过文件管理相关的能源自由。

  4. exit_thread(卡塔尔(قطر‎。只要目标是自由平台相关的局地财富。

  5. exit_澳门京葡网站,notify(卡塔尔。在Linux中经过退出时要将其脱离的由来告诉父进程,父进度调用wait(卡塔尔国系统调用后会在一个守候队列上睡觉。

  6. schedule(卡塔尔(قطر‎。调用进度调整器,因为此进程早就退出,切换成任何进度。

进度的创办到实施进度如下图所示

澳门京葡网站 3

版权申明:本文为博主原创小说 && 转发请著名出处 @

子进度试行ret_from_fork

ENTRY(ret_from_fork)
    CFI_STARTPROC
    pushl_cfi %eax
    call schedule_tail
    GET_THREAD_INFO(%ebp)
    popl_cfi %eax
    pushl_cfi $0x0202       # Reset kernel eflags
    popfl_cfi
    jmp syscall_exit
    CFI_ENDPROC
END(ret_from_fork)

子进度是从哪最初奉行的?

当推行到

p->thread.ip = (unsigned long) ret_from_fork;
//调节到子进度时的率先条指令地址。

时,即子进度获得CPU时它从那一个职分上马实施的。

而实行那条语句

*childregs = *current_pt_regs(State of Qatar; //复制内核旅舍

承保了新进度的实行起源和根本饭馆的一致性。
如下图gdb追踪所示。

澳门京葡网站 4

sched_fork 流程

core.c

int sched_fork(unsigned long clone_flags, struct task_struct *p)
{
    unsigned long flags;
    int cpu = get_cpu();

    __sched_fork(clone_flags, p);

    //将子进程状态设置为 TASK_RUNNING
    p->state = TASK_RUNNING;

    //……

    //为子进程分配 CPU
    set_task_cpu(p, cpu);

    put_cpu();
    return 0;
}

大家得以看来sched_fork差不离产生了两项主要专业,一是将子进度情况设置为
TASK_RUNNING,二是为其分配 CPU

sys_fork的实现


不等体系构造下的fork完成sys_fork首假诺透过评释会集区分,
在大部系统布局上, 标准的fork实现格局与如下

最早落成

架构 实现
arm arch/arm/kernel/sys_arm.c, line 239
i386 arch/i386/kernel/process.c, line 710
x86_64 arch/x86_64/kernel/process.c, line 706
asmlinkage long sys_fork(struct pt_regs regs)
{
    return do_fork(SIGCHLD, regs.rsp, &regs, 0);
}

 

新版本

#ifdef __ARCH_WANT_SYS_FORK
SYSCALL_DEFINE0(fork)
{
#ifdef CONFIG_MMU
        return _do_fork(SIGCHLD, 0, 0, NULL, NULL, 0);
#else
        /* can not support in nommu mode */
        return -EINVAL;
#endif
}
#endif

 

小编们能够看来唯一利用的申明是SIGCHLD。那象征在子进度终止后将发送非复信号SIGCHLD信号文告父进度,

鉴于写时复制(COW卡塔尔国本事, 最早父亲和儿子进度的栈地址相仿,
不过只要操作栈地址闭并写入数据,
则COW机制会为各种进度分别创设一个新的栈别本

如果do_fork成功, 则新建进程的pid作为系统调用的结果回到, 不然赶回错误码

新进程是从哪儿伊始推行的?

在后边的深入深入分析中,聊到copy_process中的copy_thread()函数,正是那些函数决定了子进度从系统调用中返回后的推行.

int copy_thread(unsigned long clone_flags, unsigned long sp,
    unsigned long arg, struct task_struct *p)
{
    ...

    *childregs = *current_pt_regs();
    childregs->ax = 0;
    if (sp)
        childregs->sp = sp;

    p->thread.ip = (unsigned long) ret_from_fork;

    ...
}

参谋资料

《Linux内核设计与落到实处》原书第三版

Sawoom原创文章转发请申明出处
《Linux内核深入分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000

大致流程

fork
通过0×80暂停(系统调用)来陷入内核,由系统提供的相应系统调用来成功进程的创始。

fork.c

//fork
#ifdef __ARCH_WANT_SYS_FORK
SYSCALL_DEFINE0(fork)
{
#ifdef CONFIG_MMU
    return do_fork(SIGCHLD, 0, 0, NULL, NULL);
#else
    /* can not support in nommu mode */
    return -EINVAL;
#endif
}
#endif

//vfork
#ifdef __ARCH_WANT_SYS_VFORK
SYSCALL_DEFINE0(vfork)
{
    return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0,
            0, NULL, NULL);
}
#endif

//clone
#ifdef __ARCH_WANT_SYS_CLONE
#ifdef CONFIG_CLONE_BACKWARDS
SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
         int __user *, parent_tidptr,
         int, tls_val,
         int __user *, child_tidptr)
#elif defined(CONFIG_CLONE_BACKWARDS2)
SYSCALL_DEFINE5(clone, unsigned long, newsp, unsigned long, clone_flags,
         int __user *, parent_tidptr,
         int __user *, child_tidptr,
         int, tls_val)
#elif defined(CONFIG_CLONE_BACKWARDS3)
SYSCALL_DEFINE6(clone, unsigned long, clone_flags, unsigned long, newsp,
        int, stack_size,
        int __user *, parent_tidptr,
        int __user *, child_tidptr,
        int, tls_val)
#else
SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
         int __user *, parent_tidptr,
         int __user *, child_tidptr,
         int, tls_val)
#endif
{
    return do_fork(clone_flags, newsp, 0, parent_tidptr, child_tidptr);
}
#endif

经过看上边包车型大巴代码,大家能够领略的看见,不论是运用 fork 依旧 vfork
来制程,最后都以通过 do_fork(卡塔尔国 方法来完成的。接下来大家得以追踪到
do_fork(卡塔尔的代码(部分代码,经过小编的简洁明了):

long do_fork(unsigned long clone_flags,
          unsigned long stack_start,
          unsigned long stack_size,
          int __user *parent_tidptr,
          int __user *child_tidptr)
{
        //创建进程描述符指针
        struct task_struct *p;

        //……

        //复制进程描述符,copy_process()的返回值是一个 task_struct 指针。
        p = copy_process(clone_flags, stack_start, stack_size,
             child_tidptr, NULL, trace);

        if (!IS_ERR(p)) {
            struct completion vfork;
            struct pid *pid;

            trace_sched_process_fork(current, p);

            //得到新创建的进程描述符中的pid
            pid = get_task_pid(p, PIDTYPE_PID);
            nr = pid_vnr(pid);

            if (clone_flags & CLONE_PARENT_SETTID)
                put_user(nr, parent_tidptr);

            //如果调用的 vfork()方法,初始化 vfork 完成处理信息。
            if (clone_flags & CLONE_VFORK) {
                p->vfork_done = &vfork;
                init_completion(&vfork);
                get_task_struct(p);
            }

            //将子进程加入到调度器中,为其分配 CPU,准备执行
            wake_up_new_task(p);

            //fork 完成,子进程即将开始运行
            if (unlikely(trace))
                ptrace_event_pid(trace, pid);

            //如果是 vfork,将父进程加入至等待队列,等待子进程完成
            if (clone_flags & CLONE_VFORK) {
                if (!wait_for_vfork_done(p, &vfork))
                    ptrace_event_pid(PTRACE_EVENT_VFORK_DONE, pid);
            }

            put_pid(pid);
        } else {
            nr = PTR_ERR(p);
        }
        return nr;
}

sys_vfork的实现


最早完毕

架构 实现
arm arch/arm/kernel/sys_arm.c, line 254
i386 arch/i386/kernel/process.c, line 737
x86_64 arch/x86_64/kernel/process.c, line 728
asmlinkage long sys_vfork(struct pt_regs regs)
{
    return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.rsp, &regs, 0);
}

 

新版本

#ifdef __ARCH_WANT_SYS_VFORK
SYSCALL_DEFINE0(vfork)
{
        return _do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0,
                        0, NULL, NULL, 0);
}
#endif

 

能够看来sys_vfork的得以完结与sys_fork只是微微分歧,
前面一个使用了附加的标识CLONE_VFORK | CLONE_VM

总结

  1. Linux通过复制父进度来创制三个新历程,通过调用do_fork来实现
  2. Linux为各种新创制的进度动态地分配多少个task_struct结构.
  3. 为了把基本中的全部进程组织起来,Linux提供了二种集体议程,个中哈希表和双向循环链表办法是对准系统中的全体进度(包涵基本线程),而运维队列和等候队列是把处于同一景观的长河组织起来
  4. fork(卡塔尔国函数被调用一回,但回到两次

task_struct数据布局解析

struct task_struct {
    volatile long state;//进程运行状态。-1为等待状态,0为运行,>0为停止状态
    void *stack; //进程的内核堆栈
    atomic_t usage;
    unsigned int flags; //每个进程的标识符
    unsigned int ptrace;//进程跟踪标识符

#ifdef CONFIG_SMP //条件编译,即对处理时用到的代码
    struct llist_node wake_entry;
    int on_cpu;
    struct task_struct *last_wakee;
    unsigned long wakee_flips;
    unsigned long wakee_flip_decay_ts;

    int wake_cpu;
#endif
    /*运行队列和进程调度相关的代码*/
    int on_rq;  

    int prio, static_prio, normal_prio;
    unsigned int rt_priority;
    const struct sched_class *sched_class;
    struct sched_entity se;
    struct sched_rt_entity rt;
#ifdef CONFIG_CGROUP_SCHED
    struct task_group *sched_task_group;
#endif
    struct sched_dl_entity dl;

#ifdef CONFIG_PREEMPT_NOTIFIERS
    /* list of struct preempt_notifier: */
    struct hlist_head preempt_notifiers;
#endif

#ifdef CONFIG_BLK_DEV_IO_TRACE
    unsigned int btrace_seq;
#endif

    unsigned int policy;
    int nr_cpus_allowed;
    cpumask_t cpus_allowed;

#ifdef CONFIG_PREEMPT_RCU
    int rcu_read_lock_nesting;
    union rcu_special rcu_read_unlock_special;
    struct list_head rcu_node_entry;
#endif /* #ifdef CONFIG_PREEMPT_RCU */
#ifdef CONFIG_TREE_PREEMPT_RCU
    struct rcu_node *rcu_blocked_node;
#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
#ifdef CONFIG_TASKS_RCU
    unsigned long rcu_tasks_nvcsw;
    bool rcu_tasks_holdout;
    struct list_head rcu_tasks_holdout_list;
    int rcu_tasks_idle_cpu;
#endif /* #ifdef CONFIG_TASKS_RCU */

#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
    struct sched_info sched_info;
#endif

    struct list_head tasks;  //进程的链表,将所有进程通过双向循环链表链接在一起。
#ifdef CONFIG_SMP
    struct plist_node pushable_tasks;
    struct rb_node pushable_dl_tasks;
#endif

    struct mm_struct *mm, *active_mm; //与进程的地址空间相关的数据结构
#ifdef CONFIG_COMPAT_BRK
    unsigned brk_randomized:1;
#endif
    /* per-thread vma caching */
    u32 vmacache_seqnum;
    struct vm_area_struct *vmacache[VMACACHE_SIZE];
#if defined(SPLIT_RSS_COUNTING)
    struct task_rss_stat    rss_stat;
#endif
/* task state */
    int exit_state;
    int exit_code, exit_signal;
    int pdeath_signal;  /*  The signal sent when the parent dies  */
    unsigned int jobctl;    /* JOBCTL_*, siglock protected */

    /* Used for emulating ABI behavior of previous Linux versions */
    unsigned int personality;

    unsigned in_execve:1;   /* Tell the LSMs that the process is doing an
                 * execve */
    unsigned in_iowait:1;

    /* Revert to default priority/policy when forking */
    unsigned sched_reset_on_fork:1;
    unsigned sched_contributes_to_load:1;

    unsigned long atomic_flags; /* Flags needing atomic access. */

    pid_t pid;  //进程标识符
    pid_t tgid; //进程标识符

#ifdef CONFIG_CC_STACKPROTECTOR
    /* Canary value for the -fstack-protector gcc feature */
    unsigned long stack_canary;
#endif
    /*
     * pointers to (original) parent process, youngest child, younger sibling,
     * older sibling, respectively.  (p->father can be replaced with
     * p->real_parent->pid)
     */
/*与进程父子关系有关的代码*/
    struct task_struct __rcu *real_parent; /* real parent process */
    struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
    /*
     * children/sibling forms the list of my natural children
     */
    struct list_head children;  /* list of my children */
    struct list_head sibling;   /* linkage in my parent's children list */
    struct task_struct *group_leader;   /* threadgroup leader */

    /*
     * ptraced is the list of tasks this task is using ptrace on.
     * This includes both natural children and PTRACE_ATTACH targets.
     * p->ptrace_entry is p's link on the p->parent->ptraced list.
     */
    struct list_head ptraced;
    struct list_head ptrace_entry;

    /* PID/PID hash table linkage. */
    struct pid_link pids[PIDTYPE_MAX];
    struct list_head thread_group;
    struct list_head thread_node;

    struct completion *vfork_done;      /* for vfork() */
    int __user *set_child_tid;      /* CLONE_CHILD_SETTID */
    int __user *clear_child_tid;        /* CLONE_CHILD_CLEARTID */

    /*与时间相关的代码*/
    cputime_t utime, stime, utimescaled, stimescaled;
    cputime_t gtime;
#ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
    struct cputime prev_cputime;
#endif
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
    seqlock_t vtime_seqlock;
    unsigned long long vtime_snap;
    enum {
        VTIME_SLEEPING = 0,
        VTIME_USER,
        VTIME_SYS,
    } vtime_snap_whence;
#endif
    unsigned long nvcsw, nivcsw; /* context switch counts */
    u64 start_time;     /* monotonic time in nsec */
    u64 real_start_time;    /* boot based time in nsec */
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
    unsigned long min_flt, maj_flt;

    struct task_cputime cputime_expires;
    struct list_head cpu_timers[3];

/* process credentials */
    const struct cred __rcu *real_cred; /* objective and real subjective task
                     * credentials (COW) */
    const struct cred __rcu *cred;  /* effective (overridable) subjective task
                     * credentials (COW) */
    char comm[TASK_COMM_LEN]; /* executable name excluding path
                     - access with [gs]et_task_comm (which lock
                       it with task_lock())
                     - initialized normally by setup_new_exec */
/* file system info */
    int link_count, total_link_count;
#ifdef CONFIG_SYSVIPC
/* ipc stuff */
    struct sysv_sem sysvsem;
    struct sysv_shm sysvshm;
#endif
#ifdef CONFIG_DETECT_HUNG_TASK
/* hung task detection */
    unsigned long last_switch_count;
#endif
/* 与CPU有关的数据结构*/
    struct thread_struct thread;
/* filesystem information */
    struct fs_struct *fs;//与文件系统有关的数据结构
/* open file information */
    struct files_struct *files; //文件描述符
/* namespaces */
    struct nsproxy *nsproxy;
/* 与信号处理相关的数据结构 */
    struct signal_struct *signal;
    struct sighand_struct *sighand;

    sigset_t blocked, real_blocked;
    sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
    struct sigpending pending;

    unsigned long sas_ss_sp;
    size_t sas_ss_size;
    int (*notifier)(void *priv);
    void *notifier_data;
    sigset_t *notifier_mask;
    struct callback_head *task_works;

    struct audit_context *audit_context;
#ifdef CONFIG_AUDITSYSCALL
    kuid_t loginuid;
    unsigned int sessionid;
#endif
    struct seccomp seccomp;

/* Thread group tracking */
    u32 parent_exec_id;
    u32 self_exec_id;
/* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
 * mempolicy */
    spinlock_t alloc_lock;

    /* Protection of the PI data structures: */
    raw_spinlock_t pi_lock;

#ifdef CONFIG_RT_MUTEXES  //互斥锁
    /* PI waiters blocked on a rt_mutex held by this task */
    struct rb_root pi_waiters;
    struct rb_node *pi_waiters_leftmost;
    /* Deadlock detection and priority inheritance handling */
    struct rt_mutex_waiter *pi_blocked_on;
#endif

#ifdef CONFIG_DEBUG_MUTEXES//互斥锁
    /* mutex deadlock detection */
    struct mutex_waiter *blocked_on;
#endif
#ifdef CONFIG_TRACE_IRQFLAGS //与调试相关的数据结构
    unsigned int irq_events;
    unsigned long hardirq_enable_ip;
    unsigned long hardirq_disable_ip;
    unsigned int hardirq_enable_event;
    unsigned int hardirq_disable_event;
    int hardirqs_enabled;
    int hardirq_context;
    unsigned long softirq_disable_ip;
    unsigned long softirq_enable_ip;
    unsigned int softirq_disable_event;
    unsigned int softirq_enable_event;
    int softirqs_enabled;
    int softirq_context;
#endif
#ifdef CONFIG_LOCKDEP
# define MAX_LOCK_DEPTH 48UL
    u64 curr_chain_key;
    int lockdep_depth;
    unsigned int lockdep_recursion;
    struct held_lock held_locks[MAX_LOCK_DEPTH];
    gfp_t lockdep_reclaim_gfp;
#endif

/* journalling filesystem info */
    void *journal_info;

/* stacked block device info */
    struct bio_list *bio_list;

#ifdef CONFIG_BLOCK
/* stack plugging */
    struct blk_plug *plug;
#endif

/* VM state */
    struct reclaim_state *reclaim_state;

    struct backing_dev_info *backing_dev_info;

    struct io_context *io_context;

    unsigned long ptrace_message;
    siginfo_t *last_siginfo; /* For ptrace use.  */
    struct task_io_accounting ioac;
#if defined(CONFIG_TASK_XACCT)
    u64 acct_rss_mem1;  /* accumulated rss usage */
    u64 acct_vm_mem1;   /* accumulated virtual memory usage */
    cputime_t acct_timexpd; /* stime + utime since last update */
#endif
#ifdef CONFIG_CPUSETS
    nodemask_t mems_allowed;    /* Protected by alloc_lock */
    seqcount_t mems_allowed_seq;    /* Seqence no to catch updates */
    int cpuset_mem_spread_rotor;
    int cpuset_slab_spread_rotor;
#endif
#ifdef CONFIG_CGROUPS
    /* Control Group info protected by css_set_lock */
    struct css_set __rcu *cgroups;
    /* cg_list protected by css_set_lock and tsk->alloc_lock */
    struct list_head cg_list;
#endif
#ifdef CONFIG_FUTEX
    struct robust_list_head __user *robust_list;
#ifdef CONFIG_COMPAT
    struct compat_robust_list_head __user *compat_robust_list;
#endif
    struct list_head pi_state_list;
    struct futex_pi_state *pi_state_cache;
#endif
#ifdef CONFIG_PERF_EVENTS
    struct perf_event_context *perf_event_ctxp[perf_nr_task_contexts];
    struct mutex perf_event_mutex;
    struct list_head perf_event_list;
#endif
#ifdef CONFIG_DEBUG_PREEMPT
    unsigned long preempt_disable_ip;
#endif
#ifdef CONFIG_NUMA
    struct mempolicy *mempolicy;    /* Protected by alloc_lock */
    short il_next;
    short pref_node_fork;
#endif
#ifdef CONFIG_NUMA_BALANCING
    int numa_scan_seq;
    unsigned int numa_scan_period;
    unsigned int numa_scan_period_max;
    int numa_preferred_nid;
    unsigned long numa_migrate_retry;
    u64 node_stamp;         /* migration stamp  */
    u64 last_task_numa_placement;
    u64 last_sum_exec_runtime;
    struct callback_head numa_work;

    struct list_head numa_entry;
    struct numa_group *numa_group;

    /*
     * Exponential decaying average of faults on a per-node basis.
     * Scheduling placement decisions are made based on the these counts.
     * The values remain static for the duration of a PTE scan
     */
    unsigned long *numa_faults_memory;
    unsigned long total_numa_faults;

    /*
     * numa_faults_buffer records faults per node during the current
     * scan window. When the scan completes, the counts in
     * numa_faults_memory decay and these values are copied.
     */
    unsigned long *numa_faults_buffer_memory;

    /*
     * Track the nodes the process was running on when a NUMA hinting
     * fault was incurred.
     */
    unsigned long *numa_faults_cpu;
    unsigned long *numa_faults_buffer_cpu;

    /*
     * numa_faults_locality tracks if faults recorded during the last
     * scan window were remote/local. The task scan period is adapted
     * based on the locality of the faults with different weights
     * depending on whether they were shared or private faults
     */
    unsigned long numa_faults_locality[2];

    unsigned long numa_pages_migrated;
#endif /* CONFIG_NUMA_BALANCING */

    struct rcu_head rcu;

    /*
     * 与管道相关的数据结构
     */
    struct pipe_inode_info *splice_pipe; 

    struct page_frag task_frag;

#ifdef  CONFIG_TASK_DELAY_ACCT
    struct task_delay_info *delays;
#endif
#ifdef CONFIG_FAULT_INJECTION
    int make_it_fail;
#endif
    /*
     * when (nr_dirtied >= nr_dirtied_pause), it's time to call
     * balance_dirty_pages() for some dirty throttling pause
     */
    int nr_dirtied;
    int nr_dirtied_pause;
    unsigned long dirty_paused_when; /* start of a write-and-pause period */

#ifdef CONFIG_LATENCYTOP
    int latency_record_count;
    struct latency_record latency_record[LT_SAVECOUNT];
#endif
    /*
     * time slack values; these are used to round up poll() and
     * select() etc timeout values. These are in nanoseconds.
     */
    unsigned long timer_slack_ns;
    unsigned long default_timer_slack_ns;

#ifdef CONFIG_FUNCTION_GRAPH_TRACER
    /* Index of current stored address in ret_stack */
    int curr_ret_stack;
    /* Stack of return addresses for return function tracing */
    struct ftrace_ret_stack *ret_stack;
    /* time stamp for last schedule */
    unsigned long long ftrace_timestamp;
    /*
     * Number of functions that haven't been traced
     * because of depth overrun.
     */
    atomic_t trace_overrun;
    /* Pause for the tracing */
    atomic_t tracing_graph_pause;
#endif
#ifdef CONFIG_TRACING
    /* state flags for use by tracers */
    unsigned long trace;
    /* bitmask and counter of trace recursion */
    unsigned long trace_recursion;
#endif /* CONFIG_TRACING */
#ifdef CONFIG_MEMCG /* memcg uses this to do batch job */
    unsigned int memcg_kmem_skip_account;
    struct memcg_oom_info {
        struct mem_cgroup *memcg;
        gfp_t gfp_mask;
        int order;
        unsigned int may_oom:1;
    } memcg_oom;
#endif
#ifdef CONFIG_UPROBES
    struct uprobe_task *utask;
#endif
#if defined(CONFIG_BCACHE) || defined(CONFIG_BCACHE_MODULE)
    unsigned int    sequential_io;
    unsigned int    sequential_io_avg;
#endif
};