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 A8BD6C28B2F for ; Fri, 14 Mar 2025 06:01:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F1B7280002; Fri, 14 Mar 2025 02:01:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89E82280001; Fri, 14 Mar 2025 02:01:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7668C280002; Fri, 14 Mar 2025 02:01:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 567E2280001 for ; Fri, 14 Mar 2025 02:01:03 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 44F551C9139 for ; Fri, 14 Mar 2025 06:01:04 +0000 (UTC) X-FDA: 83219108448.25.2C15206 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf16.hostedemail.com (Postfix) with ESMTP id 95510180011 for ; Fri, 14 Mar 2025 06:01:01 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of rakie.kim@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=rakie.kim@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741932062; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/ghw0YYfjyOMRaJTjhk+EBQDRC9YLchW0Rz59FRdG2A=; b=70G7I4Uu+LwGQ3CxCDry6eO+4b+02ZMvY10gffJsjS5/HCVdrzRdo6euZgOoZZQ7CIs+DR HND9YFroZrOmZ3zcBsK4HE76VlYgppiMhOa+1IQL0JLxWtUIjRrF4ehzPi5IQvNUhwcssp aL2CZxbFUQ/rIJlDIBzekw54g0ZhlDg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741932062; a=rsa-sha256; cv=none; b=w/N46NJkOPD5dTVMn/bzNl3P8IoZKioMuvdW4TGh/0cjDzVWeh10c16qZcHlEmWWEg22XW ADbkApMUzejlImf8W9cZybpt737hi+Xjy9LExzBjXipKFr+OoOxEWMUC2xbFcrAB6FXIr6 MoITTqftV0v4hsiz/62wxPJY2ZkUHLg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf16.hostedemail.com: domain of rakie.kim@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=rakie.kim@sk.com X-AuditID: a67dfc5b-669ff7000002311f-0a-67d3c61a2f75 From: Rakie Kim To: David Hildenbrand Cc: akpm@linux-foundation.org, 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, kernel_team@skhynix.com, honggyu.kim@sk.com, yunjeong.mun@sk.com, Gregory Price , Rakie Kim Subject: Re: [PATCH v2 2/4] mm/mempolicy: Support memory hotplug in weighted interleave Date: Fri, 14 Mar 2025 15:00:45 +0900 Message-ID: <20250314060053.743-1-rakie.kim@sk.com> X-Mailer: git-send-email 2.48.1.windows.1 In-Reply-To: <713b6924-a653-453e-8fde-8c966638386b@redhat.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRmVeSWpSXmKPExsXC9ZZnka70scvpBleXs1jMWb+GzWL61AuM Fl/X/2K2+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fa9 vMEKMVFTouHSPSYQm1PATuL/hj3MILaQAI/Eqw37GSHqBSVOznzCAmIzC8hLNG+dzTyBkWcW ktQsJKkFjEyrGEUy88pyEzNzTPWKszMq8zIr9JLzczcxAoN5We2fiTsYv1x2P8QowMGoxMO7 YdeldCHWxLLiytxDjBIczEoivKttL6QL8aYkVlalFuXHF5XmpBYfYpTmYFES5/UKT00QEkhP LEnNTk0tSC2CyTJxcEo1MGYn1V3fpTD5BHdYVpvJvWddWzr6n/FbRQv+077GZlka2ecqzti3 /9F2w5TbU6tXT92U+Lj5xusp3+dFrW+Vedz+7EieSO6M22ccct9OPaO5TXnBTL5VfBv7JzT3 5q+efFM4vnbXDtOfa2/s7Dh/cJ4Oe9QFmQQnx+/VOwojqqO9GU5NM1yyrVKJpTgj0VCLuag4 EQCQXnLiYgIAAA== X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 95510180011 X-Stat-Signature: wyaehfawrcbgfmotwmufwf3xryt6ef1n X-HE-Tag: 1741932061-918337 X-HE-Meta: U2FsdGVkX19ymEsBKvGypERR1PSJdLAQdEfhRKitw3FCxY1T7u8GOWTAzfubQK80imSdEfWobS9BsQW1+RF+aOlQMn+sH/2STt8xSxTOEYYi0SXihoQPC9eDoMQBBgpTCiyCVzvyKPBoO1uE9IIoIo7RMnVTmH8eGYL+M2AyccxtV0WNGmJJL15cWMJoKNjAqqDSOaAfLU4frY5xIhwJWM8Btd2woXIxhJdZM/OxgefTemyrlzDyzE9V9EAGsyrqfOnagyzJfugdDhDYKLVIeClTRiHs+2nhEM04wNBmQM1g/87dz3mtCfOOVFFJZkbJymlhE9HBEW7X/jzYvxYvs7lrvnRCV329mWmsB+rT4/UZ7MMnDVeFtzCH9Nt6z5geoYMPrWtvw7iCnqp8zq9J3U6FfpBPGdEmbA8TZX6qdAs7tz1PyiAdxEAy6t2eXoHmZUYoC0zSGt240RAYI9XuI/+q7LfqZ4rkHz5Xjr7u2ufjVS0Q1rC8pcpajoOVjMQEFbLoMGS5iAv+h+2vCi/EBU7W2y2aPXTSBV6TGx1BPnco4MY7sUptUxtPc+RmO2YgccuyVbuJrU8YSqzVN0K4NHl6EvMUfXC4aP9rmRVGB/hC1cL8wVCEw78qaTHuIfw9uVafgJpIBB/PWGzJyionQZZDtE6JYPJDN402fIlcR9oV942jdk2y7SRB81e/c8//50rIvqNnzZM02rdj0d0arJqQWUXibwAw9fNhk8X8OBB5CSYMTOMchl0gKjTslC9tHbceREJ36vpPrWMioFb3XrVIePKNcMP/3boWBc56RmZPwunA7BpZT8knVX/3s/icgLNwMJfSKoZV3c6xXeh9NMDacDPQ/2pJVwk/p16s/S2DNrKm37bqiM9MYn7OwiQR+UkAiTVgN4nHxrM14iFOL6TpjCXz6jmabkv+CfkxPUWhYc52rqS/rA85T+D2P3JiUCiT31+SPVs+ELenjBu jb+Y0qhB QwKEN1qmbh5PGjxJnAdk717Kqpd2pDVIdwxyeIHdr7dTB4dOIORu64c0+MaynHYloVj+R 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 Thu, 13 Mar 2025 23:36:47 +0100 David Hildenbrand wrote: > On 13.03.25 17:23, Gregory Price wrote: > > On Thu, Mar 13, 2025 at 03:33:37PM +0900, Rakie Kim wrote: > >>> I'm fairly certain this logic is wrong. If I add two memory blocks and > >>> then remove one, would this logic not remove the sysfs entries despite > >>> there being a block remaining? > >> > >> Regarding the assumption about node configuration: > >> Are you assuming that a node has two memory blocks and that > >> MEM_OFFLINE is triggered when one of them is offlined? If so, then > >> you are correct that this logic would need modification. > >> > >> I performed a simple test by offlining a single memory block: > >> # echo 0 > /sys/devices/system/node/node2/memory100/online > >> > >> In this case, MEM_OFFLINE was not triggered. However, I need to > >> conduct further analysis to confirm this behavior under different > >> conditions. I will review this in more detail and share my > >> findings, including the test methodology and results. > >> > > > > +David - might have a quick answer to this. I would have expected a > > single memory block going offline to cause a notification. > > Yes. Unless offlining failed, or the block was already offline :) > > If it doesn't happen for an actual online memory block that is offline > after the call, we would have a bug. > > > -- > Cheers, > > David / dhildenb > Hi David, I am currently working on adding memory hotplug-related functionality to the weighted interleave feature. While discussing this with Gregory, a question came up. If you happen to know the answer to the following, I would greatly appreciate your input. I have added the following logic to call add_weight_node when a node transitions to the N_MEMORY state to create a sysfs entry. Conversely, when all memory blocks of a node go offline (!N_MEMORY), I call sysfs_wi_node_release to remove the corresponding sysfs entry. +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: + err = add_weight_node(nid, wi_kobj); + if (err) { + pr_err("failed to add sysfs [node%d]\n", nid); + kobject_put(wi_kobj); + return NOTIFY_BAD; + } + break; + case MEM_OFFLINE: + sysfs_wi_node_release(node_attrs[nid], wi_kobj); + break; + } + +notifier_end: + return NOTIFY_OK; +} One question I have is whether the MEM_OFFLINE action in the code below will be triggered when a node that consists of multiple memory blocks has only one of its memory blocks transitioning to the offline state. + int nid = arg->status_change_nid; + + if (nid < 0) + goto notifier_end; Based on my analysis, wi_node_notifier should function as expected because arg->status_change_nid only holds a non-negative value under the following conditions: 1) !N_MEMORY -> N_MEMORY When the first memory block of a node transitions to the online state, it holds a non-negative value. In all other cases, it remains -1 (NUMA_NO_NODE). 2) N_MEMORY -> !N_MEMORY When all memory blocks of a node transition to the offline state, it holds a non-negative value. In all other cases, it remains -1 (NUMA_NO_NODE). I would truly appreciate it if you could confirm whether this analysis is correct. Below is a more detailed explanation of my findings. - The callback function registered in hotplug_memory_notifier receives the MEM_ONLINE action in online_pages. int online_pages(unsigned long pfn, unsigned long nr_pages, struct zone *zone, struct memory_group *group) { struct memory_notify arg; ... node_states_check_changes_online(nr_pages, zone, &arg); ret = memory_notify(MEM_GOING_ONLINE, &arg); ... node_states_set_node(nid, &arg); ... memory_notify(MEM_ONLINE, &arg); } - If the node is in the !N_MEMORY state, arg->status_change_nid is set to the node ID. static void node_states_check_changes_online(unsigned long nr_pages, struct zone *zone, struct memory_notify *arg) { int nid = zone_to_nid(zone); arg->status_change_nid = NUMA_NO_NODE; arg->status_change_nid_normal = NUMA_NO_NODE; if (!node_state(nid, N_MEMORY)) arg->status_change_nid = nid; ... } - If arg->status_change_nid >= 0, the node transitions to the N_MEMORY state. static void node_states_set_node(int node, struct memory_notify *arg) { ... if (arg->status_change_nid >= 0) node_set_state(node, N_MEMORY); } - The callback function registered in hotplug_memory_notifier receives the MEM_OFFLINE action in offline_pages. int offline_pages(unsigned long start_pfn, unsigned long nr_pages, struct zone *zone, struct memory_group *group) { struct memory_notify arg; ... node_states_check_changes_offline(nr_pages, zone, &arg); ret = memory_notify(MEM_GOING_OFFLINE, &arg); ... node_states_clear_node(node, &arg); ... memory_notify(MEM_OFFLINE, &arg); } - If the node becomes empty, arg->status_change_nid is set to the node ID. static void node_states_check_changes_offline(unsigned long nr_pages, struct zone *zone, struct memory_notify *arg) { ... /* * We have accounted the pages from [0..ZONE_NORMAL); ZONE_HIGHMEM * does not apply as we don't support 32bit. * Here we count the possible pages from ZONE_MOVABLE. * If after having accounted all the pages, we see that the nr_pages * to be offlined is over or equal to the accounted pages, * we know that the node will become empty, and so, we can clear * it for N_MEMORY as well. */ present_pages += pgdat->node_zones[ZONE_MOVABLE].present_pages; if (nr_pages >= present_pages) arg->status_change_nid = zone_to_nid(zone); } - If arg->status_change_nid >= 0, the node transitions to the !N_MEMORY state. static void node_states_clear_node(int node, struct memory_notify *arg) { ... if (arg->status_change_nid >= 0) node_clear_state(node, N_MEMORY); } Thank you very much for taking the time to read this lengthy email. Rakie