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 29D70C19F21 for ; Wed, 27 Jul 2022 04:38:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6812900002; Wed, 27 Jul 2022 00:38:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A16318E0001; Wed, 27 Jul 2022 00:38:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88F7A900002; Wed, 27 Jul 2022 00:38:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7AC168E0001 for ; Wed, 27 Jul 2022 00:38:55 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5B223C139E for ; Wed, 27 Jul 2022 04:38:55 +0000 (UTC) X-FDA: 79731624630.29.DC7984A Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf18.hostedemail.com (Postfix) with ESMTP id CFA891C0014 for ; Wed, 27 Jul 2022 04:38:54 +0000 (UTC) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26R4Tcgd011016; Wed, 27 Jul 2022 04:38:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : content-type : mime-version; s=pp1; bh=7PkLLJfsngw7ZWteV9ZG6v5tDLrSl0UkFzTL7lb4Ess=; b=I6tnB+HigJUoLDUqbK/2M4zkykfMg7q26W69fXlwIcuPLDFF8rxapmOPsMoHgzWaUrcD Ae/z63LsSYUyb6BvB+uWVm+J2jvxNeBzhC/QkfPrCECDlgQGMKlp6jMj7wNi7AIXnrvG bIroX6FJ+KS6YivCQxs5BZnRu0JlhCKNwEc8+18sg9wNy1wzcqFT1gWCFMfwhvCX8G4h x8fHcyItGpuBQDvoPCrmXJeXkk1TeBOqlib+L2t3wspPUTHc3m6MDpqG8yi/3OumN5+U rLF2NynO2bFBzIGDXnJNye4S8pfCh/3lFn14xWiDsxPEG49FCcqjpMF5GVz/MS472qgX Zw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hjxcur6mk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 04:38:28 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26R4Tta9011434; Wed, 27 Jul 2022 04:38:27 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hjxcur6ky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 04:38:27 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26R4K1Cp007967; Wed, 27 Jul 2022 04:38:26 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma02wdc.us.ibm.com with ESMTP id 3hg97uexyb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Jul 2022 04:38:26 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26R4cPog1114744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Jul 2022 04:38:25 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7570BAE060; Wed, 27 Jul 2022 04:38:25 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5198AE05C; Wed, 27 Jul 2022 04:38:19 +0000 (GMT) Received: from skywalker.linux.ibm.com (unknown [9.43.5.110]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 27 Jul 2022 04:38:19 +0000 (GMT) X-Mailer: emacs 29.0.50 (via feedmail 11-beta-1 I) From: "Aneesh Kumar K.V" To: "Huang, Ying" , Alistair Popple Cc: linux-mm@kvack.org, akpm@linux-foundation.org, Wei Xu , Yang Shi , Davidlohr Bueso , Tim C Chen , Michal Hocko , Linux Kernel Mailing List , Hesham Almatary , Dave Hansen , Jonathan Cameron , Dan Williams , Johannes Weiner , jvgediya.oss@gmail.com Subject: Re: [PATCH v10 3/8] mm/demotion: Add hotplug callbacks to handle new numa node onlined In-Reply-To: <87czdruxs0.fsf@yhuang6-desk2.ccr.corp.intel.com> References: <20220720025920.1373558-1-aneesh.kumar@linux.ibm.com> <20220720025920.1373558-4-aneesh.kumar@linux.ibm.com> <87fsiowmdt.fsf@yhuang6-desk2.ccr.corp.intel.com> <28582201-b438-9ac9-ca6b-1ee6e5794dd2@linux.ibm.com> <87czdruxs0.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Wed, 27 Jul 2022 10:08:16 +0530 Message-ID: <87h733rwzr.fsf@linux.ibm.com> Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-GUID: JOe4k0Eh7PPXbOycLuQEO_5le5QXvcEl X-Proofpoint-ORIG-GUID: b0nmiTWrokmfvatE3ypJMmp47dUIXCve X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_07,2022-07-26_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 adultscore=0 clxscore=1015 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207270014 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658896735; a=rsa-sha256; cv=none; b=0Mh5kw2oQmiU2zQw9crcigis0ybTEzXvjWZOF4NdcfzSySknYBEJqKSaEJys32U8QD8jAR RPUd0Sa8Zo4NUStFsoTgFMN8v8pWvAmZYk56DjPkS4y9S2rFdAF4ObFalv0dTIOmTiGX3/ RvJRaxv2x8bPCuf423hr9ftbaF6iOnw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=I6tnB+Hi; spf=pass (imf18.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658896735; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7PkLLJfsngw7ZWteV9ZG6v5tDLrSl0UkFzTL7lb4Ess=; b=UpTIZ/ddXEtDHGT3rQLC0r7oSbbe5cuovlbLPexfLJfGJVBDWwYmxFCgvwYmHHFIWqG92F Hu3eM/sBW2vLgA2aBe4LqdTgDpxb39NtFbTfrfWBh7rcF2oTJbf56WhOEhxQHPkIYqK8wL xvyuN8ntRN8BKmPRpThm3Xk1w7KMCmc= Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=I6tnB+Hi; spf=pass (imf18.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CFA891C0014 X-Stat-Signature: dxjzs3z8ewt5irnyqe7td4asjt8i7yik X-HE-Tag: 1658896734-687691 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: "Huang, Ying" writes: > Aneesh Kumar K V writes: > >> On 7/26/22 9:33 AM, Huang, Ying wrote: >>> "Aneesh Kumar K.V" writes: >>> >>>> If the new NUMA node onlined doesn't have a performance level assigned, >>>> the kernel adds the NUMA node to default memory tier. >>>> >>>> Signed-off-by: Aneesh Kumar K.V >>>> --- >>>> include/linux/memory-tiers.h | 1 + >>>> mm/memory-tiers.c | 75 ++++++++++++++++++++++++++++++++++++ >>>> 2 files changed, 76 insertions(+) >>>> >>>> diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h >>>> index ef380a39db3a..3d5f14d57ae6 100644 >>>> --- a/include/linux/memory-tiers.h >>>> +++ b/include/linux/memory-tiers.h >>>> @@ -14,6 +14,7 @@ >>>> #define MEMTIER_PERF_LEVEL_DRAM (1 << (MEMTIER_CHUNK_BITS + 2)) >>>> /* leave one tier below this slow pmem */ >>>> #define MEMTIER_PERF_LEVEL_PMEM (1 << MEMTIER_CHUNK_BITS) >>>> +#define MEMTIER_HOTPLUG_PRIO 100 >>>> >>>> extern bool numa_demotion_enabled; >>>> >>>> diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c >>>> index 41a21cc5ae55..cc3a47ec18e4 100644 >>>> --- a/mm/memory-tiers.c >>>> +++ b/mm/memory-tiers.c >>>> @@ -5,6 +5,7 @@ >>>> #include >>>> #include >>>> #include >>>> +#include >>>> #include >>>> >>>> struct memory_tier { >>>> @@ -64,6 +65,78 @@ static struct memory_tier *find_create_memory_tier(unsigned int perf_level) >>>> return new_memtier; >>>> } >>>> >>>> +static struct memory_tier *__node_get_memory_tier(int node) >>>> +{ >>>> + struct memory_tier *memtier; >>>> + >>>> + list_for_each_entry(memtier, &memory_tiers, list) { >>>> + if (node_isset(node, memtier->nodelist)) >>>> + return memtier; >>>> + } >>>> + return NULL; >>>> +} >>>> + >>>> +static void init_node_memory_tier(int node) >>> >>> set_node_memory_tier()? >> >> That was done based on feedback from Alistair >> >> https://lore.kernel.org/linux-mm/87h73iapg1.fsf@nvdebian.thelocal >> >>> >>>> +{ >>>> + int perf_level; >>>> + struct memory_tier *memtier; >>>> + >>>> + mutex_lock(&memory_tier_lock); >>>> + >>>> + memtier = __node_get_memory_tier(node); >>>> + if (!memtier) { >>>> + perf_level = node_devices[node]->perf_level; >>>> + memtier = find_create_memory_tier(perf_level); >>>> + node_set(node, memtier->nodelist); >>>> + } > > It's related to Alistair's comments too. When will memtier != NULL > here? We may need just VM_WARN_ON() here? When the platform driver sets memory tier directly. With the old code it can happen when dax/kmem register a node to a memory tier. With memory_type proposal this can happen if the node is part of memory type that is already added to a memory tier. > >>>> + mutex_unlock(&memory_tier_lock); >>>> +} >>>> + >>>> +static void clear_node_memory_tier(int node) >>>> +{ >>>> + struct memory_tier *memtier; >>>> + >>>> + mutex_lock(&memory_tier_lock); >>>> + memtier = __node_get_memory_tier(node); >>>> + if (memtier) >>>> + node_clear(node, memtier->nodelist); >>> >>> When memtier->nodelist becomes empty, we need to free memtier? >>> >>>> + mutex_unlock(&memory_tier_lock); >>>> +} >>>> + >>>> +/* >>>> + * This runs whether reclaim-based migration is enabled or not, >>>> + * which ensures that the user can turn reclaim-based migration >>>> + * at any time without needing to recalculate migration targets. >>>> + */ >>> >>> The comments doesn't apply here. >>> >>>> +static int __meminit migrate_on_reclaim_callback(struct notifier_block *self, >>>> + unsigned long action, void *_arg) >>> >>> Now we are building memory tiers instead of working on demotion. So I >>> think we should rename the function to memtier_hotplug_callback(). >>> >>>> +{ >>>> + struct memory_notify *arg = _arg; >>>> + >>>> + /* >>>> + * Only update the node migration order when a node is >>>> + * changing status, like online->offline. >>>> + */ >>>> + if (arg->status_change_nid < 0) >>>> + return notifier_from_errno(0); >>>> + >>>> + switch (action) { >>>> + case MEM_OFFLINE: >>>> + clear_node_memory_tier(arg->status_change_nid); >>>> + break; >>>> + case MEM_ONLINE: >>>> + init_node_memory_tier(arg->status_change_nid); >>>> + break; >>>> + } >>>> + >>>> + return notifier_from_errno(0); >>>> +} >>>> + >>>> +static void __init migrate_on_reclaim_init(void) >>>> +{ >>>> + hotplug_memory_notifier(migrate_on_reclaim_callback, MEMTIER_HOTPLUG_PRIO); >>>> +} >>> >>> I suggest to call hotplug_memory_notifier() in memory_tier_init() >>> directly. We are not working on demotion here. >>> >>>> + >>>> static int __init memory_tier_init(void) >>>> { >>>> int node; >>>> @@ -96,6 +169,8 @@ static int __init memory_tier_init(void) >>>> node_property->perf_level = default_memtier_perf_level; >>>> } >>>> mutex_unlock(&memory_tier_lock); >>>> + >>>> + migrate_on_reclaim_init(); >>>> return 0; >>>> } >>>> subsys_initcall(memory_tier_init); >>> >>> Best Regards, >>> Huang, Ying >> >> >> Will update the patch in next iteration to take care of other feedback. > > Thanks! > > Best Regards, > Huang, Ying