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 7EE2AC54ED0 for ; Fri, 23 May 2025 08:06:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C0616B00C5; Fri, 23 May 2025 04:06:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 171486B00C6; Fri, 23 May 2025 04:06:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0603C6B00C8; Fri, 23 May 2025 04:06:14 -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 D2D3D6B00C5 for ; Fri, 23 May 2025 04:06:14 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 65CA2C1BE5 for ; Fri, 23 May 2025 08:06:14 +0000 (UTC) X-FDA: 83473439868.13.CBE9256 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.8]) by imf20.hostedemail.com (Postfix) with ESMTP id E79BF1C0004 for ; Fri, 23 May 2025 08:06:11 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=eK6KCAMD; spf=pass (imf20.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.8 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747987572; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=rp6Hjx/YmyVFhd+IZDZGfGqixxaOhCtM0oD2AcUcjns=; b=VuRpkte4230NIAox9CW6/IfOX4s2YvXmLyMwtxWvIqcu9AClWwU3B47JrbEgiCFlqkkXsA ewXNtEbnvvjke9CYmd56KJpwtqY+Q1XPkVkwWU5bihkoT+tgc8t+1g90DuoAqgrbtRFWTv K6R4onMjDVwwiOTg4CbVH6kM0/dxdXI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=126.com header.s=s110527 header.b=eK6KCAMD; spf=pass (imf20.hostedemail.com: domain of yangge1116@126.com designates 117.135.210.8 as permitted sender) smtp.mailfrom=yangge1116@126.com; dmarc=pass (policy=none) header.from=126.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747987572; a=rsa-sha256; cv=none; b=6j2hAKPPVF/oAgDOld48ab3yOU0N/Ox0pqGVeezxxvk9d8m+oPIVBVzUAtqrxN5I8pXGz9 Z0DZe2a48RnL18LfERZi87K39LplT9I1sX6VAvBZ0ZyVni1AlOCbmpB1hgZidFfzu9+Pbq kYycF/zKLhPK+iJZDKauCoa7fbxHoUo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=rp6Hjx/YmyVFhd+ IZDZGfGqixxaOhCtM0oD2AcUcjns=; b=eK6KCAMD40HqGN8n0ZYfBa1SW/Wzawb x1FcUtyHLSJuXWz3XqVxGtbRGPsvmeq7E6uCiNBt3ave7tM7kuUjS1Zu0zBwmMTB sQ4zJMmNWqz0gscWhlB758DQILUiTy4MCm6KHYPc+jXVSdQTLdqFpQ8D2oUfFm0b Tfk9nODcBA2k= Received: from hg-OptiPlex-7040.hygon.cn (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wDXb09qLDBosZMgAg--.61413S2; Fri, 23 May 2025 16:06:03 +0800 (CST) From: yangge1116@126.com To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, 21cnbao@gmail.com, david@redhat.com, baolin.wang@linux.alibaba.com, muchun.song@linux.dev, osalvador@suse.de, liuzixing@hygon.cn, Ge Yang Subject: [PATCH] mm/hugetlb: remove redundant folio_test_hugetlb Date: Fri, 23 May 2025 16:05:59 +0800 Message-Id: <1747987559-23082-1-git-send-email-yangge1116@126.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID:_____wDXb09qLDBosZMgAg--.61413S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGF4rXryfZw4rtrWDGF1kGrg_yoWruryUpF W3GrsxtrWkXa4DWr4xAr4kJrn0k34DX34UtFWxKFWavF4aqw1UKF1DZw18XayrCr9rJFWf ZF4jqFWv9F4jy3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zNQ6JUUUUUU= X-Originating-IP: [112.64.138.194] X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbidQFWG2gwKKR7KgAAs8 X-Rspam-User: X-Rspamd-Queue-Id: E79BF1C0004 X-Rspamd-Server: rspam09 X-Stat-Signature: tbptpfz1kfohex86p9qpy8ocbwhxz9h4 X-HE-Tag: 1747987571-738815 X-HE-Meta: U2FsdGVkX1+rz3gp6dFrIR3ubvEv+D1gpEgRWtchylp5X5H2KU6hBGDFoVZ5+uaZ/VMz13sN8FIw4N0Gcey7cLWqEWjqEzaQsPbPVo/rvc1ftdx2LRpoe07wU59/963GnX8vsze4nF7NncZpa9dLHfNM6R4AiAjcdQuIN5CbrYCn1NjRCiQFudmesVD/623laofz/PvrwvQe4o7xd5IsQS5yUqGKUt7TqmnyN5g391Xw42KNsd7ojnXpujehiGxtXszVBpSmlV/WBblAmvt6T6hKww9zx5PeL5DQ8K7cQpmICg4h+PugzmxsRmKySdNaPdlopJeDH+WVRIMdBr5wReGMEq+yFnxUm9GZBotZoGjugVTsA+pZSXdN8x6alKjpaDX7jQPRN4HQYD33vY66Tbph4kZJAzHnFpkypV7UQFRNkk+MTgKE2dp/OtIZOSlP0eImZlW/9/BJNTwhOft75N1E+8O1vCem2XHyJNQMHVqCzRS7oh02vv13k1NUfJq6FZSijVpE+1QBjHTbL0qfBZfQnWpJs6W6/vNE1Fn0r6T/mq0DFDSeZVKuHXgSbyxfxbOWH5KHgkXSczT1DnEevA1JTwQ4JMOxRgGovCPucH229T0jwUDrkPcZSK/ch6d9k0gHn3omaaWro6s51CzBccwwIJ1pBEuWJ4gPNBl6GLQxKfCufj568HgnRU2N8xEsBdsEtJNIQG61u+jyjAH7NlYIYTogc0sgm4U8ujcsBAcPg+H77YVSJCCDwwkxZlKNA5s7xyGVaDlDosZxr6o6O6qdw9MezvdZ03FMkUHpOaLhfCxX6wxp5PpHHM/d/N4ITKflJCTuxlzR3vQRECbIbTDKOu9lNzB3hSLQz0K4eoX6r5CqFnoEv1h6PxiG5OZTIHBQg+3LTGaA8p0HVoCptPQfcZsCwS25e3rdx4Un8rHxM/NJkMGssFVjLIUcqX6smFpBMoFl3h5j/TyzDWw WN4GUxvc gzMVuQ+kwLvajEhIq81Yr5V0jt2RjCPgVuzCGv/A5fFBXQrpePgnvcWZyh4hqBrmp+ki9Qnf81Oqn/05rKces34ay2ZGJBItaUU0WCXasHH8wlmRHBU80/9XrTPk9yyORYIspMZmKCejEFTjnLrRrBwu77wjdW+2U8/lrCn6+bnZ57V5oHwt16Am/H9Xzdb2eT4eSglAzh+XPiVOIjdmubgGSr/V5OqxEZ/eMmxvNK3Ne7hqCKAlaR4VVOKdKmr9d2HmWRUWq7iYA3xa7EWG6ewaLOWTuUREhp0tPMmub2yFOz+9hQLGBORo3M/FWIlrVVwqyiuUksH0IbWwHCWxCCcoEmlAQUH8dNozZn5FgvZN29UxJit9vcqoVSw== 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: List-Subscribe: List-Unsubscribe: From: Ge Yang In the isolate_or_dissolve_huge_folio() function, the folio_test_hugetlb() function is called to determine whether a folio is a hugetlb folio. However, in the subsequent alloc_and_dissolve_hugetlb_folio() function, the folio_test_hugetlb() function is called again to make the same determination about whether the folio is a hugetlb folio. It appears that the folio_test_hugetlb() check in the isolate_or_dissolve_huge_folio() function can be removed. Additionally, a similar issue exists in the replace_free_hugepage_folios() function, and it should be addressed as well. Suggested-by: Oscar Salvador Signed-off-by: Ge Yang --- mm/hugetlb.c | 51 +++++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 6c2e007..6e46f2f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2787,20 +2787,24 @@ void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma, /* * alloc_and_dissolve_hugetlb_folio - Allocate a new folio and dissolve * the old one - * @h: struct hstate old page belongs to * @old_folio: Old folio to dissolve * @list: List to isolate the page in case we need to * Returns 0 on success, otherwise negated error. */ -static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, - struct folio *old_folio, struct list_head *list) +static int alloc_and_dissolve_hugetlb_folio(struct folio *old_folio, + struct list_head *list) { - gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; + gfp_t gfp_mask; + struct hstate *h; int nid = folio_nid(old_folio); struct folio *new_folio = NULL; int ret = 0; retry: + /* + * The old_folio might have been dissolved from under our feet, so make sure + * to carefully check the state under the lock. + */ spin_lock_irq(&hugetlb_lock); if (!folio_test_hugetlb(old_folio)) { /* @@ -2829,8 +2833,10 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, cond_resched(); goto retry; } else { + h = folio_hstate(old_folio); if (!new_folio) { spin_unlock_irq(&hugetlb_lock); + gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; new_folio = alloc_buddy_hugetlb_folio(h, gfp_mask, nid, NULL, NULL); if (!new_folio) @@ -2874,35 +2880,20 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, int isolate_or_dissolve_huge_folio(struct folio *folio, struct list_head *list) { - struct hstate *h; int ret = -EBUSY; /* - * The page might have been dissolved from under our feet, so make sure - * to carefully check the state under the lock. - * Return success when racing as if we dissolved the page ourselves. - */ - spin_lock_irq(&hugetlb_lock); - if (folio_test_hugetlb(folio)) { - h = folio_hstate(folio); - } else { - spin_unlock_irq(&hugetlb_lock); - return 0; - } - spin_unlock_irq(&hugetlb_lock); - - /* * Fence off gigantic pages as there is a cyclic dependency between * alloc_contig_range and them. Return -ENOMEM as this has the effect * of bailing out right away without further retrying. */ - if (hstate_is_gigantic(h)) + if (folio_order(folio) > MAX_PAGE_ORDER) return -ENOMEM; if (folio_ref_count(folio) && folio_isolate_hugetlb(folio, list)) ret = 0; else if (!folio_ref_count(folio)) - ret = alloc_and_dissolve_hugetlb_folio(h, folio, list); + ret = alloc_and_dissolve_hugetlb_folio(folio, list); return ret; } @@ -2916,7 +2907,6 @@ int isolate_or_dissolve_huge_folio(struct folio *folio, struct list_head *list) */ int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long end_pfn) { - struct hstate *h; struct folio *folio; int ret = 0; @@ -2925,23 +2915,8 @@ int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long end_pfn) while (start_pfn < end_pfn) { folio = pfn_folio(start_pfn); - /* - * The folio might have been dissolved from under our feet, so make sure - * to carefully check the state under the lock. - */ - spin_lock_irq(&hugetlb_lock); - if (folio_test_hugetlb(folio)) { - h = folio_hstate(folio); - } else { - spin_unlock_irq(&hugetlb_lock); - start_pfn++; - continue; - } - spin_unlock_irq(&hugetlb_lock); - if (!folio_ref_count(folio)) { - ret = alloc_and_dissolve_hugetlb_folio(h, folio, - &isolate_list); + ret = alloc_and_dissolve_hugetlb_folio(folio, &isolate_list); if (ret) break; -- 2.7.4