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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29CEBC54EE9 for ; Thu, 22 Sep 2022 04:15:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59BB86B0078; Thu, 22 Sep 2022 00:15:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54BEE6B007B; Thu, 22 Sep 2022 00:15:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EC0E940007; Thu, 22 Sep 2022 00:15:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 305CB6B0078 for ; Thu, 22 Sep 2022 00:15:25 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EF6191A1362 for ; Thu, 22 Sep 2022 04:15:24 +0000 (UTC) X-FDA: 79938406968.22.E2C5E2B Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf29.hostedemail.com (Postfix) with ESMTP id 78EA012000F for ; Thu, 22 Sep 2022 04:15:24 +0000 (UTC) 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> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663820124; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LjD8rPTf8lcbI7hYOccNQfDum1yqtk7Eqs7SD0RHwLw=; b=J6qgBwwjj48lhwKXa5ZdzewsTyMoQq1v1D806RaXFHlzmxhltbdksNXveuGMY0TxG1wGJh Q/KscU57XdtwEGC2hI0eF/4PoceMFXBiZjEd0IUTKC3GYc3H/RtgZpEg5h7qvAe0ueY3/N cIlHveHHmhp41xQC/KiS0j8MY7MCNwo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=dUmG1yIE; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="uSHSU/CA"; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663820124; a=rsa-sha256; cv=none; b=RKk7LtNClHqf5cXsfFSS3QKx1KxfZK4LHJKJ0P53Aigd8OBOLyIjY4rKGToaxxqawx9nCI nGHGolp9xkBfAWK0gkZwoRMcbcSe28e4XCBeYdBbzwCwITXMf488c/UozfYHnbTflsqfut bH7YUuTFXAOZaWsZRBF3QrAKtMkV+io= X-Rspam-User: X-Stat-Signature: 6nnhp7wq986bo995tzrxfp6s74kskmoq X-Rspamd-Queue-Id: 78EA012000F Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=dUmG1yIE; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="uSHSU/CA"; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf29.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Rspamd-Server: rspam08 X-HE-Tag: 1663820124-577402 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 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