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 AE2B4C001DC for ; Wed, 19 Jul 2023 02:35:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26144280026; Tue, 18 Jul 2023 22:35:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EA708D0012; Tue, 18 Jul 2023 22:35:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06442280026; Tue, 18 Jul 2023 22:35:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E85648D0012 for ; Tue, 18 Jul 2023 22:35:21 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A7B52A00AE for ; Wed, 19 Jul 2023 02:35:21 +0000 (UTC) X-FDA: 81026794842.24.048313E Received: from out-56.mta1.migadu.com (out-56.mta1.migadu.com [95.215.58.56]) by imf26.hostedemail.com (Postfix) with ESMTP id BC93A140008 for ; Wed, 19 Jul 2023 02:35:18 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=n0asVgRi; spf=pass (imf26.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.56 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689734119; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E9ZAEbBiO24j7Uknj5PMKtSmu00bsu4fHz6ctS0uYi8=; b=ZK5F2oY9bXAKMJ7oNY0pctEg8p7/LyPGlJyGaI3/R+lr888FGo2w6GeXSNgF9rXYF83gk9 A6KtLqhRbfp0sjPpdFtnNeSCdTdal+9uiYQq/dSFDrt9EzDMPNrJV/RhfMvMXY3YOH5NhC z/StMPrJpUIJ3AtLDXYB4XucxUcQfWE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689734119; a=rsa-sha256; cv=none; b=WqRR1HBB0z4a8UarUbC8yzpqEb8o1sDEoFKvDhvtEVNAOaTjzXaGozFFOVyXRrcAxljicz 9dubDwBvwXgFCKesowFCQARvcsjuTGbWAZSxUl6HEvr82tLezI9y5o2jjiuvM0pm79zEVe yBuO4NFgNwnCgg8J9dP0ht0slPL8deI= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=n0asVgRi; spf=pass (imf26.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.56 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1689734116; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E9ZAEbBiO24j7Uknj5PMKtSmu00bsu4fHz6ctS0uYi8=; b=n0asVgRiKnEBpyy9M1+lERgGLufw19A9QodAMrALzkWRaj5U6PtL8Oxgm592EvQRn6p6RZ gpiOyhAV0RHQCG9XzBocXXqaQbUbtEJQyf4VWcZFbMYhYpw1Ns6TrWF5/urtuidNDtZkSh sZnvHKgALLeThB1MKDjpaXG8D1MM93c= MIME-Version: 1.0 Subject: Re: [PATCH v2 1/2] hugetlb: Do not clear hugetlb dtor until allocating vmemmap X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20230718004942.113174-2-mike.kravetz@oracle.com> Date: Wed, 19 Jul 2023 10:34:36 +0800 Cc: Linux Memory Management List , LKML , Jiaqi Yan , Naoya Horiguchi , Muchun Song , Miaohe Lin , Axel Rasmussen , James Houghton , Michal Hocko , Andrew Morton , stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <4015AB29-76AD-4CA7-89C4-5916E2F8670B@linux.dev> References: <20230718004942.113174-1-mike.kravetz@oracle.com> <20230718004942.113174-2-mike.kravetz@oracle.com> To: Mike Kravetz X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: BC93A140008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: keb54nnhdhai5wip3w7brmh4ygf6woj7 X-HE-Tag: 1689734118-444211 X-HE-Meta: U2FsdGVkX1+Him9oAxFTWqVGwmiAYQLpbcCyHSwEDpS/r6VHX7FIdOWg0kRPNTYonZpz3bEzDBfxpO/GiDeMM5r0uprKbC7AN5YTNAy1JnP2eRWPZWVy7iUMJmwPjB3Rl2Th1nvEsgK4gR86FH+5YG8mgTwFMtVswvz/fon29cYJbxG0WMhQuBba5h9Tfr17WPCW0f72WfnJH0xa+WiiehSOlhBQVlmroiMzId9rgM2ZX5jnrw6YeYF3prPRs94YWKfjvTKKb9VV4iSSrJuRvhchOrkBSfa6EAn+3p8K5gs/j0f+GR/Mj/nVw9MxHHAeOpLNoJ12gDhu5mrTcA+e+lhI58vYcq8mGYDJnthV6unZPw2AxguHwZ5Y0flCeNFlJWBiaXCj7rHtPK2bPGz2DzrcRA45Rj5CIt4BV76xPCtvGy3XZZDoY8PjkppXhARyXEu8t17yI76bGs60oQDdCQnHrxAzOnoRhE4IjLOKA64qrvU31fifJ85QoQ6xPrVOnDaL7nvgcNsXAYu7pW2ifl5KxLtpKGcIKpXYvgFEz1KlRSXJBwaUYLo2Ftxr7lugHjlEotoWd9oesU7xIRqR1KuowBb2Y3BJ7nc6ZXTBa20rEDdpkBpOAGnn5AcSkg5yGZf6NdTdnPIW/lwIolvobhxLX665NICT8t+4yUoIvMyduf0/ALJSV7WtaHkhkyVlMGNEXc2PwOojugRQodjkub7RJ3ZRHdqRBzxRSsBDAncU3FToSFEFwYVScCzEP2/xfNqUFBcGyQUXEeG7PlxoOfzcaNvnARWnQZk5GrvH9AI9UXfhJD2lb/ncMtBcfreoU7/jeEE164Sa7zHz3+yN8PYqmd1KlqLM5O0m4eb4R9HckJMKVCHJXUze0z2K0ULwrL8QnCjhL4V4rURX5LYhROZoZaFMhGiyUKC7xKS7kKi7W6iLH8lh08DiHcng/1fTebdULljxujkGOEBuQgW k8YdTU8y MSGtlzCuJkO7DkQO4G9UbLHdKcMW66KR1vzeYGlZScfPltZ6u71kNWeV2jEcds0iO+KyF4Gef7PEHh/0+sYvT4mkAkPhEcmrdct5r3sqKRInUmRr4fk5GdIMZjYXeNLFmExCWIEZ2qsbfd0x6TqN6TowPulYs44yTDqqAQIn1M4qOo/wh7AHrTr5zIfej/FPYfPQMLnzpVrKZrE28f0iMOcaeaEnhjqBMPjL7CC66kG890vM= 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 Jul 18, 2023, at 08:49, Mike Kravetz = wrote: >=20 > Freeing a hugetlb page and releasing base pages back to the underlying > allocator such as buddy or cma is performed in two steps: > - remove_hugetlb_folio() is called to remove the folio from hugetlb > lists, get a ref on the page and remove hugetlb destructor. This > all must be done under the hugetlb lock. After this call, the page > can be treated as a normal compound page or a collection of base > size pages. > - update_and_free_hugetlb_folio() is called to allocate vmemmap if > needed and the free routine of the underlying allocator is called > on the resulting page. We can not hold the hugetlb lock here. >=20 > One issue with this scheme is that a memory error could occur between > these two steps. In this case, the memory error handling code treats > the old hugetlb page as a normal compound page or collection of base > pages. It will then try to SetPageHWPoison(page) on the page with an > error. If the page with error is a tail page without vmemmap, a write > error will occur when trying to set the flag. >=20 > Address this issue by modifying remove_hugetlb_folio() and > update_and_free_hugetlb_folio() such that the hugetlb destructor is = not > cleared until after allocating vmemmap. Since clearing the destructor > requires holding the hugetlb lock, the clearing is done in > remove_hugetlb_folio() if the vmemmap is present. This saves a > lock/unlock cycle. Otherwise, destructor is cleared in > update_and_free_hugetlb_folio() after allocating vmemmap. >=20 > Note that this will leave hugetlb pages in a state where they are = marked > free (by hugetlb specific page flag) and have a ref count. This is = not > a normal state. The only code that would notice is the memory error > code, and it is set up to retry in such a case. >=20 > A subsequent patch will create a routine to do bulk processing of > vmemmap allocation. This will eliminate a lock/unlock cycle for each > hugetlb page in the case where we are freeing a large number of pages. >=20 > Fixes: ad2fa3717b74 ("mm: hugetlb: alloc the vmemmap pages associated = with each HugeTLB page") > Cc: > Signed-off-by: Mike Kravetz Reviewed-by: Muchun Song Thanks.