From patchwork Mon Aug 8 06:25:58 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: 12938501 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 4AB6CC00140 for ; Mon, 8 Aug 2022 06:27:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C34E98E0009; Mon, 8 Aug 2022 02:27:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE3EA8E0008; Mon, 8 Aug 2022 02:27:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5EAB8E0009; Mon, 8 Aug 2022 02:27:06 -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 8F9878E0001 for ; Mon, 8 Aug 2022 02:27:06 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6309E1209C6 for ; Mon, 8 Aug 2022 06:27:06 +0000 (UTC) X-FDA: 79775442852.18.822413C Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf08.hostedemail.com (Postfix) with ESMTP id C472216016A for ; Mon, 8 Aug 2022 06:27:05 +0000 (UTC) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2785C1sd023380; Mon, 8 Aug 2022 06:26:56 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=Vm99fpXrEL5sGzVMPQGBhdc/VnWO9MKydLltPdUtcYg=; b=XDILkOvxonbyXAiLlwU4vqfSbdahZfaXgHm4HqnGcYLJAnpE9eSXy9SgnS+TdeiXcgOU wVTb8twNJ329TWqOwXUhNgRnYlYspoxrFG6tHe4ghfT593b/RsXnoJY791FpW/5kE7wM LZLOoWEUyI2SYC17D6aRuOIpTnsIn+3Ovywq/KVBr5JblbAn51IZWQgD8M8XRUMFiHGA 2pZNmJoFLUQIIptpmtE/LwZ1MM/nisyI+Y/N6JW0lKPhsIVn5qxa36VZ3//UtCuCU7Dc +81ULr13vygNDjF5jgmqH8qYP9zty39abdlETg927FldFrxlOOU6g6qfK4vu6uBEg7T/ 1w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3htv4g9tu0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 06:26:56 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2786MmEW007292; Mon, 8 Aug 2022 06:26:55 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 3htv4g9tth-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 06:26:55 +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 2786KbG6028642; Mon, 8 Aug 2022 06:26:54 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma02wdc.us.ibm.com with ESMTP id 3hsfx92v7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 08 Aug 2022 06:26:54 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2786Qrj030933258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Aug 2022 06:26:53 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2DC387805E; Mon, 8 Aug 2022 06:26:53 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DDD478060; Mon, 8 Aug 2022 06:26:47 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.19.76]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 8 Aug 2022 06:26:47 +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 v13 6/9] mm/demotion: Add pg_data_t member to track node memory tier details Date: Mon, 8 Aug 2022 11:55:58 +0530 Message-Id: <20220808062601.836025-7-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808062601.836025-1-aneesh.kumar@linux.ibm.com> References: <20220808062601.836025-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: LcTcIobk-iDHfxlzSLb2Nlsrb872aeul X-Proofpoint-ORIG-GUID: 4j-rHofYnSnj17CbZr69n1LfiUvTCka3 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-08-08_03,2022-08-05_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 spamscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2208080031 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659940026; a=rsa-sha256; cv=none; b=GGzm2TaKgdRlIAF4BN3aYuOegid/CJyc8DcypXR42f9wJ/hqTPZJW1eeIWFw9MVqiEl+A5 bKF8nFnG3qKtIg4sLMweKnHqRysLDtBryar0/1M/MVrCnGqP7GHCoOyi6BLdnmL8W+dTV8 k9DfA+2DGq3y0fAkprLpmHTtDkpeQ04= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=XDILkOvx; spf=pass (imf08.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=1659940026; 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=Vm99fpXrEL5sGzVMPQGBhdc/VnWO9MKydLltPdUtcYg=; b=LxgugFfo62SPmgKVQV3G6hq0NCytZwL0MM618r7P2g4GAgn/r3YpZmMA3hFXCWdefXbwLt m4hNggll0ri4Es6KppALfGHTG2va3tmGq0hzKPhSC3WAoQGqp1oG8cqUlfvGkZLUmyd6By 90ICtibic3Err3GFevI8T80M4Zb2UbI= X-Rspamd-Server: rspam06 X-Rspam-User: X-Stat-Signature: d5psof5nzx38euyexdnjxnhy93bdwqk4 X-Rspamd-Queue-Id: C472216016A Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=XDILkOvx; spf=pass (imf08.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-HE-Tag: 1659940025-319116 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: Also update different helpes to use NODE_DATA()->memtier. Since node specific memtier can change based on the reassignment of NUMA node to a different memory tiers, accessing NODE_DATA()->memtier needs to happen under an rcu read lock or memory_tier_lock. Signed-off-by: Aneesh Kumar K.V --- include/linux/mmzone.h | 3 +++ mm/memory-tiers.c | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index aab70355d64f..353812495a70 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -928,6 +928,9 @@ typedef struct pglist_data { /* Per-node vmstats */ struct per_cpu_nodestat __percpu *per_cpu_nodestats; atomic_long_t vm_stat[NR_VM_NODE_STAT_ITEMS]; +#ifdef CONFIG_NUMA + struct memory_tier __rcu *memtier; +#endif } pg_data_t; #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 02e514e87d5c..3778ac6a44a1 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "internal.h" @@ -137,12 +138,18 @@ static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memty static struct memory_tier *__node_get_memory_tier(int node) { - struct memory_dev_type *memtype; + pg_data_t *pgdat; - memtype = node_memory_types[node]; - if (memtype && node_isset(node, memtype->nodes)) - return memtype->memtier; - return NULL; + pgdat = NODE_DATA(node); + if (!pgdat) + return NULL; + /* + * Since we hold memory_tier_lock, we can avoid + * RCU read locks when accessing the details. No + * parallel updates are possible here. + */ + return rcu_dereference_check(pgdat->memtier, + lockdep_is_held(&memory_tier_lock)); } #ifdef CONFIG_MIGRATION @@ -295,6 +302,8 @@ static struct memory_tier *set_node_memory_tier(int node) { struct memory_tier *memtier; struct memory_dev_type *memtype; + pg_data_t *pgdat = NODE_DATA(node); + lockdep_assert_held_once(&memory_tier_lock); @@ -307,6 +316,8 @@ static struct memory_tier *set_node_memory_tier(int node) memtype = node_memory_types[node]; node_set(node, memtype->nodes); memtier = find_create_memory_tier(memtype); + if (!IS_ERR(memtier)) + rcu_assign_pointer(pgdat->memtier, memtier); return memtier; } @@ -319,12 +330,25 @@ static void destroy_memory_tier(struct memory_tier *memtier) static bool clear_node_memory_tier(int node) { bool cleared = false; + pg_data_t *pgdat; struct memory_tier *memtier; + pgdat = NODE_DATA(node); + if (!pgdat) + return false; + + /* + * Make sure that anybody looking at NODE_DATA who finds + * a valid memtier finds memory_dev_types with nodes still + * linked to the memtier. We achieve this by waiting for + * rcu read section to finish using synchronize_rcu. + */ memtier = __node_get_memory_tier(node); if (memtier) { struct memory_dev_type *memtype; + rcu_assign_pointer(pgdat->memtier, NULL); + synchronize_rcu(); memtype = node_memory_types[node]; node_clear(node, memtype->nodes); if (nodes_empty(memtype->nodes)) { @@ -422,8 +446,10 @@ static int __init memory_tier_init(void) panic("%s() failed to register memory tier: %ld\n", __func__, PTR_ERR(memtier)); - for_each_node_state(node, N_MEMORY) + for_each_node_state(node, N_MEMORY) { __init_node_memory_type(node, default_dram_type); + rcu_assign_pointer(NODE_DATA(node)->memtier, memtier); + } mutex_unlock(&memory_tier_lock); #ifdef CONFIG_MIGRATION