进程创建时cgroup处理

 
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(); }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值