• Andrew Morton's avatar
    [PATCH] rmap: nonlinear truncation · dd9fd0e0
    Andrew Morton authored
    From: Hugh Dickins <hugh@veritas.com>
    
    The earlier changes introducing PageAnon left truncated pages mapped into
    nonlinear vmas unswappable.  Once we go to object-based rmap, it's
    impossible to find where file page is mapped once page->mapping cleared:
    switching them to anonymous is odd, and breaks strict commit accounting.
    
    So now handle truncation of nonlinear vmas correctly.  And factor in
    Daniel's cluster filesystem needs while we're there: when invalidating
    local cache, we do want to unmap shared pages from all mms, but we do not
    want to discard private COWed modifications of those pages (which
    truncation discards to satisfy the SIGBUS semantics demanded by specs).
    
    Drew from Daniel's patch (LKML 2 Mar 04), but didn't always follow it;
    fewer name changes, but still some - "unmap" rather than "invalidate".
    zap_page_range is not exported, safe to give it and all the too-many layers
    an extra zap_details arg, in normal cases just NULL.
    
    Given details, zap_pte_range checks page mapping or index to skip anon or
    untruncated pages.  I didn't realize before implementing, that in nonlinear
    case, it should set a file pte when truncating - otherwise linear pages
    might appear in place of SIGBUS.  I suspect this implies that ->populate
    functions ought to set file ptes beyond EOF instead of failing, but haven't
    changed them as yet.
    
    To avoid making yet another copy of that ugly linear pgidx test, added
    inline function linear_page_index (to pagemap.h to get PAGE_CACHE_SIZE,
    though as usual things don't really work if it differs from PAGE_SIZE). 
    Ooh, I thought I'd removed ___add_to_page_cache last time, do so now.
    
    unmap_page_range static, shift its hugepage check up into sole caller
    unmap_vmas.  Killed "killme" debug from unmap_vmas, not seen it trigger.
    unmap_mapping_range is exported without restriction: I'm one of those who
    believe it should be generally available.  But I'm wrongly placed to decide
    that, probably just sob quietly to myself if _GPL added later.
    dd9fd0e0
memory.c 47.3 KB