Skip to content
  • Tejun Heo's avatar
    cgroup: make css_set_lock a rwsem and rename it to css_set_rwsem · 96d365e0
    Tejun Heo authored
    
    
    Currently there are two ways to walk tasks of a cgroup -
    css_task_iter_start/next/end() and css_scan_tasks().  The latter
    builds on the former but allows blocking while iterating.
    Unfortunately, the way css_scan_tasks() is implemented is rather
    nasty, it uses a priority heap of pointers to extract some number of
    tasks in task creation order and loops over them invoking the callback
    and repeats that until it reaches the end.  It requires either
    preallocated heap or may fail under memory pressure, while unlikely to
    be problematic, the complexity is O(N^2), and in general just nasty.
    
    We're gonna convert all css_scan_users() to
    css_task_iter_start/next/end() and remove css_scan_users().  As
    css_scan_tasks() users may block, let's convert css_set_lock to a
    rwsem so that tasks can block during css_task_iter_*() is in progress.
    
    While this does increase the chance of possible deadlock scenarios,
    given the current usage, the probability is relatively low, and even
    if that happens, the right thing to do is updating the iteration in
    the similar way to css iterators so that it can handle blocking.
    
    Most conversions are trivial; however, task_cgroup_path() now expects
    to be called with css_set_rwsem locked instead of locking itself.
    This is because the function is called with RCU read lock held and
    rwsem locking should nest outside RCU read lock.
    
    Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    Acked-by: default avatarLi Zefan <lizefan@huawei.com>
    96d365e0