进程创建时cgroup处理

来源:互联网 发布:授权书制作软件 编辑:程序博客网 时间:2024/06/05 08:57
 
void cgroup_fork(struct task_struct *child){ RCU_INIT_POINTER(child->cgroups, &init_css_set); INIT_LIST_HEAD(&child->cg_list);}
 
cgroup_can_fork:

/** * cgroup_can_fork - called on a new task before the process is exposed * @child: the task in question. * * This calls the subsystem can_fork() callbacks. If the can_fork() callback * returns an error, the fork aborts with that error code. This allows for * a cgroup subsystem to conditionally allow or deny new forks. */int cgroup_can_fork(struct task_struct *child){ struct cgroup_subsys *ss; int i, j, ret;

 do_each_subsys_mask(ss, i, have_canfork_callback) {  ret = ss->can_fork(child);  if (ret)   goto out_revert; } while_each_subsys_mask();

 return 0;

out_revert: for_each_subsys(ss, j) {  if (j >= i)   break;  if (ss->cancel_fork)   ss->cancel_fork(child); }

 return ret;}

 

/** * cgroup_post_fork - called on a new task after adding it to the task list * @child: the task in question * * Adds the task to the list running through its css_set if necessary and * call the subsystem fork() callbacks.  Has to be after the task is * visible on the task list in case we race with the first call to * cgroup_task_iter_start() - to guarantee that the new task ends up on its * list. */void cgroup_post_fork(struct task_struct *child){ struct cgroup_subsys *ss; int i;

 /*  * This may race against cgroup_enable_task_cg_lists().  As that  * function sets use_task_css_set_links before grabbing  * tasklist_lock and we just went through tasklist_lock to add  * @child, it's guaranteed that either we see the set  * use_task_css_set_links or cgroup_enable_task_cg_lists() sees  * @child during its iteration.  *  * If we won the race, @child is associated with %current's  * css_set.  Grabbing css_set_lock guarantees both that the  * association is stable, and, on completion of the parent's  * migration, @child is visible in the source of migration or  * already in the destination cgroup.  This guarantee is necessary  * when implementing operations which need to migrate all tasks of  * a cgroup to another.  *  * Note that if we lose to cgroup_enable_task_cg_lists(), @child  * will remain in init_css_set.  This is safe because all tasks are  * in the init_css_set before cg_links is enabled and there's no  * operation which transfers all tasks out of init_css_set.  */ if (use_task_css_set_links) {  struct css_set *cset;

  spin_lock_irq(&css_set_lock);  cset = task_css_set(current);  if (list_empty(&child->cg_list)) {   get_css_set(cset);   css_set_move_task(child, NULL, cset, false);  }  spin_unlock_irq(&css_set_lock); }

 /*  * Call ss->fork().  This must happen after @child is linked on  * css_set; otherwise, @child might change state between ->fork()  * and addition to css_set.  */ do_each_subsys_mask(ss, i, have_fork_callback) {  ss->fork(child); } while_each_subsys_mask();}

0 0
原创粉丝点击