Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp249630rwb; Wed, 21 Sep 2022 21:42:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ErRsQWK1GoYl5t4RlsF5GUudvcE1A7L/wfmhKQJz6cN5kw4DvEfpcpS+txL3dFJfxvrTX X-Received: by 2002:a17:902:8c90:b0:178:b9c9:9793 with SMTP id t16-20020a1709028c9000b00178b9c99793mr1461101plo.151.1663821740329; Wed, 21 Sep 2022 21:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663821740; cv=none; d=google.com; s=arc-20160816; b=PVeWX/bksWx7BHUeTvw2Do6Cg5L/z/YmBmdcEYxRFf7ysEm3U8LCqVEzVnUlYaj3lF AB6O5zBgajzSQ2jynXxeQUzOS9hOeM1tbcRZspFguxEHF/kyUlHONh1ZbWnqpMnXu0iK iPmxIYaqWYqJuwFjkoBUkMo5tz0/ToTgIkqAEW0I5/b+akGoW/XuyPkWmnxRvYzIxcuH wPNWbAUeh/Wct1HoeW8/kjMiJCfLwYBIQrWpgT5TJq5rDa1E9NimyNsXMdc/PIBaWA6r W3siOEimZJ3Kx7BY7UUX9Ai1eySzbkkcQAyKu5TGzMVT8huYQ9euVEtPzYV5HS331e5e beRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=LjD8rPTf8lcbI7hYOccNQfDum1yqtk7Eqs7SD0RHwLw=; b=nFdru9jiolwXOSVrZUb+j586g8gnyaPLgKWD2w/5eHceLu+EtoVvc8M0LzDkxZwBi/ hf4mp35oDXfiWESuwY4cHpCYMPuZtXYe1qrU8JPCE4NoLuOj8QqgPBjCOYiHkh8vu2Xe NRYumwqxJsKpMXDPlBi5DzxYxQ4sBCw2oGsraGFsM3umOey0rCUnPBt2Sj9V+EHN7tg+ vBHLNka0VXFOBleFLnF8qeLXlk2Ej5lWYpaQSgDhwS9nIpbj9jPNHB4DeqXcHUiu2zlM lTEXKpqVcgQd6XeMI8AhhUqRHgCr1OXNXWJL6ZB/CMcsoN9dQAaoI31m74JQePdW0taf S74g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=dUmG1yIE; dkim=neutral (no key) header.i=@suse.de; 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=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mh17-20020a17090b4ad100b001fb3503ff97si5570243pjb.8.2022.09.21.21.42.08; Wed, 21 Sep 2022 21:42:20 -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; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=dUmG1yIE; dkim=neutral (no key) header.i=@suse.de; 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=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbiIVEP1 (ORCPT + 99 others); Thu, 22 Sep 2022 00:15:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbiIVEPZ (ORCPT ); Thu, 22 Sep 2022 00:15:25 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8128832CC for ; Wed, 21 Sep 2022 21:15:24 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id ECF331F8DB; Thu, 22 Sep 2022 04:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1663820122; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LjD8rPTf8lcbI7hYOccNQfDum1yqtk7Eqs7SD0RHwLw=; b=dUmG1yIErk4qsNgbsFq+xuzScYW3ciQu8Tj5t7+g57G2H4LiRcSTjiY/sCBttj8e955ooV sRmDWO0VkRqOL4gtM2H+kBsLrFYglkqcc2tAmSorfeobVim2A6EUPSm2lH3iDbsXK67w1W sS/iQv2BU2tmOn9nmgHYqkehpWtlbfM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1663820122; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LjD8rPTf8lcbI7hYOccNQfDum1yqtk7Eqs7SD0RHwLw=; b=uSHSU/CAvx2hNoUld+4CAJsUJp5e5zK1+uG4mj25fq2oNHy8rKOqZccpV/uldyNiZ9qigg 9MrVvPBwEPvzZ2DA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3E3A6139EF; Thu, 22 Sep 2022 04:15:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id G3JUDFrhK2NEBAAAMHmgww (envelope-from ); Thu, 22 Sep 2022 04:15:22 +0000 Date: Thu, 22 Sep 2022 06:15:20 +0200 From: Oscar Salvador To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Joao Martins , Matthew Wilcox , Michal Hocko , Peter Xu , Miaohe Lin , Naoya Horiguchi , Vlastimil Babka , Andrew Morton Subject: Re: [PATCH v3] hugetlb: freeze allocated pages before creating hugetlb pages Message-ID: References: <20220921202702.106069-1-mike.kravetz@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220921202702.106069-1-mike.kravetz@oracle.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Wed, Sep 21, 2022 at 01:27:02PM -0700, 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 Looks good to me, and it makes the code much more simple: Reviewed-by: Oscar Salvador -- Oscar Salvador SUSE Labs