• T
    cgroup: load and release pidlists from seq_file start and stop respectively · 4bac00d1
    Tejun Heo 提交于
    Currently, pidlists are reference counted from file open and release
    methods.  This means that holding onto an open file may waste memory
    and reads may return data which is very stale.  Both aren't critical
    because pidlists are keyed and shared per namespace and, well, the
    user isn't supposed to have large delay between open and reads.
    
    cgroup is planned to be converted to use kernfs and it'd be best if we
    can stick to just the seq_file operations - start, next, stop and
    show.  This can be achieved by loading pidlist on demand from start
    and release with time delay from stop, so that consecutive reads don't
    end up reloading the pidlist on each iteration.  This would remove the
    need for hooking into open and release while also avoiding issues with
    holding onto pidlist for too long.
    
    The previous patches implemented delayed release and restructured
    pidlist handling so that pidlists can be loaded and released from
    seq_file start / stop.  This patch actually moves pidlist load to
    start and release to stop.
    
    This means that pidlist is pinned only between start and stop and may
    go away between two consecutive read calls if the two calls are apart
    by more than CGROUP_PIDLIST_DESTROY_DELAY.  cgroup_pidlist_start()
    thus can't re-use the stored cgroup_pid_list_open_file->pidlist
    directly.  During start, it's only used as a hint indicating whether
    this is the first start after open or not and pidlist is always looked
    up or created.
    
    pidlist_mutex locking and reference counting are moved out of
    pidlist_array_load() so that pidlist_array_load() can perform lookup
    and creation atomically.  While this enlarges the area covered by
    pidlist_mutex, given how the lock is used, it's highly unlikely to be
    noticeable.
    
    v2: Refreshed on top of the updated "cgroup: introduce struct
        cgroup_pidlist_open_file".
    Signed-off-by: NTejun Heo <tj@kernel.org>
    Acked-by: NLi Zefan <lizefan@huawei.com>
    4bac00d1
cgroup.c 148.2 KB