• Song Liu's avatar
    bpf: Introduce task_vma bpf_iter · 3a7b35b8
    Song Liu authored
    Introduce task_vma bpf_iter to print memory information of a process. It
    can be used to print customized information similar to /proc/<pid>/maps.
    
    Current /proc/<pid>/maps and /proc/<pid>/smaps provide information of
    vma's of a process. However, these information are not flexible enough to
    cover all use cases. For example, if a vma cover mixed 2MB pages and 4kB
    pages (x86_64), there is no easy way to tell which address ranges are
    backed by 2MB pages. task_vma solves the problem by enabling the user to
    generate customize information based on the vma (and vma->vm_mm,
    vma->vm_file, etc.).
    
    To access the vma safely in the BPF program, task_vma iterator holds
    target mmap_lock while calling the BPF program. If the mmap_lock is
    contended, task_vma unlocks mmap_lock between iterations to unblock the
    writer(s). This lock contention avoidance mechanism is similar to the one
    used in show_smaps_rollup().
    Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarYonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20210212183107.50963-2-songliubraving@fb.com
    3a7b35b8
task_iter.c 14.7 KB