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 08333C433EF for ; Thu, 28 Apr 2022 12:35:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FA396B0082; Thu, 28 Apr 2022 08:35:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A8496B0083; Thu, 28 Apr 2022 08:35:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 322746B0085; Thu, 28 Apr 2022 08:35:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 222426B0082 for ; Thu, 28 Apr 2022 08:35:18 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E80AB29F9F for ; Thu, 28 Apr 2022 12:35:17 +0000 (UTC) X-FDA: 79406233074.22.D7ABA8A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 6B2F212006C for ; Thu, 28 Apr 2022 12:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651149317; 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=nGWQ6H7zY//+ePLV7y3mXzYy2j68sneKy+Fe3Uh+WKw=; b=KNJ2Li3Q0wGUwR1JyctR0IuE7Nf0kPkYFnk952XcFk1+Y5yM6hbCvb0d4is4MHUm6a8AjC xx3L8nuDjJCPzf2CGmnuBkeO+AN9GPlvcjKZaCVB/ylTIJTe25/gIX2Z524ZJITgBull5V o1P2iXN/Fc1gl3PDhvrOD69VI6TfEaU= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-190-V-s9BKuGOGiffxmhl2fQHQ-1; Thu, 28 Apr 2022 08:35:15 -0400 X-MC-Unique: V-s9BKuGOGiffxmhl2fQHQ-1 Received: by mail-ed1-f71.google.com with SMTP id s24-20020a05640217d800b00425e19e7deaso2682039edy.3 for ; Thu, 28 Apr 2022 05:35:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=nGWQ6H7zY//+ePLV7y3mXzYy2j68sneKy+Fe3Uh+WKw=; b=EIiZsVV5QOyKmBQ4xlw6kry+vsSWM013/QC9xEslIDxjqXLepUe2wkU+sk4LF6RgC+ Zqc6QHI60DyHc9VF5caqFhTC1rDohKgRc+/F1NLFczo4lMqbT96FjH10VIo1Zmvk63kh RdRzHa1C9AfxYOqT9obdpFS0dw4QKh3C3eXxFCCJUYDsEhF3CagQ/RyJJ0VlsaT07Dat K4iLbi3lR3F7RmlvyAHAEQhODXjpVvHg4pSlHoMf36gCg3ANHoW+z5/Z88inJSxltxYQ JqhwSbk7nXddWnsDxZMzHcVAETTjMgfJyHa0fE2PY1SKJFQFk226S0beAbeGG7LTdY5F GGLw== X-Gm-Message-State: AOAM530dpBeTKA3hbzk+xCERt1Yj481+Y8/oN+U4GQyCa6u7yKB+Ix44 SmjcVOhnKDWzzkslR0VKCg2VbCPiyoj2ZzadeKuJ5k7y5+DlEJCnGGZ00WnEIvZj92TG7qarqM6 OSUP4JwKQLrU= X-Received: by 2002:aa7:cd0a:0:b0:425:bc13:4ccb with SMTP id b10-20020aa7cd0a000000b00425bc134ccbmr34085912edw.229.1651149314523; Thu, 28 Apr 2022 05:35:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5fl50Q/sAa6D8th7Nk6LW9E3kVKKq1obRR9aikELreRwxgNIJHimE11UjYQ7ynsMj1mw9zQ== X-Received: by 2002:aa7:cd0a:0:b0:425:bc13:4ccb with SMTP id b10-20020aa7cd0a000000b00425bc134ccbmr34085879edw.229.1651149314257; Thu, 28 Apr 2022 05:35:14 -0700 (PDT) Received: from ?IPV6:2003:cb:c708:ef00:7443:a23c:26b8:b96? (p200300cbc708ef007443a23c26b80b96.dip0.t-ipconnect.de. [2003:cb:c708:ef00:7443:a23c:26b8:b96]) by smtp.gmail.com with ESMTPSA id su22-20020a17090703d600b006f3a97cda9esm4579895ejb.18.2022.04.28.05.35.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Apr 2022 05:35:12 -0700 (PDT) Message-ID: <7946f6ca-fe03-e286-32f9-b22ff1edb52f@redhat.com> Date: Thu, 28 Apr 2022 14:35:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH 3/3] mm/memory_hotplug: Refactor hotadd_init_pgdat and try_online_node To: Oscar Salvador , Andrew Morton Cc: Michal Hocko , Wei Yang , Miaohe Lin , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220307150725.6810-1-osalvador@suse.de> <20220307150725.6810-4-osalvador@suse.de> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220307150725.6810-4-osalvador@suse.de> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 6B2F212006C X-Stat-Signature: mxucwrjfxtsbxkjht71ffi57q7kkak9z X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KNJ2Li3Q; spf=none (imf29.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam09 X-HE-Tag: 1651149314-74430 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: On 07.03.22 16:07, Oscar Salvador wrote: > Since we pre-allocate all nodes now, hotadd_init_pgdat() does > not need to return a pgdat struct, as that was meant for > __try_online_node() to check whether the node was succesfully > allocated. > > Also get rid of the __ref as all functions hotadd_init_pgdat() > calls fall within the same section. > > Also try to make more clear the return codes from __try_online_node(). > __try_online_node() can return either 0, 1 or -errno (the latter not really > as the BUG_ON() would catch it before we return) but depending on the caller > that has different meanings. > For add_memory_resource(), when __try_online_node() returns non-zero, > it means that the node was already allocated and it does not need to bring > it up. It is fine not to check for -errno values because we do not > get to call register_one_node() when !set_node_online. > For those who call try_online_node(), so set_node_online is true, a value > other than zero means a failure (e.g: cpu_up() or find_and_online_cpu_nid()). > > Signed-off-by: Oscar Salvador > --- > mm/memory_hotplug.c | 35 ++++++++++++++--------------------- > 1 file changed, 14 insertions(+), 21 deletions(-) > > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 07cece9e22e4..5c92ac81a399 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -1161,8 +1161,7 @@ static void reset_node_present_pages(pg_data_t *pgdat) > pgdat->node_present_pages = 0; > } > > -/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ > -static pg_data_t __ref *hotadd_init_pgdat(int nid) > +static void hotadd_init_pgdat(int nid) > { > struct pglist_data *pgdat = NODE_DATA(nid); > > @@ -1182,8 +1181,6 @@ static pg_data_t __ref *hotadd_init_pgdat(int nid) > * to access not-initialized zonelist, build here. > */ > build_all_zonelists(pgdat); > - > - return pgdat; > } > > /* > @@ -1193,31 +1190,27 @@ static pg_data_t __ref *hotadd_init_pgdat(int nid) > * called by cpu_up() to online a node without onlined memory. > * > * Returns: > - * 1 -> a new node has been allocated > - * 0 -> the node is already online > - * -ENOMEM -> the node could not be allocated > + * 1 -> The node has been initialized. > + * 0 -> Either the node was already online, or we succesfully registered a new > + * one. > + * -errno -> register_one_node() failed. > */ > static int __try_online_node(int nid, bool set_node_online) > { > - pg_data_t *pgdat; > - int ret = 1; > + int ret; > > if (node_online(nid)) > return 0; > > - pgdat = hotadd_init_pgdat(nid); > - if (!pgdat) { > - pr_err("Cannot online node %d due to NULL pgdat\n", nid); > - ret = -ENOMEM; > - goto out; > - } > + hotadd_init_pgdat(nid); > + > + if (!set_node_online) > + return 1; > + > + node_set_online(nid); > + ret = register_one_node(nid); > + BUG_ON(ret); > > - if (set_node_online) { > - node_set_online(nid); > - ret = register_one_node(nid); > - BUG_ON(ret); > - } > -out: > return ret; BUG_ON(ret); return ret; hm? This will never return :) So either leave the old code flow or "return 1;" I'd actually prefer the old code flow to then "return 1;" here: if (set_node_online) { node_set_online(nid); BUG_ON(register_one_node(nid)); } return 1; We can then let go of "ret". -- Thanks, David / dhildenb