From patchwork Wed Jun 22 08:25:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 12890315 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 94826C43334 for ; Wed, 22 Jun 2022 08:46:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D3B58E009A; Wed, 22 Jun 2022 04:46:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 284018E008A; Wed, 22 Jun 2022 04:46:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 124538E009A; Wed, 22 Jun 2022 04:46:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 021F18E008A for ; Wed, 22 Jun 2022 04:46:17 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C0105347DA for ; Wed, 22 Jun 2022 08:46:16 +0000 (UTC) X-FDA: 79605239952.17.CE7D752 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf25.hostedemail.com (Postfix) with ESMTP id 54715A0093 for ; Wed, 22 Jun 2022 08:46:09 +0000 (UTC) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25M8AV1d000657; Wed, 22 Jun 2022 08:25:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=VynPHaB44iwLNm1NI/jimLhyT7ZD9Z8XYUiK5QEqD2Y=; b=eAbhHZJYQhz7YtUctC/KVm8r/kqOaDR5eA8qAmHG9yHO5SUH2N7TZMZOHgOeCKb3hQb2 Wp8iJzVaOKJ+cotVHsbiVyYFaXZ9b9aHxKUiZ6iTxJC8Gz0QxnvAy1EcW6E4IXUXGlQH vEU/cWd7VslxFdftUOpr9fpUAxtQd8b/ZlfLaHeOo5iSKSZLtNi5ULv/EHSpX5bR/bbe Ufod7mhZZTHWqKBSy1VdkNsSgHW01rfezSfQgdhuoIaCbRNQr6HzZqk3zejX737MS3ss VuQ9T3shmhjLrfotfsarfbS6jbpfjqxsrEumHT6iGm6uqSvGCob+38sfXtXaraHaGvCL aA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3guxxeru62-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Jun 2022 08:25:59 +0000 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25M8ORcm002989; Wed, 22 Jun 2022 08:25:59 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3guxxeru5h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Jun 2022 08:25:59 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25M8LcEi002840; Wed, 22 Jun 2022 08:25:58 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma03dal.us.ibm.com with ESMTP id 3gs6b9rqxx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Jun 2022 08:25:57 +0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25M8PuAg8520130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 22 Jun 2022 08:25:56 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A33216E059; Wed, 22 Jun 2022 08:25:56 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2DE156E053; Wed, 22 Jun 2022 08:25:51 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.69.226]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 22 Jun 2022 08:25:50 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Wei Xu , Huang Ying , Yang Shi , Davidlohr Bueso , Tim C Chen , Michal Hocko , Linux Kernel Mailing List , Hesham Almatary , Dave Hansen , Jonathan Cameron , Alistair Popple , Dan Williams , "Aneesh Kumar K.V" Subject: [PATCH v7 04/12] mm/demotion: Add hotplug callbacks to handle new numa node onlined Date: Wed, 22 Jun 2022 13:55:05 +0530 Message-Id: <20220622082513.467538-5-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220622082513.467538-1-aneesh.kumar@linux.ibm.com> References: <20220622082513.467538-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yeXRvffaooIxMKEbbhC9rYaowq3ts_g9 X-Proofpoint-ORIG-GUID: RjTjphhgxogDLAs6b07dhTL5g0LNEfSq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-21_11,2022-06-21_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206220039 ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=temperror ("DNS error when getting key") header.d=ibm.com header.s=pp1 header.b=eAbhHZJY; spf=pass (imf25.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 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=1655887574; 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:dkim-signature; bh=VynPHaB44iwLNm1NI/jimLhyT7ZD9Z8XYUiK5QEqD2Y=; b=u0Y+62/gKdlniF1g1vRIi0fqv1GJVr63/z1uWJYqAYLAlqPRmaaUWBg7ya58wTn6wwFA3V DHBL0hkG+5lMwh40uD4MeucxZ0JtAaSTWC3P8JEDlLEA2phEGO1je619UF/Kvhzzt/sZA5 2wWW/AQ4QK0Fwo7hV19Jyc25Fg1P4Ug= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655887574; a=rsa-sha256; cv=none; b=j4fWaAx78v6P5Eqzgk3nHhmdgvxmN9zw6AZ87w6/v37WNywiSd0/qWNGCel9/iHBnNb8NW JQEPZzb8CIfDk+tr2HI3MJcYrjim5eeAsvmClvOh1BjuJDLZgJkDwUsZ6rgS4b1ORudM+N Hb9Ap/dDrq7b9sSBHQTI2tiBgqpsgYI= X-Stat-Signature: xwjkfiru89ocpf8j7adqwfrqa5zy6g11 X-Rspam-User: X-Rspamd-Server: rspam07 Authentication-Results: imf25.hostedemail.com; dkim=temperror ("DNS error when getting key") header.d=ibm.com header.s=pp1 header.b=eAbhHZJY; spf=pass (imf25.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-Rspamd-Queue-Id: 54715A0093 X-HE-Tag: 1655887569-356525 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: If the new NUMA node onlined doesn't have a memory tier assigned, the kernel adds the NUMA node to default memory tier. Signed-off-by: Aneesh Kumar K.V --- mm/memory-tiers.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index fc404fcff7ff..2147112981a6 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -5,6 +5,7 @@ #include #include #include +#include #include struct memory_tier { @@ -130,8 +131,73 @@ int node_create_and_set_memory_tier(int node, int tier) } EXPORT_SYMBOL_GPL(node_create_and_set_memory_tier); +static int __node_set_memory_tier(int node, int tier) +{ + int ret = 0; + struct memory_tier *memtier; + + memtier = __get_memory_tier_from_id(tier); + if (!memtier) { + ret = -EINVAL; + goto out; + } + node_set(node, memtier->nodelist); +out: + return ret; +} + +static int node_set_memory_tier(int node, int tier) +{ + struct memory_tier *memtier; + int ret = 0; + + mutex_lock(&memory_tier_lock); + memtier = __node_get_memory_tier(node); + if (!memtier) + ret = __node_set_memory_tier(node, tier); + + mutex_unlock(&memory_tier_lock); + + return ret; +} + static unsigned int default_memtier = DEFAULT_MEMORY_TIER; core_param(default_memory_tier, default_memtier, uint, 0644); +/* + * 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. + */ +static int __meminit migrate_on_reclaim_callback(struct notifier_block *self, + unsigned long action, void *_arg) +{ + 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_ONLINE: + /* + * We ignore the error here, if the node already have the tier + * registered, we will continue to use that for the new memory + * we are adding here. + */ + node_set_memory_tier(arg->status_change_nid, default_memtier); + break; + } + + return notifier_from_errno(0); +} + +static void __init migrate_on_reclaim_init(void) +{ + hotplug_memory_notifier(migrate_on_reclaim_callback, 100); +} static int __init memory_tier_init(void) { @@ -153,6 +219,8 @@ static int __init memory_tier_init(void) /* CPU only nodes are not part of memory tiers. */ memtier->nodelist = node_states[N_MEMORY]; mutex_unlock(&memory_tier_lock); + + migrate_on_reclaim_init(); return 0; } subsys_initcall(memory_tier_init);