From patchwork Thu Jul 14 04:53:47 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: 12917288 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 9B307C43334 for ; Thu, 14 Jul 2022 04:55:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28CCC94017F; Thu, 14 Jul 2022 00:55:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1ECD9940134; Thu, 14 Jul 2022 00:55:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F331594017F; Thu, 14 Jul 2022 00:55:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DE103940134 for ; Thu, 14 Jul 2022 00:55:02 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AD2D9945 for ; Thu, 14 Jul 2022 04:55:02 +0000 (UTC) X-FDA: 79684490844.09.35CCA65 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf25.hostedemail.com (Postfix) with ESMTP id 21069A007B for ; Thu, 14 Jul 2022 04:55:00 +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 26E4euTr025703; Thu, 14 Jul 2022 04:54:54 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=GCK7ll44P8j4h55kV+WDbGEyORYDyOp7vBvfUGSIw0A=; b=pZ5do8lfViIMc4xyZ/APyecusSIsca4WZKmKLn/E4QRf36ajs/npEmCxq2q7XmKuQy4c vp9eWRxLvZy1uRWf6oFr57+L2bKxK8bIAy2qp1sjmTxjM/UgCbYYAv8vlOsYFCwMend5 Ecn2R/aGCQGEX6nltw7j/N/2cYG9BdxbyEqwAZqveNf/Xze/L9EsGz85jk/gHZjVnLpx whkH3YdyTETglCKm0sgsrGXtUX+6DKI69sjMTQCVA2OUEKzRejdsagYWCRfkDa6cWkka +pBv61YebfjS6WjFzIsvFl5esTVym+Hawb4/JyS0MNxcdDOQwEXybutfqsyJ043iZFEu zg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hac1k8dk3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Jul 2022 04:54:53 +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 26E4irFH008767; Thu, 14 Jul 2022 04:54:52 GMT Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hac1k8djv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Jul 2022 04:54:52 +0000 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26E4qOTZ010045; Thu, 14 Jul 2022 04:54:51 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma01dal.us.ibm.com with ESMTP id 3h71aa8s1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Jul 2022 04:54:51 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26E4soA021889472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Jul 2022 04:54:50 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5DDF77805F; Thu, 14 Jul 2022 04:54:50 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0664A7805C; Thu, 14 Jul 2022 04:54:44 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.119.34]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Thu, 14 Jul 2022 04:54:43 +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 , Johannes Weiner , jvgediya.oss@gmail.com, "Aneesh Kumar K.V" Subject: [PATCH v9 4/8] mm/demotion: Add hotplug callbacks to handle new numa node onlined Date: Thu, 14 Jul 2022 10:23:47 +0530 Message-Id: <20220714045351.434957-5-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220714045351.434957-1-aneesh.kumar@linux.ibm.com> References: <20220714045351.434957-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: uMPMhRGHcGzasyEimxH5UObiVYEJQYmK X-Proofpoint-ORIG-GUID: JOK9OVg23shEHFpvU0lD4K5a5O5uW0o9 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-14_02,2022-07-13_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 phishscore=0 clxscore=1015 priorityscore=1501 mlxscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207140019 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657774501; 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=GCK7ll44P8j4h55kV+WDbGEyORYDyOp7vBvfUGSIw0A=; b=0AMmwEFKT1DCxu9ccUYI5dBVx8PzmKwwWg6YS7tlNPIFTyyryooV9nuHA/qsG5NXisf2ST 9GL0b3Bnflv/FHtZET2FKB0LbwlBSH+JU0f3opa8oxZQLjQnoySBhinJ5qePMN2y9leLFt nWJ9tISr0oV8Cfa7v7S8YEYL1oQVFdM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657774501; a=rsa-sha256; cv=none; b=g2KyoDvq3/lAG9oBssqbrzSbj7ymWrFXmXB8KXzpXxkQZUzhxBBIj8sRQM53r2z4xgFb4A gfaudvWUfhOm3iNEzJ0Iy9p7rktkWnRW84rt5Dgnz7dmDXGnji16+ljXJbj/dspSG/5nVc okCYcT6y1AWrJ1Un7DIdbvkXDB3cA8U= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=pZ5do8lf; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf25.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com X-Stat-Signature: g16src85ry3f798bq6oa7s38un1cwx1z X-Rspamd-Queue-Id: 21069A007B X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=pZ5do8lf; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf25.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com X-Rspamd-Server: rspam05 X-HE-Tag: 1657774500-82758 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 79347d4ab05e..5706ad647136 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);