• Andrew Morton's avatar
    [PATCH] Optimize proc_pid_lookup · 9c02379c
    Andrew Morton authored
    From: Manfred Spraul <manfred@colorfullife.com>
    
    readdir on /proc has two problems: reading all entries is O(N^2), and
    entries are overlooked if tasks die in the middle of readdir: the readdir
    implementation remembers the offset into the task list, and if a task
    (actually: process) that was returned by previous readdir calls exits, then
    a random entry is dropped.
    
    The attached patch fixes the O(N^2) by using f_version to store the pid of
    the task that should be returned next.  This speeds up reading /proc to
    O(N).  Additionally, it mitigates the effects of dying tasks: Tasks are
    skipped only if the task whose pid is stored in f_version exits, all other
    task deaths have no effect.  Unfortunately the code has a bad worst case
    behavior: if the targeted task exits and a new task with the same pid is
    created, then all entries in the task list between old and new position are
    dropped.  This should be rare.
    9c02379c
base.c 41.8 KB