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 32F44C4707B for ; Wed, 10 Jan 2024 21:55:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 893A18D0003; Wed, 10 Jan 2024 16:55:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8434E8D0001; Wed, 10 Jan 2024 16:55:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70B418D0003; Wed, 10 Jan 2024 16:55:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 616DC8D0001 for ; Wed, 10 Jan 2024 16:55:20 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3939E16041C for ; Wed, 10 Jan 2024 21:55:20 +0000 (UTC) X-FDA: 81664758000.05.4E2B876 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by imf24.hostedemail.com (Postfix) with ESMTP id C3AC3180016 for ; Wed, 10 Jan 2024 21:55:17 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="e/Slo0DE"; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf24.hostedemail.com: domain of tim.c.chen@linux.intel.com has no SPF policy when checking 198.175.65.9) smtp.mailfrom=tim.c.chen@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704923718; 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=ItDbikXpEyuQqAnU+ILQFGkkup2ssCJVSI6q9uTey2c=; b=IhugG3i/LVQFf9jssmeb7L9JIqq92lNw4itNLY3+1XcW2M3o3xRwQ6V3vJgOopVTDKqRLb U4lxSgmnEWtVL2szTwdDzPy4Up96cnOAMAmCuPi/xdftVQhxqF07N0Yra6WdAGJnEoovKG hIsKU6yYnfuTIV/8R56Sr572DwEX/ls= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="e/Slo0DE"; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf24.hostedemail.com: domain of tim.c.chen@linux.intel.com has no SPF policy when checking 198.175.65.9) smtp.mailfrom=tim.c.chen@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704923718; a=rsa-sha256; cv=none; b=konut+L/1mD5Glw/jjhN2XXboeJkKnybkmc7yx8q/VVjhjxd8+hQ2UB6sdaneGfOfnlbVo AUiJl1e5XxI3URDv1QzITaMlk8aHivmzEFDoJS4NCwhof3OmlDOpP0Rx7FamRnr+kRuxv0 Qp8afoZu2GMTXKD/GHuj5WjpZjm71/8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704923718; x=1736459718; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=kauCl20DmtVewkNVcUeFNOrPm0xT7hFAub/QzXwa5Qw=; b=e/Slo0DEtMBxF+BGeGjUPUhSLD0kZoh2nydRrjUqM9pEtcK2szNMpcke JanFAum4dW5pdpJ+tVfuCsKvRzukF/1NSuepQF0owAE73a9CB30LlqxTC 0Z6GNPoMMchsjLZvUeoAiTMGdhPFZzZZE4mg+gG3bz798O5X+sFc9dPsx Z04OhtAoWVdEE4ul/ybbJNL+l0f6n79f9hSluCwGlOVtW2/T7eJTei9ZB Fvu6U9xZOZbrNY/+4DUuaLYRoHnHxa8cd3rfV74Mqkm1bqi3ZaxSt9kBE zr01ajWhJ5lxLmdpcdc74jyc0SwY74FyhZstm98CZgF3RJoo4NofZXo+a w==; X-IronPort-AV: E=McAfee;i="6600,9927,10949"; a="17261980" X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="17261980" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 13:55:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,184,1695711600"; d="scan'208";a="30741455" Received: from phungng1-mobl.amr.corp.intel.com (HELO [10.255.229.71]) ([10.255.229.71]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2024 13:55:16 -0800 Message-ID: <46769d44703b2f8d2e279d6e95db960c8a87e39c.camel@linux.intel.com> Subject: Re: [PATCH v3 1/7] hugetlb: code clean for hugetlb_hstate_alloc_pages From: Tim Chen To: Gang Li , David Hildenbrand , David Rientjes , Mike Kravetz , Muchun Song , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com Date: Wed, 10 Jan 2024 13:55:15 -0800 In-Reply-To: <20240102131249.76622-2-gang.li@linux.dev> References: <20240102131249.76622-1-gang.li@linux.dev> <20240102131249.76622-2-gang.li@linux.dev> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 93w8x4iz6nkcg8tbxxhcamcc41rixmfj X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C3AC3180016 X-HE-Tag: 1704923717-891993 X-HE-Meta: U2FsdGVkX1/vOS1x52ZYEhoq5i5hQw3EM3hpfNZvq9vCzMHDvObnytrz02dRgub2q+cDllie1q92SvqwJlJkQ2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s3NGZlehTc 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: On Tue, 2024-01-02 at 21:12 +0800, Gang Li wrote: > The readability of `hugetlb_hstate_alloc_pages` is poor. By cleaning the > code, its readability can be improved, facilitating future modifications. >=20 > This patch extracts two functions to reduce the complexity of > `hugetlb_hstate_alloc_pages` and has no functional changes. >=20 > - 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. Minor nit, I think hugetlb_hstate_alloc_pages_errcheck() is more descriptive than hugetlb_hstate_alloc_pages_report(). Otherwise Reviewed-by: Tim Chen >=20 > Signed-off-by: Gang Li > --- > mm/hugetlb.c | 46 +++++++++++++++++++++++++++++----------------- > 1 file changed, 29 insertions(+), 17 deletions(-) >=20 > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index ed1581b670d42..2606135ec55e6 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3482,6 +3482,33 @@ static void __init hugetlb_hstate_alloc_pages_onen= ode(struct hstate *h, int nid) > h->max_huge_pages_node[nid] =3D i; > } > =20 > +static bool __init hugetlb_hstate_alloc_pages_node_specific(struct hstat= e *h) > +{ > + int i; > + bool node_specific_alloc =3D false; > + > + for_each_online_node(i) { > + if (h->max_huge_pages_node[i] > 0) { > + hugetlb_hstate_alloc_pages_onenode(h, i); > + node_specific_alloc =3D true; > + } > + } > + > + return node_specific_alloc; > +} > + > +static void __init hugetlb_hstate_alloc_pages_report(unsigned long alloc= ated, 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 allocat= ed %lu hugepages.\n", > + h->max_huge_pages, buf, allocated); > + h->max_huge_pages =3D 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(struc= t hstate *h) > struct folio *folio; > LIST_HEAD(folio_list); > nodemask_t *node_alloc_noretry; > - bool node_specific_alloc =3D false; > =20 > /* 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(stru= ct hstate *h) > } > =20 > /* 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 =3D true; > - } > - } > - > - if (node_specific_alloc) > + if (hugetlb_hstate_alloc_pages_node_specific(h)) > return; > =20 > /* below will do all node balanced alloc */ > @@ -3558,14 +3577,7 @@ static void __init hugetlb_hstate_alloc_pages(stru= ct hstate *h) > /* list will be empty if hstate_is_gigantic */ > prep_and_add_allocated_folios(h, &folio_list); > =20 > - 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 allocat= ed %lu hugepages.\n", > - h->max_huge_pages, buf, i); > - h->max_huge_pages =3D i; > - } > + hugetlb_hstate_alloc_pages_report(i, h); > kfree(node_alloc_noretry); > } > =20