From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0683FC433E0 for ; Fri, 8 Jan 2021 01:08:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5879223447 for ; Fri, 8 Jan 2021 01:08:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5879223447 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 72FC68D015F; Thu, 7 Jan 2021 20:08:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EB628D0156; Thu, 7 Jan 2021 20:08:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CFCB8D015F; Thu, 7 Jan 2021 20:08:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 44FCF8D0156 for ; Thu, 7 Jan 2021 20:08:37 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0C115181AEF1A for ; Fri, 8 Jan 2021 01:08:37 +0000 (UTC) X-FDA: 77680822674.12.bear74_060d257274ee Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id DFD9818003C06 for ; Fri, 8 Jan 2021 01:08:36 +0000 (UTC) X-HE-Tag: bear74_060d257274ee X-Filterd-Recvd-Size: 6773 Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Fri, 8 Jan 2021 01:08:36 +0000 (UTC) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10813oah092989; Fri, 8 Jan 2021 01:08:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=vJYZ13cXxFkQ+MJP9Qv7/yIo9FE9hy8UjOwKUfe1eg4=; b=tt+/21Oo6cFEyIfSy850JdlWYQ5LjFNV8at6v4cKOo3H5m+HQl1QpQTf+D21oxzd0Cbs OQSKqoEEjXFowLHCZNn+1HWTkAm0nEHELWvLYHA8CHvfgSAerO5QB1cMdb/QQT+H/IE+ lXRdrflyC5j5Y53e8Qx67AZf0HYwSm4sAwIaK1OK0/G/xXXcisPZDXd1l4ODw6uTM4kR KFHI30NiTvPmc7kf6UyuajSbBWUSQiPByFtOqf5yBvEeqQjf2jMvUHrkiXVUY35lyWtQ dWjtmQzZp/E74PlyLBm1CBOc7CFBtwVu7Hy3PhORg8Ezin7/BOSRhL78FvRcsutkt4V5 UQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 35wftxenvr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 08 Jan 2021 01:08:30 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10810VK3160063; Fri, 8 Jan 2021 01:06:30 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 35w3qujs04-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 08 Jan 2021 01:06:30 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 10816RRa025514; Fri, 8 Jan 2021 01:06:27 GMT Received: from [192.168.2.112] (/50.38.35.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 08 Jan 2021 01:06:26 +0000 Subject: Re: [External] Re: [PATCH v2 3/6] mm: hugetlb: fix a race between freeing and dissolving the page To: Muchun Song , Michal Hocko Cc: Andrew Morton , Naoya Horiguchi , Andi Kleen , Linux Memory Management List , LKML References: <20210106084739.63318-1-songmuchun@bytedance.com> <20210106084739.63318-4-songmuchun@bytedance.com> <20210106165632.GT13207@dhcp22.suse.cz> <20210107084146.GD13207@dhcp22.suse.cz> <20210107111827.GG13207@dhcp22.suse.cz> <20210107123854.GJ13207@dhcp22.suse.cz> <20210107141130.GL13207@dhcp22.suse.cz> From: Mike Kravetz Message-ID: Date: Thu, 7 Jan 2021 17:06:25 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101080002 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9857 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101080002 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 1/7/21 7:11 AM, Muchun Song wrote: > On Thu, Jan 7, 2021 at 10:11 PM Michal Hocko wrote: >> >> On Thu 07-01-21 20:59:33, Muchun Song wrote: >>> On Thu, Jan 7, 2021 at 8:38 PM Michal Hocko wrote: >> [...] >>>> Right. Can we simply back off in the dissolving path when ref count is >>>> 0 && PageHuge() if list_empty(page->lru)? Is there any other scenario >>>> when the all above is true and the page is not being freed? >>> >>> The list_empty(&page->lru) may always return false. >>> The page before freeing is on the active list >>> (hstate->hugepage_activelist).Then it is on the free list >>> after freeing. So list_empty(&page->lru) is always false. >> >> The point I was trying to make is that the page has to be enqueued when >> it is dissolved and freed. If the page is not enqueued then something >> racing. But then I have realized that this is not a great check to >> detect the race because pages are going to be released to buddy >> allocator and that will reuse page->lru again. So scratch that and sorry >> for the detour. >> >> But that made me think some more and one way to reliably detect the race >> should be PageHuge() check in the freeing path. This is what dissolve >> path does already. PageHuge becomes false during update_and_free_page() >> while holding the hugetlb_lock. So can we use that? > > It may make the thing complex. Apart from freeing it to the > buddy allocator, free_huge_page also does something else for > us. If we detect the race in the freeing path, if it is not a HugeTLB > page, the freeing path just returns. We also should move those > things to the dissolve path. Right? > > But I find a tricky problem to solve. See free_huge_page(). > If we are in non-task context, we should schedule a work > to free the page. We reuse the page->mapping. If the page > is already freed by the dissolve path. We should not touch > the page->mapping. So we need to check PageHuge(). > The check and llist_add() should be protected by > hugetlb_lock. But we cannot do that. Right? If dissolve > happens after it is linked to the list. We also should > remove it from the list (hpage_freelist). It seems to make > the thing more complex. You are correct. This is also an issue/potential problem with this race. It seems that adding the state information might be the least complex way to address issue. -- Mike Kravetz