Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2219430rwb; Sat, 24 Sep 2022 05:07:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7yzG6n5Kztqns6SVxAM+FBfRxF4DjE57wTX8fZUAr5TIyW3CcYbqjpGbkAiVWUOHJwJK97 X-Received: by 2002:a17:906:4791:b0:783:b09:cae3 with SMTP id cw17-20020a170906479100b007830b09cae3mr1272059ejc.759.1664021245667; Sat, 24 Sep 2022 05:07:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664021245; cv=none; d=google.com; s=arc-20160816; b=pe4JFD39xpOuCewkVQdNQQDO1a7j/THSt/N3oGyN0+1STtxYSTKC1CgnDbfKI5H6p8 NDnqvgeB1fMGJdttvcAJQkqXCuZGp7BT83xPUsjAdowDrvZmSFTJr1ZPofZ7NzBmszzj n7zIYZ3ACOjK7f2n2LcHHQM9gB1Q8GUS/rOEr0Du6WxfzmhA4DpNS+oiQFGa5L8mFbIs 4M/IXDwzlhtEe8EtkXtzEeiUXhESE3/e9vHfbtc5AdkREkdHfk6HCPMQTUvJ2VEFW03O hdtbkitBLWhefzsTGC1VMOUMkiBRx8FcSDB4ZJ2SbjpaQDWru59fx3pTurH8J2qIgfqI 3cHQ== 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=18DZO6SGCwMOFWyQOilCWm/2B3T3JULIpE+HMVCNAMs=; b=A9KEfzAoDLSlVwXsfwwwOjLC2rcxx4QpdXq6lYmm3BzHZt8SJAkyPoP4WzJO2pKfIu Wis4r9YM4sGRLrdwPaX0Q6JbrGbY5p7udjFg1wODW8O3YtyZvABxfEX0P5gklckwc5ds 8uB7EIBvYkiYseDnDIlwlG778Mqv1oJy0J65AnqtrJhYyLoijh7H9zMsLcWEjmQNcshs R4/UXlx7Kjr5cN9MFjInrlxJNv7r56fnz7LGSkBPA/pl/VFG2DVqaAf7Ck2Bf7bnNZks KIVcWqPYtxZHmXaDxuTYoDZImj9+7cLbcC24/tARJhW/CORd29dfREXqUmNAQn/osfkn go/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w7-20020a056402268700b00449902443a0si9877930edd.23.2022.09.24.05.06.49; Sat, 24 Sep 2022 05:07:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233133AbiIXLUN (ORCPT + 99 others); Sat, 24 Sep 2022 07:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbiIXLUL (ORCPT ); Sat, 24 Sep 2022 07:20:11 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CAB02B1B7 for ; Sat, 24 Sep 2022 04:20:07 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MZRK567xNzlWkK; Sat, 24 Sep 2022 19:15:53 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) 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.31; Sat, 24 Sep 2022 19:20:04 +0800 Subject: Re: [PATCH v3] hugetlb: freeze allocated pages before creating hugetlb pages To: Mike Kravetz , , CC: Muchun Song , Joao Martins , Matthew Wilcox , Michal Hocko , Peter Xu , Oscar Salvador , Naoya Horiguchi , Vlastimil Babka , Andrew Morton References: <20220921202702.106069-1-mike.kravetz@oracle.com> From: Miaohe Lin Message-ID: Date: Sat, 24 Sep 2022 19:20:04 +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: <20220921202702.106069-1-mike.kravetz@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/9/22 4:27, Mike Kravetz wrote: > When creating hugetlb pages, the hugetlb code must first allocate > contiguous pages from a low level allocator such as buddy, cma or > memblock. The pages returned from these low level allocators are > ref counted. This creates potential issues with other code taking > speculative references on these pages before they can be transformed to > a hugetlb page. This issue has been addressed with methods and code > such as that provided in [1]. > > Recent discussions about vmemmap freeing [2] have indicated that it > would be beneficial to freeze all sub pages, including the head page > of pages returned from low level allocators before converting to a > hugetlb page. This helps avoid races if we want to replace the page > containing vmemmap for the head page. > > There have been proposals to change at least the buddy allocator to > return frozen pages as described at [3]. If such a change is made, it > can be employed by the hugetlb code. However, as mentioned above > hugetlb uses several low level allocators so each would need to be > modified to return frozen pages. For now, we can manually freeze the > returned pages. This is done in two places: > 1) alloc_buddy_huge_page, only the returned head page is ref counted. > We freeze the head page, retrying once in the VERY rare case where > there may be an inflated ref count. > 2) prep_compound_gigantic_page, for gigantic pages the current code > freezes all pages except the head page. New code will simply freeze > the head page as well. > > In a few other places, code checks for inflated ref counts on newly > allocated hugetlb pages. With the modifications to freeze after > allocating, this code can be removed. > > After hugetlb pages are freshly allocated, they are often added to the > hugetlb free lists. Since these pages were previously ref counted, this > was done via put_page() which would end up calling the hugetlb > destructor: free_huge_page. With changes to freeze pages, we simply > call free_huge_page directly to add the pages to the free list. > > In a few other places, freshly allocated hugetlb pages were immediately > put into use, and the expectation was they were already ref counted. In > these cases, we must manually ref count the page. > > [1] https://lore.kernel.org/linux-mm/20210622021423.154662-3-mike.kravetz@oracle.com/ > [2] https://lore.kernel.org/linux-mm/20220802180309.19340-1-joao.m.martins@oracle.com/ > [3] https://lore.kernel.org/linux-mm/20220809171854.3725722-1-willy@infradead.org/ > > Signed-off-by: Mike Kravetz Thanks Mike. The code looks more simple. Reviewed-by: Miaohe Lin Thanks, Miaohe Lin