Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp357680rdb; Thu, 22 Feb 2024 06:06:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXiEh7n7t6fT1d2Uw6BQpfvDz/Oki+Fs15sKnisEhmuTFWEgmtOBjvf9n7DXut/6Uugcr/L6EAa9RSOzQtQ/8En3JqqI67u5E5khTxnDg== X-Google-Smtp-Source: AGHT+IGGZfa22bnW0maU8QHfgXT8tnL87jaSc+j35V6iPq8mvJw7ohCdt/zX07tX0L0NaKEXaXXM X-Received: by 2002:a0c:ca92:0:b0:68f:1901:299c with SMTP id a18-20020a0cca92000000b0068f1901299cmr20280739qvk.15.1708610777209; Thu, 22 Feb 2024 06:06:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708610777; cv=pass; d=google.com; s=arc-20160816; b=b/TXXy8JMWf+KRGJnjtkduAtXTVmpewLiUQBM4c6cNdgHiXICE+L4wM7V1QbaJTmlf Mv39GckNj0PykDDL8omC7gHD0mnVHuVEH0wLUtIOBPoic7fOaWqyCZ+xYmtM7cO0K7l0 wsaoGoi+pB5k5FSY5n2foTLwa2xZHAIWFerQqVUgglfouS8wkvc1YxisvvqRONOPMkHE V2++lA74w/ReQgVASsU7W5kyB0cPjgaNpR2cutk1NWQ2rjDUW5unEjLAQeUfABs8tqjL /gjmYaZQ6LoizaP+Ett4EcRGcYymReqrLdddjoAONegWIcJXSwW5ubT4XwkmNa81j2pB c8hw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qLDJ0oXYyRPh9zz0wE8IXI1bSRdqq7PDnnR6TGU9VgU=; fh=yRWAnXCrDeo1JkXV9iUtee7xVlLig8radlX7vPmVxyI=; b=A/3p43G+uLvVLZRUeFtFA1E/6H7Amki0mfhuApdemzcUbfWk86lKPxiGM4Sx4/ui96 eXGo9/qD6UPxZ3rkFHc7MmaH8vIWdso3ErKAoT9h7PnMbhSgHPz1adVo5fXiScVT8ESP 7FSOqeAgb/SOqYty9NsK8UFy12y4jY1dBYElaqnsUQIJbyomyezkB+KbnnjEo6hAk6y5 NxlS/TdIjvixSL3ELZP0TJwnx6byLmCjIGEltf3W5fO7j7HB+7exaxipKe1FeSiFUBMx mT+GBbMJ42fGzR4oXsrUsoti9j9lrkeiClp8BB5D+lx8KCws0iLZ/RCdjQKd3yhZ6EG0 uGWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=i3uRvd9J; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-76662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76662-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id hf1-20020a0562140e8100b0068f78b7739dsi7984086qvb.528.2024.02.22.06.06.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 06:06:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=i3uRvd9J; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-76662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76662-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8A5D51C25AD2 for ; Thu, 22 Feb 2024 14:05:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41F7914535B; Thu, 22 Feb 2024 14:04:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="i3uRvd9J" Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 782EC1474A4 for ; Thu, 22 Feb 2024 14:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708610690; cv=none; b=sGUFOgsC4egy+wuHmRHyKGNgmxB2uj7P1iSuywJSHRxCkexdtNWlfDd6YjbGsseFfEv+SEsaWiMwkKCtphkX64yPL70zK+rVj6PYCDOjMjrzztO1FPKV8Ho68/c9U1MlM9dL2MsiiCEO+F3Itp15rdLsvletDf8ps2Crl1FIlBE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708610690; c=relaxed/simple; bh=9Nlv5yU9lraOMOB9dfIUMrxAw7ypqQN0Obqwia5pjOo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Tv7tR7D1/QoVuyuZxrH9a9W651ymOGuK9NDh7wCJ+z/oF/dUw8TExGAvetfsvexl7IBu0KNBQmvGtLSl2bDhOhUgAlaOSiR+5NklFEDGUKZF524oNw8KnnOBp9+/CXybxoz1Zpz2QcB4qKFSd9jCOoL+FlYGYNW/ny7+jOgAIBk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=i3uRvd9J; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708610686; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qLDJ0oXYyRPh9zz0wE8IXI1bSRdqq7PDnnR6TGU9VgU=; b=i3uRvd9JstCtGlLa8/tyWtExImE0JtGxaojcIRs7n7nhFDNAP1r0mFxWuFGnV0DVJck360 +ybW3ROURTCTJyB8p7i3fvB985dnVQ3LNtm4RXv8GdUo6fpAsYQ3cBv0H6OF+4mHm7dqT7 SiYS5mOQGsqbMvVVng+9nU3mjbwRkQs= From: Gang Li To: Andrew Morton Cc: David Hildenbrand , David Rientjes , Muchun Song , Tim Chen , Steffen Klassert , Daniel Jordan , Jane Chu , "Paul E . McKenney" , Randy Dunlap , linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, Gang Li Subject: [PATCH v6 1/8] hugetlb: code clean for hugetlb_hstate_alloc_pages Date: Thu, 22 Feb 2024 22:04:14 +0800 Message-Id: <20240222140422.393911-2-gang.li@linux.dev> In-Reply-To: <20240222140422.393911-1-gang.li@linux.dev> References: <20240222140422.393911-1-gang.li@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT The readability of `hugetlb_hstate_alloc_pages` is poor. By cleaning the code, its readability can be improved, facilitating future modifications. This patch extracts two functions to reduce the complexity of `hugetlb_hstate_alloc_pages` and has no functional changes. - hugetlb_hstate_alloc_pages_node_specific() to handle iterates through each online node and performs allocation if necessary. - hugetlb_hstate_alloc_pages_report() report error during allocation. And the value of h->max_huge_pages is updated accordingly. Signed-off-by: Gang Li Tested-by: David Rientjes Reviewed-by: Muchun Song Reviewed-by: Tim Chen --- mm/hugetlb.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c53a41d07cd3a..794f3e6a19bb6 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3482,6 +3482,33 @@ static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) h->max_huge_pages_node[nid] = i; } +static bool __init hugetlb_hstate_alloc_pages_specific_nodes(struct hstate *h) +{ + int i; + bool node_specific_alloc = false; + + for_each_online_node(i) { + if (h->max_huge_pages_node[i] > 0) { + hugetlb_hstate_alloc_pages_onenode(h, i); + node_specific_alloc = true; + } + } + + return node_specific_alloc; +} + +static void __init hugetlb_hstate_alloc_pages_errcheck(unsigned long allocated, struct hstate *h) +{ + if (allocated < h->max_huge_pages) { + char buf[32]; + + string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); + pr_warn("HugeTLB: allocating %lu of page size %s failed. Only allocated %lu hugepages.\n", + h->max_huge_pages, buf, allocated); + h->max_huge_pages = allocated; + } +} + /* * NOTE: this routine is called in different contexts for gigantic and * non-gigantic pages. @@ -3499,7 +3526,6 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) struct folio *folio; LIST_HEAD(folio_list); nodemask_t *node_alloc_noretry; - bool node_specific_alloc = false; /* skip gigantic hugepages allocation if hugetlb_cma enabled */ if (hstate_is_gigantic(h) && hugetlb_cma_size) { @@ -3508,14 +3534,7 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) } /* do node specific alloc */ - for_each_online_node(i) { - if (h->max_huge_pages_node[i] > 0) { - hugetlb_hstate_alloc_pages_onenode(h, i); - node_specific_alloc = true; - } - } - - if (node_specific_alloc) + if (hugetlb_hstate_alloc_pages_specific_nodes(h)) return; /* below will do all node balanced alloc */ @@ -3558,14 +3577,7 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) /* list will be empty if hstate_is_gigantic */ prep_and_add_allocated_folios(h, &folio_list); - if (i < h->max_huge_pages) { - char buf[32]; - - string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); - pr_warn("HugeTLB: allocating %lu of page size %s failed. Only allocated %lu hugepages.\n", - h->max_huge_pages, buf, i); - h->max_huge_pages = i; - } + hugetlb_hstate_alloc_pages_errcheck(i, h); kfree(node_alloc_noretry); } -- 2.20.1