Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp572076pxj; Wed, 2 Jun 2021 06:21:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUNhz9p/JXfup3L61CBkfaZVPzAtKaCZVcCK4cIBfMai2VcKb7LTaGQS25QBAlplYv5c63 X-Received: by 2002:a17:906:e2d6:: with SMTP id gr22mr7119654ejb.514.1622640119321; Wed, 02 Jun 2021 06:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622640119; cv=none; d=google.com; s=arc-20160816; b=NNum+7ZwkTbcF6P8xnNGaNfp1tQQmeGyaUfJ7kxiUaSHkjGqvjO2quAWJPHRp1pHuj 9yIpw8lprR9hlDpjvCMuLBvLi7L4qLB87ZE+eesfnGNPbMZVGSRCW3i8AbF9senl07mV VwWhJrn+YAtYcyRxL91+5O0h+ay7UnmSBim/roQKZIXZpZMYRwt98xtLZ/xksLcyF7/r jbIW0/lMPw1kUXuhDaqQuSl+bSAkeesurCWciFy475RW2Gd/J3iZkijU0nOXTy0d09fQ W0/6Ro9aq5Hbgf+78T3TkrHx7hKPYrtXmk2Og4HIFYAXzAZdNelvnSDmMbZzKlqP2ot2 1uCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=V34WfrkdD6/9aIsyqfoGvdFpZt67DR0hlCu0xlBMjrA=; b=ePmBnjell3QhhJX4nr2z/a3+gCXMu2I6L1uIJ/H0cpeqWujL0WAgsUMe40jTSklA2E iN1V5paTSDSbL81N/gu0Xr/1jVq5ZZgGsdkr0RBv6Wr7hvQDh00g3TGAZfpdFvC+9eXL EB5AkVIIQiEyyGWhaRA2fQaP8Ip5xsFHecoLfDZwUP4OeSlrooN12uLv7l9aAITub3+y +RqH3HtLwur4su25H7MeyYdPA8MDj/D6WOwH8XYHDVByaLyvDijF80kLgONnqiM6B3Xd llmnZuf9vzNgBz+CMfWfWIje1gHu5wCO9i3pYBbDV0VaEG8nMFhpWdKdHvJwv+nymkNM 2MQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si2095188edy.432.2021.06.02.06.21.34; Wed, 02 Jun 2021 06:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbhFBNWS (ORCPT + 99 others); Wed, 2 Jun 2021 09:22:18 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:56702 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbhFBNWS (ORCPT ); Wed, 2 Jun 2021 09:22:18 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=xuyu@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0Ub3L4fy_1622640032; Received: from xuyu-mbp15.local(mailfrom:xuyu@linux.alibaba.com fp:SMTPD_---0Ub3L4fy_1622640032) by smtp.aliyun-inc.com(127.0.0.1); Wed, 02 Jun 2021 21:20:33 +0800 Subject: Re: [PATCH] mm, thp: relax migration wait when failed to get tail page To: Hugh Dickins Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, gavin.dg@linux.alibaba.com, Greg Thelen , Wei Xu , Matthew Wilcox , Nicholas Piggin , Vlastimil Babka References: From: Yu Xu Message-ID: Date: Wed, 2 Jun 2021 21:20:32 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/2/21 12:55 AM, Hugh Dickins wrote: > On Wed, 2 Jun 2021, Xu Yu wrote: > >> We notice that hung task happens in a conner but practical scenario when >> CONFIG_PREEMPT_NONE is enabled, as follows. >> >> Process 0 Process 1 Process 2..Inf >> split_huge_page_to_list >> unmap_page >> split_huge_pmd_address >> __migration_entry_wait(head) >> __migration_entry_wait(tail) >> remap_page (roll back) >> remove_migration_ptes >> rmap_walk_anon >> cond_resched >> >> Where __migration_entry_wait(tail) is occurred in kernel space, e.g., >> copy_to_user, which will immediately fault again without rescheduling, >> and thus occupy the cpu fully. >> >> When there are too many processes performing __migration_entry_wait on >> tail page, remap_page will never be done after cond_resched. >> >> This relaxes __migration_entry_wait on tail page, thus gives remap_page >> a chance to complete. >> >> Signed-off-by: Gang Deng >> Signed-off-by: Xu Yu > > Well caught: you're absolutely right that there's a bug there. > But isn't cond_resched() just papering over the real bug, and > what it should do is a "page = compound_head(page);" before the > get_page_unless_zero()? How does that work out in your testing? compound_head works. The patched kernel is alive for hours under our reproducer, which usually makes the vanilla kernel hung after tens of minutes at most. If we use compound_head, the behavior of __migration_entry_wait(tail) changes from "retry fault" to "prevent THP from being split". Is that right? Then which is preferred? If it were me, I would prefer "retry fault". > > Hugh > >> --- >> mm/migrate.c | 7 +++++-- >> 1 file changed, 5 insertions(+), 2 deletions(-) >> >> diff --git a/mm/migrate.c b/mm/migrate.c >> index b234c3f3acb7..df2dc39fe566 100644 >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -301,8 +301,11 @@ void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, >> * is zero; but we must not call put_and_wait_on_page_locked() without >> * a ref. Use get_page_unless_zero(), and just fault again if it fails. >> */ >> - if (!get_page_unless_zero(page)) >> - goto out; >> + if (!get_page_unless_zero(page)) { >> + pte_unmap_unlock(ptep, ptl); >> + cond_resched(); >> + return; >> + } >> pte_unmap_unlock(ptep, ptl); >> put_and_wait_on_page_locked(page, TASK_UNINTERRUPTIBLE); >> return; >> -- >> 2.20.1.2432.ga663e714 >> >> >> -- Thanks, Yu