• Hugh Dickins's avatar
    [PATCH] vmtrunc: unmap_mapping dropping i_mmap_lock · 3ee07371
    Hugh Dickins authored
    vmtruncate (or more generally, unmap_mapping_range) has been observed
    responsible for very high latencies: the lockbreak work in unmap_vmas is good
    for munmap or exit_mmap, but no use while mapping->i_mmap_lock is held, to
    keep our place in the prio_tree (or list) of a file's vmas.
    
    Extend the zap_details block with i_mmap_lock pointer, so unmap_vmas can
    detect if that needs lockbreak, and break_addr so it can notify where it left
    off.
    
    Add unmap_mapping_range_vma, used from both prio_tree and nonlinear list
    handlers.  This is what now calls zap_page_range (above unmap_vmas), but
    handles the lockbreak and restart issues: letting unmap_mapping_range_ tree or
    list know when they need to start over because lock was dropped.
    
    When restarting, of course there's a danger of never making progress.  Add
    vm_truncate_count field to vm_area_struct, update that to mapping->
    truncate_count once fully scanned, skip up-to-date vmas without a scan (and
    without dropping i_mmap_lock).
    
    Further danger of never making progress if a vma is very large: when breaking
    out, save restart_vma and restart_addr (and restart_pgoff to confirm, in case
    vma gets reused), to help continue where we left off.
    Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    3ee07371
memory.c 59.4 KB