Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp316372rdb; Thu, 18 Jan 2024 04:39:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhnDQRHHlpClUFwdXD/LzuXCR43lRWJ2M1JOEvE8m4GdgDsrgzbNuS8aV04tLIl//ed6Q9 X-Received: by 2002:a05:6214:1d09:b0:681:157:f9ed with SMTP id e9-20020a0562141d0900b006810157f9edmr770682qvd.99.1705581584115; Thu, 18 Jan 2024 04:39:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705581584; cv=pass; d=google.com; s=arc-20160816; b=KSDBnVRSgy6nkC5QiLykYnWnpF2l2/pxX+6/IUI/+qq3r3uCpr0k80Fh2JCUG8MEUn Uahf80L9tMDSUG2cU7IPLPZxtSq/cv6dEc2jfUo620t543AJ4u3XHPjTxWgamkduFaZD HI3Npdzuit1by7mCr7SCzOdKvGjh8BLDzl2N+KbCDPA9yqZRDG7bJP9zL/xc+LCgDD6x l+/T1Euo8rOnqB8tANL0tHF13ZheYmPQUqUS3+UfC4dHQz03wUxJ5U4jG6cNfz2yagQC 6BjvNuP808Qz5dvm7WQdsbYaZ7dYhoxy5bCRCIMkGAM0cOrJ0GhrKvdcdL4yhfBW/K0Q o+3g== 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=ExNhxk12A1ggZeTlNcXFGggLGZAANw7/uA5h1igFwws=; fh=5n5b5+XOwLgGNDePhvfXysty56rnkWOs9jaHEODdVeE=; b=cITJk76yYZkEsDuUMUhfNfRQoXDOrOKZ2fbvJRJ4cEIR2LgkXPfGgFXDhOg0mzKIq6 SsbsnyG+hOKy0PZxQDvKknCYdI+75a4evNgM+CAKH5KavhU79KUMy0cbJYMJ16fihvOP vpQmxchRl1SIdUoBDapzNFA326xDzZTavb5jBI6thhT/QaUcYAbW1WdnPCyC6mbYbhfz FHnMXQvYuRbdF9egqkMD1X+xTtsl/hib0D4h5CTGnoQ6SQyNBynItNVhA02vrO1sE5Lr Hm/mTblHcIWLJxBM1/e+KRqZ2k2QWosDodGPc5heoKR6D/a6drmPn3NEaeBPTTrIlReQ biXw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pG+RITuc; 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-30104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30104-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 r23-20020a0cb297000000b0067ab557459fsi14155155qve.305.2024.01.18.04.39.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:39:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30104-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=pG+RITuc; 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-30104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30104-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 DB9C01C22770 for ; Thu, 18 Jan 2024 12:39:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10A65250FA; Thu, 18 Jan 2024 12:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pG+RITuc" Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (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 BF92B24218 for ; Thu, 18 Jan 2024 12:39:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705581567; cv=none; b=vDdmZbdjGwuzM0eH8Fd3ZjkGF6zGYGhGn2agAwprnt2TxtzX04CsiZKF0VyVK/9FI4ltQeMQEKl4CWaC1tA/GYsI4oCLK4l746egdkdkxvIW6JY/96PfE7WjpdaAM3eNjgQOiq7FlrwzFbnzGkCuCyj1g9UeumHLeFaM3+zNweQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705581567; c=relaxed/simple; bh=19wxRPGuWzdYtgWW1oofCQJ69J7HTW3D6AE90rHpxLY=; h=X-Report-Abuse:DKIM-Signature:From:To:Cc:Subject:Date:Message-Id: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: X-Migadu-Flow; b=gZYwoaNNM0BukFM/sBp4VIM68iZk6KYK05On7D1Q0PqSkj4yclpsPccW1ecqRQl3W9n56mRw90I138ONjRfKwk5Pt3Hl2yt4xj2iHW9XrmGVh5Vk0K873TkQX+DiRSsye8nuhS9AJOY7LBwDvgAvpxVgDDqGu9IQ0vqzeXk6PKQ= 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=pG+RITuc; arc=none smtp.client-ip=95.215.58.180 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=1705581562; 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=ExNhxk12A1ggZeTlNcXFGggLGZAANw7/uA5h1igFwws=; b=pG+RITucTavbLnmWFp3E6QAPFq6rT1oIcvMFugCJGPD5YHA51y/POAMaILEiYttWA6sMqo fe6xZrMWrKZkEmcTKROczOtPuUp9k7PzdRptuHFedB7YlplZR/bOKcT3VabFLJ3wGJqTlz HkA+MBmGSrPMVAGd220o9Ilf16iE0ac= From: Gang Li To: David Hildenbrand , David Rientjes , Mike Kravetz , Muchun Song , Andrew Morton , Tim Chen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, Gang Li Subject: [PATCH v4 1/7] hugetlb: code clean for hugetlb_hstate_alloc_pages Date: Thu, 18 Jan 2024 20:39:05 +0800 Message-Id: <20240118123911.88833-2-gang.li@linux.dev> In-Reply-To: <20240118123911.88833-1-gang.li@linux.dev> References: <20240118123911.88833-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 ed1581b670d4..b8e4a6adefd6 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