From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755061AbdLOEek (ORCPT ); Thu, 14 Dec 2017 23:34:40 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36904 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754921AbdLOEeh (ORCPT ); Thu, 14 Dec 2017 23:34:37 -0500 Subject: Re: [PATCH] mm: thp: use down_read_trylock in khugepaged to avoid long block To: Yang Shi , kirill.shutemov@linux.intel.com, mhocko@suse.com, hughd@google.com, aarcange@redhat.com, akpm@linux-foundation.org References: <1513281203-54878-1-git-send-email-yang.s@alibaba-inc.com> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org From: Anshuman Khandual Date: Fri, 15 Dec 2017 10:04:27 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1513281203-54878-1-git-send-email-yang.s@alibaba-inc.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17121504-0008-0000-0000-000004B75C3E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121504-0009-0000-0000-00001E4A70D3 Message-Id: <16a06998-34ba-65d9-c6d0-8078d9ef98f9@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-15_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712150062 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/15/2017 01:23 AM, Yang Shi wrote: > In the current design, khugepaged need acquire mmap_sem before scanning > mm, but in some corner case, khugepaged may scan the current running > process which might be modifying memory mapping, so khugepaged might > block in uninterruptible state. But, the process might hold the mmap_sem > for long time when modifying a huge memory space, then it may trigger > the below khugepaged hung issue: > > INFO: task khugepaged:270 blocked for more than 120 seconds. > Tainted: G E 4.9.65-006.ali3000.alios7.x86_64 #1 > "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. > khugepaged D 0 270 2 0x00000000 > ffff883f3deae4c0 0000000000000000 ffff883f610596c0 ffff883f7d359440 > ffff883f63818000 ffffc90019adfc78 ffffffff817079a5 d67e5aa8c1860a64 > 0000000000000246 ffff883f7d359440 ffffc90019adfc88 ffff883f610596c0 > Call Trace: > [] ? __schedule+0x235/0x6e0 > [] schedule+0x36/0x80 > [] rwsem_down_read_failed+0xf0/0x150 > [] call_rwsem_down_read_failed+0x18/0x30 > [] down_read+0x20/0x40 > [] khugepaged+0x476/0x11d0 > [] ? idle_balance+0x1ce/0x300 > [] ? prepare_to_wait_event+0x100/0x100 > [] ? collapse_shmem+0xbf0/0xbf0 > [] kthread+0xe6/0x100 > [] ? kthread_park+0x60/0x60 > [] ret_from_fork+0x25/0x30 > > So, it sounds pointless to just block for waiting for the semaphore for > khugepaged, here replace down_read() to down_read_trylock() to move to > scan next mm quickly instead of just blocking on the semaphore so that > other processes can get more chances to install THP. > Then khugepaged can come back to scan the skipped mm when finish the > current round full_scan. That may be too harsh on the process which now has to wait for a complete round of full scan before the khugepaged comes back. What if the mmap_sem contention because of VMA changes in the process was just temporary ?