Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3540499pxp; Tue, 8 Mar 2022 17:00:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVWkJzQ+Mh99DqOW3yg3y59ZFYs+Iau95egJdVIK9d0uXtzZqG0DNDDiLyNZSPFDa9iUz6 X-Received: by 2002:a65:6c0c:0:b0:378:d9d6:cd0a with SMTP id y12-20020a656c0c000000b00378d9d6cd0amr16011059pgu.117.1646787631289; Tue, 08 Mar 2022 17:00:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646787631; cv=none; d=google.com; s=arc-20160816; b=bAeQACdT/aQ+FGqc4DcDRSUhtiS80nXQYLpEGKOh3DPYBA4sT0iJlH+qQJ0EsetTA4 UPZkjCo37KNP3PdKqbXwy/72kEu+5Zet9G2q4dLGqeDkgMGPk4Yn0TknHrdX2HtFch6E BEP5YTAS2PisGhKcZBV8+wkuRI+G0m9MQ3afMfrEV29FfXbfgRNkI4wdd+qTy971ekLX J9Pj3yzsR9lRca59JlI2kDgqILRfJBHCyAIM2cjzJuiRLMTQmEz5PY07v0w6bwSF01oZ aFFoOpAw/GX38KOxObpTmw+inbjfPo5dZQq1Kv27VjRnTzx5Ksx/uBTZDY2/d15W7szm PsOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=3P7bIRLrBlFDijrCRgEyPsvaDPLZQ9uN0q/x7eaR+p0=; b=rASfNruDSz7OD4YgLVmzjl32Mmzj2LOwJZoBV4EamD1zukm9OhRV9bxpal713GRF3x jglTC4x/UV6ZVwSUarO91cFn144h8nE1z/9dQb5AMvM6+69r1v0qwpj0uEhewHmStMi7 vLvrS1g2I1YpVjwBq0+N0RCf0oE8jt1M8WOwOWaztkdf0vw2Mq3lycUhSW/8D5fpPhnG g2lREAqxQGPhhMnoMtM2sW5Ebm3iB6VyvXeGyA9/KPmCUR2MYT8G9w/cp1r3X7FPc9xw bcki3hIc+B6QKPen5E0OmBr9ZeCVrmnUnOa69oirOqOpkw5oarAmGueyI2Q7Qpws8jYu boYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Ey7TZ3Rt; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g6-20020a1709026b4600b0014a083779e4si438277plt.622.2022.03.08.17.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:00:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Ey7TZ3Rt; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F107B163D46; Tue, 8 Mar 2022 16:08:26 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236388AbiCGPIj (ORCPT + 99 others); Mon, 7 Mar 2022 10:08:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242498AbiCGPIc (ORCPT ); Mon, 7 Mar 2022 10:08:32 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 934C41260E for ; Mon, 7 Mar 2022 07:07:38 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 451591F396; Mon, 7 Mar 2022 15:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1646665657; h=from:from:reply-to: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=3P7bIRLrBlFDijrCRgEyPsvaDPLZQ9uN0q/x7eaR+p0=; b=Ey7TZ3RtHRDRJfjlRvqYGfgCeXP6f2e/zRCCnY0fgKG+lWYsIszX1S0JeOD0iI27d9FANs tuAtcOnnQkyna/xA02xRXWVx8vqENll2LjOAKLAhL+6nmVki01Um8UZ6XeCpBYpoOs4YJy MpxRC9LshIBY1+5Sm80cxTgxfftE1Uw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1646665657; h=from:from:reply-to: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=3P7bIRLrBlFDijrCRgEyPsvaDPLZQ9uN0q/x7eaR+p0=; b=bk0rwY2cBrRtaQPiDVmNf/T1xTP4vhye4JE996PHCMKFUBCfYkvXZ+ODoldNb+f4Gr+V34 YBZ0mSifN2993CBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C38FB132BC; Mon, 7 Mar 2022 15:07:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gIoJLbgfJmLrHgAAMHmgww (envelope-from ); Mon, 07 Mar 2022 15:07:36 +0000 From: Oscar Salvador To: Andrew Morton Cc: David Hildenbrand , Michal Hocko , Wei Yang , Miaohe Lin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH 3/3] mm/memory_hotplug: Refactor hotadd_init_pgdat and try_online_node Date: Mon, 7 Mar 2022 16:07:25 +0100 Message-Id: <20220307150725.6810-4-osalvador@suse.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307150725.6810-1-osalvador@suse.de> References: <20220307150725.6810-1-osalvador@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.34.1