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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DF9EC433EF for ; Fri, 24 Jun 2022 08:15:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231253AbiFXIPj (ORCPT ); Fri, 24 Jun 2022 04:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbiFXIPa (ORCPT ); Fri, 24 Jun 2022 04:15:30 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B22D6E798 for ; Fri, 24 Jun 2022 01:15:29 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LTqbJ168LzSgx5; Fri, 24 Jun 2022 16:11:56 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 24 Jun 2022 16:15:19 +0800 Subject: Re: [PATCH v2 1/9] mm/hugetlb: remove checking hstate_is_gigantic() in return_unused_surplus_pages() To: Muchun Song CC: Naoya Horiguchi , Andrew Morton , David Hildenbrand , Mike Kravetz , Liu Shixin , Yang Shi , Oscar Salvador , Naoya Horiguchi , , Linux-MM References: <20220623235153.2623702-1-naoya.horiguchi@linux.dev> <20220623235153.2623702-2-naoya.horiguchi@linux.dev> <0b69e3ef-0123-4575-b68d-4d9b2067aa0e@huawei.com> From: Miaohe Lin Message-ID: Date: Fri, 24 Jun 2022 16:15:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/6/24 16:03, Muchun Song wrote: > On Fri, Jun 24, 2022 at 10:25:48AM +0800, Miaohe Lin wrote: >> On 2022/6/24 7:51, Naoya Horiguchi wrote: >>> From: Naoya Horiguchi >>> >>> I found a weird state of 1GB hugepage pool, caused by the following >>> procedure: >>> >>> - run a process reserving all free 1GB hugepages, >>> - shrink free 1GB hugepage pool to zero (i.e. writing 0 to >>> /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages), then >>> - kill the reserving process. >>> >>> , then all the hugepages are free *and* surplus at the same time. >>> >>> $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages >>> 3 >>> $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/free_hugepages >>> 3 >>> $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/resv_hugepages >>> 0 >>> $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/surplus_hugepages >>> 3 >>> >>> This state is resolved by reserving and allocating the pages then >>> freeing them again, so this seems not to result in serious problem. >>> But it's a little surprizing (shrinking pool suddenly fails). >>> >>> This behavior is caused by hstate_is_gigantic() check in >>> return_unused_surplus_pages(). This was introduced so long ago in 2008 >>> by commit aa888a74977a ("hugetlb: support larger than MAX_ORDER"), and >>> it seems to me that this check is no longer unnecessary. Let's remove it. >> >> s/unnecessary/necessary/ >> >>> >>> Signed-off-by: Naoya Horiguchi >>> --- >>> mm/hugetlb.c | 4 ---- >>> 1 file changed, 4 deletions(-) >>> >>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >>> index a57e1be41401..c538278170a2 100644 >>> --- a/mm/hugetlb.c >>> +++ b/mm/hugetlb.c >>> @@ -2432,10 +2432,6 @@ static void return_unused_surplus_pages(struct hstate *h, >>> /* Uncommit the reservation */ >>> h->resv_huge_pages -= unused_resv_pages; >>> >>> - /* Cannot return gigantic pages currently */ >>> - if (hstate_is_gigantic(h)) >>> - goto out; >>> - >> >> IIUC it might be better to do the below check: >> /* >> * Cannot return gigantic pages currently if runtime gigantic page >> * allocation is not supported. >> */ >> if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) >> goto out; >> > > The change looks good to me. However, the comments above is unnecessary > since gigantic_page_runtime_supported() is straightforward. Agree. The comments can be removed. > > Thanks. Thanks for reviewing. > >> But I might be miss something. >> >> Thanks. >> >>> /* >>> * Part (or even all) of the reservation could have been backed >>> * by pre-allocated pages. Only free surplus pages. >>> >> >> > . >