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 8D38BC3DA6E for ; Wed, 10 Jan 2024 10:20:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A8DE6B0078; Wed, 10 Jan 2024 05:20:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 059246B007B; Wed, 10 Jan 2024 05:20:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E893C6B007E; Wed, 10 Jan 2024 05:20:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DAD696B0078 for ; Wed, 10 Jan 2024 05:20:22 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A8C69A0412 for ; Wed, 10 Jan 2024 10:20:22 +0000 (UTC) X-FDA: 81663006684.14.25688CF Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf02.hostedemail.com (Postfix) with ESMTP id 9ADB980011 for ; Wed, 10 Jan 2024 10:20:20 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=CK2U00TA; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf02.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=muchun.song@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704882020; 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=HqWLnzHdhYYeRCqMae8M6cQn2qiQCuRsbTV+dKiFGmo=; b=2vgLoEXYjUKl6mGIJ7zFeyxHul+qLRQrzoMpoElDaH05pMDUlDu7IWwXPnzIAy13f6YbYy tRRVAI9t4Hs8QydVZtJzGf4xgMR1gVJ9w59YUjPqqfMdB8adi83dPKOPwsDY+lzYjgFGY8 0oFdmZHQHkJOC+davHfDNbzMT7BhM/I= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=CK2U00TA; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf02.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=muchun.song@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704882020; a=rsa-sha256; cv=none; b=eRA9O5T+5oKLTuWf9SDcmit0UCo0HwPBlgvrCDniBR2ib7BEmnBFjOASvgiM0FZm3HzLwF jD4rbc/9jSTAqYAnm3NTS9YSsZgmXFzoYGCeALsI8kvRJ0phJOVLTwrTSjOQ//jJjG8AeE QrAwyW2DJF2H46PZRQyxtrj0fmi/91A= Message-ID: <73111be3-3077-4821-8c2f-9c5564cb2bb7@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1704882018; h=from:from: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; bh=HqWLnzHdhYYeRCqMae8M6cQn2qiQCuRsbTV+dKiFGmo=; b=CK2U00TAoeJZ6otiqwyvKNb+WcXawuJ82/NZd9tetCf8iTBiKMn7NAC9B/zf42c5olKs7C jhGDBJMgEPZGg+e/Vd8rlmjcFITXUVHH+g6grdLSJW6vzqXGZSa84zjzRcck0H1BKUtfiD KwxG0N/Cw1i/0IhbkMXjD7tehX+NSVo= Date: Wed, 10 Jan 2024 18:19:49 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v3 1/7] hugetlb: code clean for hugetlb_hstate_alloc_pages To: Gang Li Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, David Hildenbrand , David Rientjes , Mike Kravetz , Andrew Morton , Tim Chen References: <20240102131249.76622-1-gang.li@linux.dev> <20240102131249.76622-2-gang.li@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20240102131249.76622-2-gang.li@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: rw76ko44a5gg1j45z4pzst53ksnn1m6s X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9ADB980011 X-HE-Tag: 1704882020-91934 X-HE-Meta: U2FsdGVkX1/Pm7zEFl13GaT3W/u7Mszc68lHj7gVJw+Wdl4n4jf1pX1RnXc9xi/Rwp7gEFsmbcxoKtSvS4jhV13gAip6BrLyiRjWPxIvE0gW4pxB4jITDAai7LtoT4GpvP83FxnxRfr0R7Q1pq820tiZOrPNCwA1HroAnOXwSRDC1UkjpWVJgWCasSCndkjhcU2XBHUXnupUY8JIqNa1fOv0Uc0LjxLUMzbuxAY//9j4/6JtbhhOSmvxS9HHH+G6IN2NW16ET2BkUOqqGa83SP1+wMhx2RJxmYBd5N9kzx/uxqgSPJN82+5oj01dRqolYPN/2k+wdimEllkcHo7va1eU7ugjKMuTTWlLHs4nIJEKncb8tuhLojmqS6suS8SuYZPpO9kB93MgluDglIbhebWP0P9oLOwx5mrnT/nm44L6ajl3yOU/gGo2nxrOCZF2t3T2yOsj89t3RZqOsW0U0ROeLcx9wqRc6QSgrCXGJbM5zEvYqSkUct6B0Vy49vOxhv7EMzL+Fy38xHVSbwHxC5Ri6ETO2pPRyfCoXaJxRR3HLpLk11CIp40zmEX8p8y/A989fhaa7Pgy0NY5PSVVF84F03D8RV/ilCS35tfEyIzYB8cyexmgWm3nrLzfleuYKLFKojFE9HjCYlOyUwBdjxjGfcsN17/PTXpAa9mCmE8XZNjmJcpm66csBlyCdxdX2jOsqrsZQrFzMpsGWEji31KAZXoQCWz1LSD6z5M8h7LrNYG2wS/rZpo25IIuQxp7Am348ZFhtr6Et+OlR3I184qBxmoirzFgiNJtihghAMI1wWxkwQImLr7OMlg/tZ811uwuUiOXFhAkWn4kXzdRJ8A6XidcN+ie4SJXL+dYK3Orw2MX+bH7+I3di5ULvUTOprA2mFkuhd2C5rWO9f2w3y8OyzfvtrjAD9cGP8ey54nT6HNslGtlT6T9uQnixsRt5HNrAqKi4fnDgaB9C16 jLnTru7V pPgsfRe/qkjdOAzjWkkigFeGho8J6/7u93bbh3dIIXmKLxI1j3ZTLZMATw3RjG696RYfnyRJj2mN5Kh04PXDeZ0+6zPNF2rNsnNj0u9OWACCLTSg9sqU7xzQ8e644CRiML9hz 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 2024/1/2 21:12, Gang Li wrote: > 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 > --- > mm/hugetlb.c | 46 +++++++++++++++++++++++++++++----------------- > 1 file changed, 29 insertions(+), 17 deletions(-) > > 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_onenode(struct hstate *h, int nid) > h->max_huge_pages_node[nid] = i; > } > > +static bool __init hugetlb_hstate_alloc_pages_node_specific(struct hstate *h) I'd like to rename this to hugetlb_hstate_alloc_pages_specific_nodes. Otherwise, LGTM. Reviewed-by: Muchun Song > +{ > + 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_report(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_node_specific(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_report(i, h); > kfree(node_alloc_noretry); > } >