From patchwork Fri Jan 26 15:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 192654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:106:343:edcb with SMTP id ju23csp7389dyc; Fri, 26 Jan 2024 07:25:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGICch80LkRv8buoP6L0vO6Z6EoyIs9uy0DpJAmBZ5CEUHYaSyajhvpl4KEeaH72O9OpwcA X-Received: by 2002:a17:902:bd82:b0:1d7:c27:2d3c with SMTP id q2-20020a170902bd8200b001d70c272d3cmr1377185pls.6.1706282723858; Fri, 26 Jan 2024 07:25:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706282723; cv=pass; d=google.com; s=arc-20160816; b=SrTy+2gLYY6anrPpBIBA0g1zHMIVGQd71r02l8MMyb0Xg29sDv3o3Az1MdRJWVkuBR xSxFcqBxSLJsBsC0oF0P9Ux95Hhj3mv7WX2cV1cQ7beSW3c/PZngeDa1Irs6/c0c6j7D WnrHttx9nEiDRmauvAOK84rVO9LpyMWUOXyxj8+fHd+UogtWJpvaxq+L+zPolZDqc7mI 1vDL/9j3EOSPtNXC8gSqFunaLz7heLinaNcmdCRwDXaH1CbGDKOEdiSoflbtMSF44/oH fwOU8PYrfV5GI8QGQy7V4x6VexWoYdxnnGtPqZZrNA1aIsxo0crsPmve1B2JJRdP2xFC jNiA== 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=P9aNrm9Rl6VWe92w5Q1+H7U7+x0T3IY85gF9i1XPLD0=; fh=5n5b5+XOwLgGNDePhvfXysty56rnkWOs9jaHEODdVeE=; b=Kl9Bt5wjxbOWxRzOntZK51Prf+U2VfV/o8CNGSe7PpTil4cbBQCmeDs4X6IoTjlCko e/MrqZZxViI8m6oabyDUPIwtVe7hpoqS3EvTyPqOGTDf8AuAC11j1426hVrCH39pxK9k 90wPb1hW6xlf0v4PBjGVw0pyIhxcLkV337SvhrOH2M6oU3GpS+d5Ba4pgaGVKut6ZZ3x mBkqgSJ1+W9U+pbp+Zo6pD9zvQ1zXID6e3J4CDEpJI1E8YTdjQfvgFMPAjS33DexPG4Y VPJzonCa+sjlivFSLAA82fDXZ4HrTBvNUwury9FzJ8NJpXwWl84tgFpimEmkFsAwCIBe B84Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Z2mGLWb9; 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-40268-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40268-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m4-20020a170902db0400b001d773be7a63si1315415plx.26.2024.01.26.07.25.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 07:25:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40268-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Z2mGLWb9; 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-40268-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40268-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9BD10282429 for ; Fri, 26 Jan 2024 15:25:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6CFF01D693; Fri, 26 Jan 2024 15:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Z2mGLWb9" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (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 1BBBC1CF91 for ; Fri, 26 Jan 2024 15:24:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706282701; cv=none; b=nD7q1HV94BtN6Qk3+J0WB8rWTQBbmrSNm/VIfEcUSrr2CgOXshyyjwEaXZKCmD0xyZVbdKlq31QagUYVNx6BG3Dg0cCk9QaSL5BRV9IGSiVRlOmrKl2ERf8hwgiBeuRXtchbjG9r0b60o+ibqiJwY1ZBhLcD+Emqj993k/53yLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706282701; c=relaxed/simple; bh=JynJSsrcEmEyDiudVXgdLpdbaxMIxOCbRPacHoaDnbQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=elMGBtMqd3WwB9Ekd6QqBeNQ6tY/uipBvmVc7ELoyYnDM8QeGWqY6FsW2+41m75wS9ea+5/xQZuJjjOCrnAnjT9c3Me0QfAi6cT9oRUQ0tv5nnTu1KNx0+KgFwMtvTJKmePq/HEViyXB3l+n3dn8mnPR/eb4nyr0oBp8YbjeL4s= 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=Z2mGLWb9; arc=none smtp.client-ip=95.215.58.171 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=1706282697; 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=P9aNrm9Rl6VWe92w5Q1+H7U7+x0T3IY85gF9i1XPLD0=; b=Z2mGLWb9xrBuI0vOVD3E/NJFwQiuaje5gheixSf/WVC/8b+43XxkctLePzaM1b5Q45N43H jiACbC9uRwNgXG1Aj/uKYCxw/54Qrw4qopzYmDpDtD28Eu+qzsQAz6NeImrzqeJQQJWWKD oNdPxdCl8DH8xl4A48uiL4uj+fNJQvE= 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 v5 1/7] hugetlb: code clean for hugetlb_hstate_alloc_pages Date: Fri, 26 Jan 2024 23:24:05 +0800 Message-Id: <20240126152411.1238072-2-gang.li@linux.dev> In-Reply-To: <20240126152411.1238072-1-gang.li@linux.dev> References: <20240126152411.1238072-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 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789167113862059573 X-GMAIL-MSGID: 1789167113862059573 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 2cf78218dfe2e..20d0494424780 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); }