• zhong jiang's avatar
    mm,ksm: fix endless looping in allocating memory when ksm enable · 956e1e40
    zhong jiang authored
    [ Upstream commit 5b398e41 ]
    
    I hit the following hung task when runing a OOM LTP test case with 4.1
    kernel.
    
    Call trace:
    [<ffffffc000086a88>] __switch_to+0x74/0x8c
    [<ffffffc000a1bae0>] __schedule+0x23c/0x7bc
    [<ffffffc000a1c09c>] schedule+0x3c/0x94
    [<ffffffc000a1eb84>] rwsem_down_write_failed+0x214/0x350
    [<ffffffc000a1e32c>] down_write+0x64/0x80
    [<ffffffc00021f794>] __ksm_exit+0x90/0x19c
    [<ffffffc0000be650>] mmput+0x118/0x11c
    [<ffffffc0000c3ec4>] do_exit+0x2dc/0xa74
    [<ffffffc0000c46f8>] do_group_exit+0x4c/0xe4
    [<ffffffc0000d0f34>] get_signal+0x444/0x5e0
    [<ffffffc000089fcc>] do_signal+0x1d8/0x450
    [<ffffffc00008a35c>] do_notify_resume+0x70/0x78
    
    The oom victim cannot terminate because it needs to take mmap_sem for
    write while the lock is held by ksmd for read which loops in the page
    allocator
    
    ksm_do_scan
    	scan_get_next_rmap_item
    		down_read
    		get_next_rmap_item
    			alloc_rmap_item   #ksmd will loop permanently.
    ...
    956e1e40
ksm.c 63.3 KB