• Tejun Heo's avatar
    cgroup: add css_set->mg_tasks · c7561128
    Tejun Heo authored
    Currently, while migrating tasks from one cgroup to another,
    cgroup_attach_task() builds a flex array of all target tasks;
    unfortunately, this has a couple issues.
    
    * Flex array has size limit.  On 64bit, struct task_and_cgroup is
      24bytes making the flex element limit around 87k.  It is a high
      number but not impossible to hit.  This means that the current
      cgroup implementation can't migrate a process with more than 87k
      threads.
    
    * Process migration involves memory allocation whose size is dependent
      on the number of threads the process has.  This means that cgroup
      core can't guarantee success or failure of multi-process migrations
      as memory allocation failure can happen in the middle.  This is in
      part because cgroup can't grab threadgroup locks of multiple
      processes at the same time, so when there are multiple processes to
      migrate, it is imposible to tell how many tasks are to be migrated
      beforehand.
    
      Note that this already affects cgroup_transfer_tasks().  cgroup
      currently cannot guarantee atomic success or failure of the
      operation.  It may fail in the middle and after such failure cgroup
      doesn't have enough information to roll back properly.  It just
      aborts with some tasks migrated and others not.
    
    To resolve the situation, we're going to use task->cg_list during
    migration too.  Instead of building a separate array, target tasks
    will be linked into a dedicated migration list_head on the owning
    css_set.  Tasks on the migration list are treated the same as tasks on
    the usual tasks list; however, being on a separate list allows cgroup
    migration code path to keep track of the target tasks by simply
    keeping the list of css_sets with tasks being migrated, making
    unpredictable dynamic allocation unnecessary.
    
    In prepartion of such migration path update, this patch introduces
    css_set->mg_tasks list and updates css_set task iterations so that
    they walk both css_set->tasks and ->mg_tasks.  Note that ->mg_tasks
    isn't used yet.
    Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    Acked-by: default avatarLi Zefan <lizefan@huawei.com>
    c7561128
cgroup.c 124 KB