Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4424272pxb; Mon, 21 Feb 2022 21:10:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRGXeARGrgVDQV9Z6UrbIaL5EFEsPTIruOkKfsCFbtJYTwRDJcJnh/Vg1NMUSNkrHr/bUU X-Received: by 2002:a17:902:dacf:b0:14d:682a:160c with SMTP id q15-20020a170902dacf00b0014d682a160cmr21545175plx.145.1645506656168; Mon, 21 Feb 2022 21:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645506656; cv=none; d=google.com; s=arc-20160816; b=Euf5xpoddMjT7YD19+pC9ZIr/2AZKap6nRTeWaE59Rw1Hmog7OvQs0FzHgNIrSpBWI I3WCqt4yPAcXpu6BA6S/lzC2aURh/n7LvCEEFuqadeO1j4K8TCwH22XTpAUWkr33XL1T 0uWFPzqItS8VAO/IPtHPxx3X0G2JQGVK+aONjwkyjDwAoaVy67KkK4sdVLCe0KB6AD7b vmAgNapXASCLVrdR79CZxXn22IEXQgc+6Tiz4dghUn9nm0aCqSNpULpg6edtVb4nYTDP jtEVl8y4aHKOzS3oPnD3RWhRDlxncen3kump6cuLEKSqftocCsbK91MYKHL4dzySz/xi Tv3Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=5p6SVD+iSqqkjQ95jNA8dJL55xZ3wL1UzWwbq1ZkZlU=; b=v5TcoTaHsu+EU23zWCcDZGDj7CX8UZYiT+zutT8zotfn0Cq7gQAc8rt0+DrGYIb8os qSy1nvPXDRq3se+Q8IHyCjMtMkrZr0xoAjFvZqW+fGRAQru2W7RX6risu02039a2J6e5 I7ye4b+Cse3E+SbrECcDzX0Pz7BxIQp+IHoSwVhddMBSekxypgNPJ9DSFOJsLFp9lhdP aZ3cqKmcbkYi/lzxsBOIDGVSQQKHmGXovN0uiSUz/R4UAD9Z75qMmoQHWWtsOxeh8W1J 5X9jUE/HBEBprm/a0PJ4b0XYk+6e63aRi4jF/ayYRaTubjYUXLSl/tTNTpvnQZkIfWL+ 5T1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ieUeonr/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u11si3205371pls.259.2022.02.21.21.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:10:56 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ieUeonr/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 03D64CCC46; Mon, 21 Feb 2022 20:43:45 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379455AbiBUPqY (ORCPT + 99 others); Mon, 21 Feb 2022 10:46:24 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379586AbiBUPqD (ORCPT ); Mon, 21 Feb 2022 10:46:03 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 226BF22B0E for ; Mon, 21 Feb 2022 07:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645458339; 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; bh=5p6SVD+iSqqkjQ95jNA8dJL55xZ3wL1UzWwbq1ZkZlU=; b=ieUeonr/JUc9Dk2nItDbDnSTLjH21qFTFpZqVFMh5TU0s2OaOb5acHgCbp/VY2nozp9Pk5 MBK8IQapYIZOe6wONP9dmCKzL9W53NB6dfuN77HzgP5CSvptirSwhgVDS5v6YfySm+WpJ+ 6gtvf480Q0piCyU15SV8PBqq4PIUsQo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-422-5YxYP_JDPTOfWzl8jPuItQ-1; Mon, 21 Feb 2022 10:45:36 -0500 X-MC-Unique: 5YxYP_JDPTOfWzl8jPuItQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BE49801B0C; Mon, 21 Feb 2022 15:45:34 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.195.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A92A2BE74; Mon, 21 Feb 2022 15:45:32 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , "Rafael J. Wysocki" , Greg Kroah-Hartman , Michal Hocko , Oscar Salvador Subject: [PATCH v1] drivers/base/memory: clarify adding and removing of memory blocks Date: Mon, 21 Feb 2022 16:45:31 +0100 Message-Id: <20220221154531.11382-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 Let's make it clearer at which places we actually add and remove memory blocks -- streamlining the terminology -- and highlight which memory block start out online and which start out as offline. * rename add_memory_block -> add_boot_memory_block * rename init_memory_block -> add_memory_block * rename unregister_memory -> remove_memory_block * rename register_memory -> __add_memory_block * add add_hotplug_memory_block * mark add_boot_memory_block with __init (suggested by Oscar) __add_memory_block() is a pure helper for add_memory_block(), remove the somewhat obvious comment. Cc: Andrew Morton Cc: "Rafael J. Wysocki" Cc: Greg Kroah-Hartman Cc: Michal Hocko Cc: Oscar Salvador Signed-off-by: David Hildenbrand --- Based on v5.17-rc5 and: [PATCH v2 0/2] drivers/base/memory: determine and store zone for single-zone memory blocks [1] [1] https://lkml.kernel.org/r/20220210184359.235565-1-david@redhat.com --- drivers/base/memory.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 5297c8a84428..c7dfd86e960f 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -617,11 +617,7 @@ static const struct attribute_group *memory_memblk_attr_groups[] = { NULL, }; -/* - * register_memory - Setup a sysfs device for a memory block - */ -static -int register_memory(struct memory_block *memory) +static int __add_memory_block(struct memory_block *memory) { int ret; @@ -721,9 +717,9 @@ void memory_block_add_nid(struct memory_block *mem, int nid, } #endif -static int init_memory_block(unsigned long block_id, unsigned long state, - unsigned long nr_vmemmap_pages, - struct memory_group *group) +static int add_memory_block(unsigned long block_id, unsigned long state, + unsigned long nr_vmemmap_pages, + struct memory_group *group) { struct memory_block *mem; int ret = 0; @@ -754,7 +750,7 @@ static int init_memory_block(unsigned long block_id, unsigned long state, mem->zone = early_node_zone_for_memory_block(mem, NUMA_NO_NODE); #endif /* CONFIG_NUMA */ - ret = register_memory(mem); + ret = __add_memory_block(mem); if (ret) return ret; @@ -766,7 +762,7 @@ static int init_memory_block(unsigned long block_id, unsigned long state, return 0; } -static int add_memory_block(unsigned long base_section_nr) +static int __init add_boot_memory_block(unsigned long base_section_nr) { int section_count = 0; unsigned long nr; @@ -778,11 +774,18 @@ static int add_memory_block(unsigned long base_section_nr) if (section_count == 0) return 0; - return init_memory_block(memory_block_id(base_section_nr), - MEM_ONLINE, 0, NULL); + return add_memory_block(memory_block_id(base_section_nr), + MEM_ONLINE, 0, NULL); +} + +static int add_hotplug_memory_block(unsigned long block_id, + unsigned long nr_vmemmap_pages, + struct memory_group *group) +{ + return add_memory_block(block_id, MEM_OFFLINE, nr_vmemmap_pages, group); } -static void unregister_memory(struct memory_block *memory) +static void remove_memory_block(struct memory_block *memory) { if (WARN_ON_ONCE(memory->dev.bus != &memory_subsys)) return; @@ -821,8 +824,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size, return -EINVAL; for (block_id = start_block_id; block_id != end_block_id; block_id++) { - ret = init_memory_block(block_id, MEM_OFFLINE, vmemmap_pages, - group); + ret = add_hotplug_memory_block(block_id, vmemmap_pages, group); if (ret) break; } @@ -833,7 +835,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size, mem = find_memory_block_by_id(block_id); if (WARN_ON_ONCE(!mem)) continue; - unregister_memory(mem); + remove_memory_block(mem); } } return ret; @@ -862,7 +864,7 @@ void remove_memory_block_devices(unsigned long start, unsigned long size) if (WARN_ON_ONCE(!mem)) continue; unregister_memory_block_under_nodes(mem); - unregister_memory(mem); + remove_memory_block(mem); } } @@ -922,7 +924,7 @@ void __init memory_dev_init(void) */ for (nr = 0; nr <= __highest_present_section_nr; nr += sections_per_block) { - ret = add_memory_block(nr); + ret = add_boot_memory_block(nr); if (ret) panic("%s() failed to add memory block: %d\n", __func__, ret); -- 2.35.1