Skip to content
  • Hugh Dickins's avatar
    mm: munlock use follow_page · 408e82b7
    Hugh Dickins authored
    
    
    Hiroaki Wakabayashi points out that when mlock() has been interrupted
    by SIGKILL, the subsequent munlock() takes unnecessarily long because
    its use of __get_user_pages() insists on faulting in all the pages
    which mlock() never reached.
    
    It's worse than slowness if mlock() is terminated by Out Of Memory kill:
    the munlock_vma_pages_all() in exit_mmap() insists on faulting in all the
    pages which mlock() could not find memory for; so innocent bystanders are
    killed too, and perhaps the system hangs.
    
    __get_user_pages() does a lot that's silly for munlock(): so remove the
    munlock option from __mlock_vma_pages_range(), and use a simple loop of
    follow_page()s in munlock_vma_pages_range() instead; ignoring absent
    pages, and not marking present pages as accessed or dirty.
    
    (Change munlock() to only go so far as mlock() reached?  That does not
    work out, given the convention that mlock() claims complete success even
    when it has to give up early - in part so that an underlying file can be
    extended later, and those pages locked which earlier would give SIGBUS.)
    
    Signed-off-by: default avatarHugh Dickins <hugh.dickins@tiscali.co.uk>
    Cc: <stable@kernel.org>
    Acked-by: default avatarRik van Riel <riel@redhat.com>
    Reviewed-by: default avatarMinchan Kim <minchan.kim@gmail.com>
    Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
    Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
    Cc: Nick Piggin <npiggin@suse.de>
    Cc: Mel Gorman <mel@csn.ul.ie>
    Reviewed-by: default avatarHiroaki Wakabayashi <primulaelatior@gmail.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    408e82b7