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 C9A8DC7EE30 for ; Tue, 1 Jul 2025 12:19:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D0286B0089; Tue, 1 Jul 2025 08:19:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 658F76B009A; Tue, 1 Jul 2025 08:19:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5486E6B009C; Tue, 1 Jul 2025 08:19:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3D4366B0089 for ; Tue, 1 Jul 2025 08:19:06 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CD0121D7253 for ; Tue, 1 Jul 2025 12:19:05 +0000 (UTC) X-FDA: 83615600250.10.F7EB845 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf21.hostedemail.com (Postfix) with ESMTP id 89FE91C0003 for ; Tue, 1 Jul 2025 12:19:03 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="y/Okyzvc"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="AW/jynFm"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="y/Okyzvc"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="AW/jynFm"; spf=pass (imf21.hostedemail.com: domain of hare@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=hare@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751372343; 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=kPoTXXapW5Br7YXV58xMBwBNvvmONgJuE24PXbOlMaA=; b=Nx448NPZNoaRuRJFr+0IJg/tznrK/UsmJRgt7ZtwBPoZK9JfjIpQS+9GmOHHQDlI3NeSth FzgkxP9mdHGCXDwTsjGxMcK4HmxO2cE9RCPTXwvTN2uwDzy7J2ZfrIwaicaTFqFrHC4F+v WpMtUblPjHuteckkIOx6VEO9A5UKngU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="y/Okyzvc"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="AW/jynFm"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="y/Okyzvc"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="AW/jynFm"; spf=pass (imf21.hostedemail.com: domain of hare@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=hare@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751372343; a=rsa-sha256; cv=none; b=xm9J2g2q1PB2D0ar/knHIF4VTMLXpxQklZEf8LO7gGp9LQf3+Af5MMQZmc0Zj47tBvI7/b UcZcUT/lBdj6NpUyuxXPXDTFi1jH1zcRfbfeSXrvxxPVGNgZ/V2638DsZYO1tPxSp9lIVu 6WgBg64fsGdvjpsPE14VfglA4wcfyQY= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BD9111F393; Tue, 1 Jul 2025 12:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1751372341; h=from:from:reply-to: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=kPoTXXapW5Br7YXV58xMBwBNvvmONgJuE24PXbOlMaA=; b=y/Okyzvc4rAWRWgs797ykXYbcMSrqTyyeNjrrMdX3t3whOjflK/TmMkQSd18v678xXgrNy 88RWt6gu87xrnn+jz6TrMAwmNHs/C2s77Tjrnh3oWXWes06f1ADqzghrHnkTuLCigqV1qs lZIxIJnuQdUqLqY+uZUFKY4LR9RxZTM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1751372341; h=from:from:reply-to: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=kPoTXXapW5Br7YXV58xMBwBNvvmONgJuE24PXbOlMaA=; b=AW/jynFm51f5pdRRrponCn/Z7PYAH3diFa4nzGn9ukz7CLtd3sH4Xeod6tYUl4F+ceBLMn pMJW5HTQtB2GkLAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1751372341; h=from:from:reply-to: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=kPoTXXapW5Br7YXV58xMBwBNvvmONgJuE24PXbOlMaA=; b=y/Okyzvc4rAWRWgs797ykXYbcMSrqTyyeNjrrMdX3t3whOjflK/TmMkQSd18v678xXgrNy 88RWt6gu87xrnn+jz6TrMAwmNHs/C2s77Tjrnh3oWXWes06f1ADqzghrHnkTuLCigqV1qs lZIxIJnuQdUqLqY+uZUFKY4LR9RxZTM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1751372341; h=from:from:reply-to: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=kPoTXXapW5Br7YXV58xMBwBNvvmONgJuE24PXbOlMaA=; b=AW/jynFm51f5pdRRrponCn/Z7PYAH3diFa4nzGn9ukz7CLtd3sH4Xeod6tYUl4F+ceBLMn pMJW5HTQtB2GkLAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8DB981364B; Tue, 1 Jul 2025 12:19:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 1eXeIDXSY2iEZQAAD6G6ig (envelope-from ); Tue, 01 Jul 2025 12:19:01 +0000 Message-ID: <63e71cf0-8bb8-490b-81b5-5bfee38bad32@suse.de> Date: Tue, 1 Jul 2025 14:18:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] mm/memory_hotplug: activate node before adding new memory blocks To: David Hildenbrand , Hannes Reinecke Cc: Oscar Salvador , linux-mm@kvack.org References: <20250701114155.16452-1-hare@kernel.org> <20250701114155.16452-3-hare@kernel.org> <58715af1-2fe1-46a1-a5fe-3ee0e126bf63@redhat.com> Content-Language: en-US From: Hannes Reinecke In-Reply-To: <58715af1-2fe1-46a1-a5fe-3ee0e126bf63@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Action: no action X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id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VmOB/amxFKdRIYN7XehV7M6wx4SwMbAXP8gvnspMZgEo7z2DsNZJdw+Eyh5/otKXv801XiuoAXqIcAh9ZAM6ZbKKwQTrNZ/sAa7pf7/aGru2nfKMpm6Ak/rV6yJnk5nh7RS8/eQC4u4zTMvFQ4zGziLcBcmv1jw94VbTL0m8QTpgbjDW5IHlMLmkSnAZqQWqk5uEg3CXbd/5T189ookALmDPsr+6Ip6OCHAgE4v4JLyvJCqUz9Ie9SwBBGRZpBOv32J/cLmuHT5icQ2b24RWnmkFAYWUaiNSHvmYPxgQaNOTaf9fEzP1A3R+cPkpVAHgatz9rSHY5PjZDbOfFhv6ANJfkMpJtIM9p5PoXEez25NzGQEUy4Jqx9MwDZ06Qa9GNFM96x9GWHfwoGNgTorgCVPArA== 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 7/1/25 14:09, David Hildenbrand wrote: > On 01.07.25 13:41, Hannes Reinecke wrote: >> The sysfs attributes for memory blocks require the node ID to be >> set and initialized, so move the node activation before adding >> new memory blocks. This also has the nice side effect that the >> BUG_ON() can be converted into a WARN_ON() as we now can handle >> registration errors. > > I think this should work. > >> >> Signed-off-by: Hannes Reinecke >> --- >>   drivers/base/memory.c  | 19 +++++++++---------- >>   include/linux/memory.h |  2 +- >>   mm/memory_hotplug.c    | 32 +++++++++++++++++--------------- >>   3 files changed, 27 insertions(+), 26 deletions(-) >> >> diff --git a/drivers/base/memory.c b/drivers/base/memory.c >> index 2b951e5f8a27..d24a90e0ea96 100644 >> --- a/drivers/base/memory.c >> +++ b/drivers/base/memory.c >> @@ -810,15 +810,14 @@ void memory_block_add_nid(struct memory_block >> *mem, int nid, >>               mem->zone = early_node_zone_for_memory_block(mem, nid); >>           else >>               mem->zone = NULL; >> +        /* >> +         * If this memory block spans multiple nodes, we only indicate >> +         * the last processed node. If we span multiple nodes (not >> applicable >> +         * to hotplugged memory), zone == NULL will prohibit memory >> offlining >> +         * and consequently unplug. >> +         */ >> +        mem->nid = nid; >>       } >> - >> -    /* >> -     * If this memory block spans multiple nodes, we only indicate >> -     * the last processed node. If we span multiple nodes (not >> applicable >> -     * to hotplugged memory), zone == NULL will prohibit memory >> offlining >> -     * and consequently unplug. >> -     */ >> -    mem->nid = nid; > > > In stead of that, I suggest we do something like this now, because the > function > no longer makes any sense for hotplugged memory: > > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index 5c6c1d6bb59f1..fb501df920cec 100644 > --- a/drivers/base/memory.c > +++ b/drivers/base/memory.c > @@ -769,21 +769,22 @@ static struct zone > *early_node_zone_for_memory_block(struct memory_block *mem, > >  #ifdef CONFIG_NUMA >  /** > - * memory_block_add_nid() - Indicate that system RAM falling into this > memory > - *                         block device (partially) belongs to the > given node. > + * memory_block_add_nid_early() - Indicate that early system RAM > falling into > + *                               this memory block device (partially) > belongs > + *                               to the given node. >   * @mem: The memory block device. >   * @nid: The node id. > - * @context: The memory initialization context. >   * > - * Indicate that system RAM falling into this memory block (partially) > belongs > - * to the given node. If the context indicates ("early") that we are > adding the > - * node during node device subsystem initialization, this will also > properly > - * set/adjust mem->zone based on the zone ranges of the given node. > + * Indicate that early system RAM falling into this memory block > (partially) > + * belongs to the given node. This will also properly set/adjust mem- > >zone based > + * on the zone ranges of the given node. > + * > + * Memory hotplug handles this on memory block creation, where we can > only have > + * a single nid span a memory block. >   */ > -void memory_block_add_nid(struct memory_block *mem, int nid, > -                         enum meminit_context context) > +void memory_block_add_nid_early(struct memory_block *mem, int nid) >  { > -       if (context == MEMINIT_EARLY && mem->nid != nid) { > +       if (mem->nid != nid) { >                 /* >                  * For early memory we have to determine the zone when > setting >                  * the node id and handle multiple nodes spanning a single > @@ -836,7 +837,7 @@ static int add_memory_block(unsigned long block_id, > unsigned long state, >                 /* >                  * MEM_ONLINE at this point implies early memory. With > NUMA, >                  * we'll determine the zone when setting the node id via > -                * memory_block_add_nid(). Memory hotplug updated the zone > +                * memory_block_add_nid_early(). Memory hotplug updated > the zone >                  * manually when memory onlining/offlining succeeds. >                  */ >                 mem->zone = early_node_zone_for_memory_block(mem, > NUMA_NO_NODE); > diff --git a/drivers/base/node.c b/drivers/base/node.c > index bef84f01712f3..6cfda015fdea6 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -786,7 +786,8 @@ static void do_register_memory_block_under_node(int > nid, >  { >         int ret; > > -       memory_block_add_nid(mem_blk, nid, context); > +       if (context == MEMINIT_EARLY) > +               memory_block_add_nid_early(mem_blk, nid); > >         ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj, >                                        &mem_blk->dev.kobj, > diff --git a/include/linux/memory.h b/include/linux/memory.h > index 40eb70ccb09d5..bc805205ed258 100644 > --- a/include/linux/memory.h > +++ b/include/linux/memory.h > @@ -202,8 +202,7 @@ static inline unsigned long > phys_to_block_id(unsigned long phys) >  } > >  #ifdef CONFIG_NUMA > -void memory_block_add_nid(struct memory_block *mem, int nid, > -                         enum meminit_context context); > +void memory_block_add_nid_early(struct memory_block *mem, int nid); >  #endif /* CONFIG_NUMA */ >  int memory_block_advise_max_size(unsigned long size); >  unsigned long memory_block_advised_max_size(void); > > Sure. I'll add it as a separate patch. Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich