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 B0A7BC36010 for ; Mon, 7 Apr 2025 10:47:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F36B06B0005; Mon, 7 Apr 2025 06:47:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE23A6B0007; Mon, 7 Apr 2025 06:47:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D81EA280001; Mon, 7 Apr 2025 06:47:29 -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 B5EFB6B0005 for ; Mon, 7 Apr 2025 06:47:29 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8C4A556731 for ; Mon, 7 Apr 2025 10:47:31 +0000 (UTC) X-FDA: 83306921502.19.5DC93A2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 02E42100012 for ; Mon, 7 Apr 2025 10:47:28 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BsmtbRxA; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744022849; a=rsa-sha256; cv=none; b=PVa0uAVC73sq8fJpk8ioczkZ1I6A7EajbQSCRvW8nWmx9xoR77xcHSiA/CzL4ges5gXI2C aQOB16yYhcyd7+g8Vc+XMcxAGMHk/YOlA5dd8ckT8RVpnsau/kyXg9TbzMSkvl6qYxNkg2 +eY5wN7dLxUELOMA+RqxBQe2KlYoxX8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BsmtbRxA; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744022849; 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=p5WvegW14BicmFVOaxVbVa9+TlojjI8sm0GtsJZYUhI=; b=f+RxB0Bm4B8H/jscDSocrevH5/xW5lgdxqgCP+q+NkCnE70W7o7yeaRzKnHGiEoxfgDVeZ aA2HZRh8yj2dcjpSe+zu8JfaogiD3UFVwGFmCkPJHZoo/9n0BAuI3bKFoaOoQrq47hQ+Kz zrxBai41NIus9KuwFzHJLcD3TXsq2sA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744022848; 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:autocrypt:autocrypt; bh=p5WvegW14BicmFVOaxVbVa9+TlojjI8sm0GtsJZYUhI=; b=BsmtbRxAAaW4d9atUHxuQqRfEzULJcXQj5zvORCob42e2NrAJcm7aVj+oePAlh+yRh6jaI CbpBYOZNK4hMxyA0sKiTYHm7wao8E5MypnmtEduFfeC9ibTf3VoJF5UEr9m2iE+t/sk+KG mHrqIOEHFzX/m/8vdeLWcdAiV7BPJmY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-SnZ092-hObepv3VbYDL9og-1; Mon, 07 Apr 2025 06:47:27 -0400 X-MC-Unique: SnZ092-hObepv3VbYDL9og-1 X-Mimecast-MFC-AGG-ID: SnZ092-hObepv3VbYDL9og_1744022846 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-43cf327e9a2so35930225e9.3 for ; Mon, 07 Apr 2025 03:47:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744022846; x=1744627646; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=p5WvegW14BicmFVOaxVbVa9+TlojjI8sm0GtsJZYUhI=; b=ey3fe6GmF4pVs1Syc4EHe49Ps0TXC8Fug8BBrQoShdu4eqAb6h0R6gizwxdDfV9ysG aUAeJyGjsLdOddLb+k11mVM/IiCC2j6TvbO9GY+YOZ9sAho3LN/lYibC6eSKoYDv24Sx gk0LDWi0L63POOs3DPEtpseaBuvnEf9+DwAa5z9LMlO3D0aMfcx8Ybei5bZa4YGdm7U8 /oNMiyNIcOCHmFmKFVAe4/JKjvQQsZnyACv16J2QOqf0U2MxWValqTxW5HLBejWNUt9x x+17JXzfhhd2cKQHdObBUAb3cEUbDUbiQrCUrPsJ1LnrbRbvIQoCbeT7Lzree4bFryru 9yHw== X-Forwarded-Encrypted: i=1; AJvYcCWK4H/fHrtZDc7MUHzUWsD+mhzJDJwjEHWivs54thuzwqSyiY/93PY9qaAYUwstQdDK7cF7EMRvFA==@kvack.org X-Gm-Message-State: AOJu0YwY3ay2oxoj2PlgKjenZuhsymnTt2f1zGVwRSrcvWjHs7hIQhV/ 9jl/OTlRW0yKH/q46zvU1cuwHHcw/xa3L6wEUy2E76Ab+1xUSGstHstrFVqRFRN4pHl7/SGu7Br ZickcbtrIPLjfAMq/HEM8j9dDLIijhc+9KwFRrzLIW4iWOBxR X-Gm-Gg: ASbGncsb5TTrbfWP2VjwFyvbTZshKXlZC6WUfUl8EpsbeA5UwQ0B6rKKTxmYhe53cqd hR0bVkRV2xhSh+nF14FUS4tQA9CMTdrxYRwjKR9xRmmahU068I5HU1nYyQp8AFFJ094Jj5qwyQr 9LRLiX5wqw4cD2M37kXLCb/S62mlE/9+AD/VQD97pwzGkgYXCCPII7wxQ81ML1RFZgr0xbCI1r+ alvW2mkxPcZtY6QJ1ylyAHfj7gJX6tb7nnZuHUGpha9k6KMPpcbyOsBF7nDVYgE1gw8L+Fbwdvq rxq8dhg/2JjWkwjg1t1wfjz7m9mI8/Je22nPnH48Nszg X-Received: by 2002:a5d:648c:0:b0:38d:d0ca:fbad with SMTP id ffacd0b85a97d-39d6fc48d22mr6333070f8f.14.1744022845790; Mon, 07 Apr 2025 03:47:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcZwpMMV74k2xAExUYyBT36I7Zk5hVYn4ciKcjdpgmZy94eGv8XAzLYfRPs6dLjDpDsSW5Ew== X-Received: by 2002:a5d:648c:0:b0:38d:d0ca:fbad with SMTP id ffacd0b85a97d-39d6fc48d22mr6333029f8f.14.1744022845286; Mon, 07 Apr 2025 03:47:25 -0700 (PDT) Received: from [192.168.3.141] (p5b0c6a16.dip0.t-ipconnect.de. [91.12.106.22]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c300968cfsm11847622f8f.16.2025.04.07.03.47.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Apr 2025 03:47:24 -0700 (PDT) Message-ID: Date: Mon, 7 Apr 2025 12:47:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 3/3] mm/mempolicy: Support memory hotplug in weighted interleave To: Rakie Kim Cc: gourry@gourry.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, joshua.hahnjy@gmail.com, dan.j.williams@intel.com, ying.huang@linux.alibaba.com, Jonathan.Cameron@huawei.com, osalvador@suse.de, kernel_team@skhynix.com, honggyu.kim@sk.com, yunjeong.mun@sk.com, akpm@linux-foundation.org References: <20250407093926.450-1-rakie.kim@sk.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT7CwZgEEwEIAEICGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAAhkBFi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Xp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20250407093926.450-1-rakie.kim@sk.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: w7Pyt9V3caYFGsXz0XBQyDFzrEnEZTKZv3bjaKeLQI8_1744022846 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 02E42100012 X-Stat-Signature: nxs4bq79idumfofx3w8xm5uo6ybo6b3d X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1744022848-760068 X-HE-Meta: U2FsdGVkX1/kCAP70h7ov9xNoQHgllio0hU1GhQS+bwhdYjVDqBPXx64PBU7/ZZlNmI4/nz2ZbfiUoHBRCm62wNWEMaWUfLvS0OkDTfypLmFJGk5TOsbCDD/bF5OMGJCmOQ4mL2vzT9lXjyngvE3pS4F7sAj5FencheGeJtLlsFHFWveyIAiMBibXImC+40ONkkxsHfl2ZncCSr5f9JuaN4gSfQ4X/DckpOkYRsYR8Vq74xFbX86KmkxJ6vqCY7OGd3w8mP7IOoYcHx9wfufhftHameYFetJAz+nMD+/lWbOKjdlBEjA/IVTrQ1GjtNv5/xiR5goxGUzcrcstgVGZwyUwGukszjqUhMWJa+ifklRGoKYxLdXDn4IZd4zBjPZqm3PLBpe85JRBXUbtIqUyaWl1yKf86luEN+yr2r70TVApVd9KHMsGmrNkSGRwap/FqGgJ8LhQBZJls5iggztgZYyCOeoQLZb5Q5UwYcH0vRylb4uW5rcqP6eAIST0mYkT8UPLET7TPti4JI40lT16hqtGluqGCJsSgq/OYcFA2U/8lGJt4KJn4rnOyscIh7Qu9Y3TdTxNy4x2MVlVtdYnxKfGhyqPZ9eimhHzSHCJIDR7E1J5SHPCff21BoL4vOSz5rLPhbkZk5BYmpQVPDupxLhSAMRNPlTjNdhMynFpefAi0D9QMMp7fc9QMgUDVW1rcFkcFJJ8B2tR988o+HhRpn0mZvm6QUbsRWYNtoBxefuoPRSG0IwqZiP8+SwRHqwKwmqDFxHnIcuVfE9p3T8UM5OB7s+rdfS5RN49ZIxufCZtU6GiPhosRdUvVLR4Jab8lrBHT3zTZ/yZV1BiowkNDHiUq0d3tzA7VVNkbwE1IsyyrPQhEusSCqQGmaUUMTMJct2tYtyE+YTB7kcwLYeFBobE4BpfZuI4SfJoaObJDY4Efqla45HUPOI67ya0rdZPx9+z2KrKSQgPL31DfH ZJPA461L M7V1GYBpPud9efFCf079OASgjXZ00dFuaeF7ZGAsLvRZmllFY2k2Z5yDyw+GYbEWizBMfenEkrYLiuDtGdU9eWalrzZ/hHLE1eVZvUidVPxS5xbHjmOF/SfLvBnpcYIRzjhq1NhyFvz6VgYKcfZAnQKrahISR67Q0Sul9yHuDy+tTtQeKgK0Cx1QzGy7E2ExFCfAd6TGE6AkoDNOVDQ15cTPH/WcHtmZmZmR7GVd703Q6JVB5d+SZCLJA3W7EVVwMqqTktaXAv8GChBN6Qt9wd+MTQoZ0C5CL2IiNwAX2W9AOviNDloBfEB5dvJasmazcMtgkgpzVon3rPTy/LlXlC7Lx6NBYRPhzcAHce1K0ln1WdqaSaCem5hS7XbuyjbbXzV00kiqbWXzFLzx0GyjMISqv43ZvhJ5cJuf4PPde5nyvLcwKgW8UvoK5aasVEiPt8u690md1mmlzPKWmXPelpCMMJeFwRecdklHKGHbKDhkbYjq00amlfEGiVKno+VSIuoT+/CUJ+/POyzN+4bimD/glZ+dvB3llQxDTZMRsnXjpNNai5Jj9x4hzJ7T496glasxR 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 07.04.25 11:39, Rakie Kim wrote: > On Fri, 4 Apr 2025 22:45:00 +0200 David Hildenbrand wrote: >> On 04.04.25 09:46, Rakie Kim wrote: >>> The weighted interleave policy distributes page allocations across multiple >>> NUMA nodes based on their performance weight, thereby improving memory >>> bandwidth utilization. The weight values for each node are configured >>> through sysfs. >>> >>> Previously, sysfs entries for configuring weighted interleave were created >>> for all possible nodes (N_POSSIBLE) at initialization, including nodes that >>> might not have memory. However, not all nodes in N_POSSIBLE are usable at >>> runtime, as some may remain memoryless or offline. >>> This led to sysfs entries being created for unusable nodes, causing >>> potential misconfiguration issues. >>> >>> To address this issue, this patch modifies the sysfs creation logic to: >>> 1) Limit sysfs entries to nodes that are online and have memory, avoiding >>> the creation of sysfs entries for nodes that cannot be used. >>> 2) Support memory hotplug by dynamically adding and removing sysfs entries >>> based on whether a node transitions into or out of the N_MEMORY state. >>> >>> Additionally, the patch ensures that sysfs attributes are properly managed >>> when nodes go offline, preventing stale or redundant entries from persisting >>> in the system. >>> >>> By making these changes, the weighted interleave policy now manages its >>> sysfs entries more efficiently, ensuring that only relevant nodes are >>> considered for interleaving, and dynamically adapting to memory hotplug >>> events. >>> >>> Signed-off-by: Rakie Kim >>> Signed-off-by: Honggyu Kim >>> Signed-off-by: Yunjeong Mun >>> --- >>> mm/mempolicy.c | 109 ++++++++++++++++++++++++++++++++++++++----------- >>> 1 file changed, 86 insertions(+), 23 deletions(-) >>> >>> diff --git a/mm/mempolicy.c b/mm/mempolicy.c >>> index 73a9405ff352..f25c2c7f8fcf 100644 >>> --- a/mm/mempolicy.c >>> +++ b/mm/mempolicy.c >>> @@ -113,6 +113,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> >>> #include "internal.h" >>> >>> @@ -3390,6 +3391,7 @@ struct iw_node_attr { >>> >>> struct sysfs_wi_group { >>> struct kobject wi_kobj; >>> + struct mutex kobj_lock; >>> struct iw_node_attr *nattrs[]; >>> }; >>> >>> @@ -3439,13 +3441,24 @@ static ssize_t node_store(struct kobject *kobj, struct kobj_attribute *attr, >>> >>> static void sysfs_wi_node_delete(int nid) >>> { >>> - if (!wi_group->nattrs[nid]) >>> + struct iw_node_attr *attr; >>> + >>> + if (nid < 0 || nid >= nr_node_ids) >>> + return; >>> + >>> + mutex_lock(&wi_group->kobj_lock); >>> + attr = wi_group->nattrs[nid]; >>> + if (!attr) { >>> + mutex_unlock(&wi_group->kobj_lock); >>> return; >>> + } >>> + >>> + wi_group->nattrs[nid] = NULL; >>> + mutex_unlock(&wi_group->kobj_lock); >>> >>> - sysfs_remove_file(&wi_group->wi_kobj, >>> - &wi_group->nattrs[nid]->kobj_attr.attr); >>> - kfree(wi_group->nattrs[nid]->kobj_attr.attr.name); >>> - kfree(wi_group->nattrs[nid]); >>> + sysfs_remove_file(&wi_group->wi_kobj, &attr->kobj_attr.attr); >>> + kfree(attr->kobj_attr.attr.name); >>> + kfree(attr); >>> } >>> >>> static void sysfs_wi_release(struct kobject *wi_kobj) >>> @@ -3464,35 +3477,80 @@ static const struct kobj_type wi_ktype = { >>> >>> static int sysfs_wi_node_add(int nid) >>> { >>> - struct iw_node_attr *node_attr; >>> + int ret = 0; >>> char *name; >>> + struct iw_node_attr *new_attr = NULL; >>> >>> - node_attr = kzalloc(sizeof(*node_attr), GFP_KERNEL); >>> - if (!node_attr) >>> + if (nid < 0 || nid >= nr_node_ids) { >>> + pr_err("Invalid node id: %d\n", nid); >>> + return -EINVAL; >>> + } >>> + >>> + new_attr = kzalloc(sizeof(struct iw_node_attr), GFP_KERNEL); >>> + if (!new_attr) >>> return -ENOMEM; >>> >>> name = kasprintf(GFP_KERNEL, "node%d", nid); >>> if (!name) { >>> - kfree(node_attr); >>> + kfree(new_attr); >>> return -ENOMEM; >>> } >>> >>> - sysfs_attr_init(&node_attr->kobj_attr.attr); >>> - node_attr->kobj_attr.attr.name = name; >>> - node_attr->kobj_attr.attr.mode = 0644; >>> - node_attr->kobj_attr.show = node_show; >>> - node_attr->kobj_attr.store = node_store; >>> - node_attr->nid = nid; >>> + mutex_lock(&wi_group->kobj_lock); >>> + if (wi_group->nattrs[nid]) { >>> + mutex_unlock(&wi_group->kobj_lock); >>> + pr_info("Node [%d] already exists\n", nid); >>> + kfree(new_attr); >>> + kfree(name); >>> + return 0; >>> + } >>> + wi_group->nattrs[nid] = new_attr; >>> >>> - if (sysfs_create_file(&wi_group->wi_kobj, &node_attr->kobj_attr.attr)) { >>> - kfree(node_attr->kobj_attr.attr.name); >>> - kfree(node_attr); >>> - pr_err("failed to add attribute to weighted_interleave\n"); >>> - return -ENOMEM; >>> + sysfs_attr_init(&wi_group->nattrs[nid]->kobj_attr.attr); >>> + wi_group->nattrs[nid]->kobj_attr.attr.name = name; >>> + wi_group->nattrs[nid]->kobj_attr.attr.mode = 0644; >>> + wi_group->nattrs[nid]->kobj_attr.show = node_show; >>> + wi_group->nattrs[nid]->kobj_attr.store = node_store; >>> + wi_group->nattrs[nid]->nid = nid; >>> + >>> + ret = sysfs_create_file(&wi_group->wi_kobj, >>> + &wi_group->nattrs[nid]->kobj_attr.attr); >>> + if (ret) { >>> + kfree(wi_group->nattrs[nid]->kobj_attr.attr.name); >>> + kfree(wi_group->nattrs[nid]); >>> + wi_group->nattrs[nid] = NULL; >>> + pr_err("Failed to add attribute to weighted_interleave: %d\n", ret); >>> } >>> + mutex_unlock(&wi_group->kobj_lock); >>> >>> - wi_group->nattrs[nid] = node_attr; >>> - return 0; >>> + return ret; >>> +} >>> + >>> +static int wi_node_notifier(struct notifier_block *nb, >>> + unsigned long action, void *data) >>> +{ >>> + int err; >>> + struct memory_notify *arg = data; >>> + int nid = arg->status_change_nid; >>> + >>> + if (nid < 0) >>> + goto notifier_end; >>> + >>> + switch(action) { >>> + case MEM_ONLINE: >> >> MEM_ONLINE is too late, we cannot fail hotplug at that point. >> >> Would MEM_GOING_ONLINE / MEM_CANCEL_ONLINE be better? > > Hi David, Hi, > > Thank you for raising these points. I would appreciate your clarification > on the following: > > Issue1: I want to invoke sysfs_wi_node_add() after a node with memory > has been fully transitioned to the online state. Does replacing > MEM_ONLINE with MEM_GOING_ONLINE or MEM_CANCEL_ONLINE still ensure > that the node is considered online and usable by that point? After MEM_GOING_ONLINE nothing can go wrong except that some other notifier fails MEM_GOING_ONLINE. That happens rarely -- only if some other allocation, like for kasan, fails. In MEM_CANCEL_ONLINE you have to undo what you did (remove the node again). > >> >> >>> + err = sysfs_wi_node_add(nid); >>> + if (err) { >>> + pr_err("failed to add sysfs [node%d]\n", nid); >>> + return NOTIFY_BAD; >> >> Note that NOTIFY_BAD includes NOTIFY_STOP_MASK. So you wouldn't call >> other notifiers, but the overall memory onlining would succeed, which is >> bad. >> >> If we don't care about the error (not prevent hotplug) we could only >> pr_warn() and continue. Maybe this (unlikely) case is not a good reason >> to stop memory from getting onlined. OTOH, it will barely ever trigger >> in practice ... >> > > Issue2: Regarding your note about NOTIFY_BAD ? are you saying that > if sysfs_wi_node_add() returns NOTIFY_BAD, it will trigger > NOTIFY_STOP_MASK, preventing other notifiers from running, while > still allowing the memory hotplug operation to complete? Yes. > > If so, then I'm thinking of resolving both issues as follows: > - For Issue1: I keep using MEM_ONLINE, assuming it is safe and > sufficient to ensure the node is fully online. > - For Issue2: I avoid returning NOTIFY_BAD from the notifier. > Instead, I log the error using pr_err() and continue the operation. > > This would result in the following code: > > if (nid < 0) > return NOTIFY_OK; > > switch (action) { > case MEM_ONLINE: // Issue1: keeping this unchanged > err = sysfs_wi_node_add(nid); > if (err) { > pr_err("failed to add sysfs [node%d]\n", nid); > // Issue2: Do not return NOTIFY_BAD > } > break; > case MEM_OFFLINE: > sysfs_wi_node_delete(nid); > break; > } > > // Always return NOTIFY_OK > return NOTIFY_OK; > > Please let me know if this approach is acceptable. That would work. The alternative is failing during MEM_GOING_ONLINE if the allocation failed, and deleting the node during MEM_CANCEL_ONLINE. -- Cheers, David / dhildenb