• Prasanna Meda's avatar
    [PATCH] Speed up /proc/pid/maps · d6b7a781
    Prasanna Meda authored
    This patch uses find_vma() to improve the read response of /proc/pid/maps. 
    It attempts to make the liner scan instead of quadratic walk and utilise rb
    tree.  Reading the file was doing sequential scan from the begining to file
    position all the time, and taking a quite long time.
    
    The improvements came from f_version/m_version and resulting in mmap_cache
    match.  Even if mmap_cache does not match, rb tree walk should be faster
    than sequential walk.  First attempt was to put the state across read
    system calls into private data.  Later got inspiration from wli's pid patch
    using f_version in readdir of /proc.  Other advantage is, f_version will be
    cleared automatically by lseek.
    
    The test program creates 32K maps and splits them into two(limited by
    max_map_count sysctl) using mprotect(0).  After the patch, the read time
    improves from many seconds to milliseconds, and does not grow superlinearly
    with number of read calls.
    
    Help taken from Peter Swain in idea and testing.
    
    After the patch:
    Reading /proc/self/maps:65528 time: 0 secs and   780728 usecs buf:4096 bytes:3811362
    Reading /proc/self/maps:65528 time: 1 secs and   117573 usecs buf:1024 bytes:3866627
    Reading /proc/self/maps:65528 time: 0 secs and   473459 usecs buf: 256 bytes:3866627
    Reading /proc/self/maps:65528 time: 0 secs and   901288 usecs buf:  64 bytes:3866627
    Reading /proc/self/maps:65528 time: 1 secs and   480185 usecs buf:  16 bytes:3866627
    Reading /proc/self/maps:65528 time: 1 secs and   636268 usecs buf:   4 bytes:3866627
    Reading /proc/self/maps:65528 time: 4 secs and   118327 usecs buf:   1 bytes:3866627
    
    Before the patch:
    Reading /proc/self/maps:65528 time: 4 secs and   359556 usecs buf:4096 bytes:3866647
    Reading /proc/self/maps:65528 time:16 secs and   218584 usecs buf:1024 bytes:3866688
    Reading /proc/self/maps:65528 time:67 secs and   870200 usecs buf: 256 bytes:3866688
    Reading /proc/self/maps:65528 time:255 secs and   186934 usecs buf:  64 bytes:3866688
    Small reads never completed.
    Signed-off-by: default avatarPrasanna Meda <pmeda@akamai.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    d6b7a781
task_mmu.c 5.21 KB