From patchwork Fri Aug 26 10:02:24 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: 12955816 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 EE37DECAAA3 for ; Fri, 26 Aug 2022 10:03:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B22B940008; Fri, 26 Aug 2022 06:03:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6619E940007; Fri, 26 Aug 2022 06:03:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 502A6940008; Fri, 26 Aug 2022 06:03:34 -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 4282B940007 for ; Fri, 26 Aug 2022 06:03:34 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0FAD116044A for ; Fri, 26 Aug 2022 10:03:34 +0000 (UTC) X-FDA: 79841306748.03.3BADF7D Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf12.hostedemail.com (Postfix) with ESMTP id 7458440022 for ; Fri, 26 Aug 2022 10:03:32 +0000 (UTC) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27Q9ssqN015394; Fri, 26 Aug 2022 10:02:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=qtGOveAZGHqntea80eUXt48fNigwR9RxX3Zy07zwieI=; b=e/md9rTTap3868LvPoYs4WFodRJTJJq4RoXUByhqUSFFx7sHwswjeTakaAUB1Veb3Ipz +BEZpVLJMBkeBRRBX8nYmyYRq+tPzQWf6MIiyvTmxFflv+x8peEsZ9t2gYOP/R2RgR/2 aq1ose/NF1gVTeCyFWsRbf4NIMKAb8tDsGGjokLPTLrufb5uplhLB4GLbW+cZZafvGFo /i+DRcYsqXxJmAcxHKPwwncmIH3892aiaWqkU9IQ4rdCqPCSPHLlrUhYIDQ/PZtJkYlv 2vGAPbA2Qu1HkqDdCM8REpZn4xlrPL4rJv2ZBs71Lomf1YrlK7cRg94Sw2a78XcpAtjA hw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j6uyag8g1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Aug 2022 10:02:43 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27Q9u53O024298; Fri, 26 Aug 2022 10:02:43 GMT Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j6uyag8f5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Aug 2022 10:02:43 +0000 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27Q9nuKV007490; Fri, 26 Aug 2022 10:02:41 GMT Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by ppma05wdc.us.ibm.com with ESMTP id 3j2q8add0k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Aug 2022 10:02:41 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27QA2fF744040670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2022 10:02:41 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 16152AE060; Fri, 26 Aug 2022 10:02:41 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2ADEBAE05C; Fri, 26 Aug 2022 10:02:35 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.10.139]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 26 Aug 2022 10:02:34 +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, Bharata B Rao , "Aneesh Kumar K.V" Subject: [PATCH mm-unstable] mm/demotion: Assign correct memory type for multiple dax devices with the same node affinity Date: Fri, 26 Aug 2022 15:32:24 +0530 Message-Id: <20220826100224.542312-1-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: beGUxM7NooPWd3VMHfktpWJsfFRRDf7v X-Proofpoint-ORIG-GUID: OAWi3D-VOM8w0nUHJFXiIc5l81NUCMUC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-26_04,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 mlxscore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208260040 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661508212; a=rsa-sha256; cv=none; b=B2BKG+d9DATiTcwzhVU0ao5cEwcLWeY7efGzLi4Q5w41UOG/Zw9lA/u5ylPAHMraqwQ+10 cLXbPuVEBhwx5yQwSCBgpOl96Yg5CqUC4gcUPHGNR0MNQVzr8sbwQph0Vqf2s+brtQHMEN /c4y2afpZrDVRKSdoK4lab1x+k/5VYg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="e/md9rTT"; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf12.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661508212; 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:references:dkim-signature; bh=qtGOveAZGHqntea80eUXt48fNigwR9RxX3Zy07zwieI=; b=W3vRPbenrx6p8n8kwokYQ58rhpYM16l7k9TeKRGsglFtoZq692VloACYDTEToDiKn3drRC zc+jXBvlp5qKJD0eMmf0vjK42kd02ZEFdh6EfGiHJfEyjZx67u0P4mweYU5ynoWAQmcHAs SaI3DXUtNAbJBnl3HUyF0rutReNBaTA= Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="e/md9rTT"; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf12.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-Rspam-User: X-Rspamd-Queue-Id: 7458440022 X-Rspamd-Server: rspam08 X-Stat-Signature: 9pk9ouidr41tcii35msjatsexa6wi38b X-HE-Tag: 1661508212-353810 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: With multiple dax devices having the same node affinity, the kernel wrongly assigned default_dram memory type to some devices after the memory hotplug operation. Fix this by not clearing node_memory_types on the dax device remove. The current kernel cleared node_memory_type on successful removal of a dax device. But then we can have multiple dax devices with the same node affinity. Clearing the node_memory_type results in assigning other dax devices to the default dram type when we bring them online. Signed-off-by: Aneesh Kumar K.V --- mm/memory-tiers.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index ba844fe9cc8c..c4bd6d052a33 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -27,9 +27,14 @@ struct demotion_nodes { nodemask_t preferred; }; +struct node_memory_type_map { + struct memory_dev_type *memtype; + int map_count; +}; + static DEFINE_MUTEX(memory_tier_lock); static LIST_HEAD(memory_tiers); -static struct memory_dev_type *node_memory_types[MAX_NUMNODES]; +static struct node_memory_type_map node_memory_types[MAX_NUMNODES]; static struct memory_dev_type *default_dram_type; #ifdef CONFIG_MIGRATION static int top_tier_adistance; @@ -386,9 +391,19 @@ static inline void establish_demotion_targets(void) {} static inline void __init_node_memory_type(int node, struct memory_dev_type *memtype) { - if (!node_memory_types[node]) { - node_memory_types[node] = memtype; - kref_get(&memtype->kref); + if (!node_memory_types[node].memtype) + node_memory_types[node].memtype = memtype; + /* + * for each device getting added in the same NUMA node + * with this specific memtype, bump the map count. We + * Only take memtype device reference once, so that + * changing a node memtype can be done by droping the + * only reference count taken here. + */ + + if (node_memory_types[node].memtype == memtype) { + if (!node_memory_types[node].map_count++) + kref_get(&memtype->kref); } } @@ -406,7 +421,7 @@ static struct memory_tier *set_node_memory_tier(int node) __init_node_memory_type(node, default_dram_type); - memtype = node_memory_types[node]; + memtype = node_memory_types[node].memtype; node_set(node, memtype->nodes); memtier = find_create_memory_tier(memtype); if (!IS_ERR(memtier)) @@ -448,7 +463,7 @@ static bool clear_node_memory_tier(int node) rcu_assign_pointer(pgdat->memtier, NULL); synchronize_rcu(); - memtype = node_memory_types[node]; + memtype = node_memory_types[node].memtype; node_clear(node, memtype->nodes); if (nodes_empty(memtype->nodes)) { list_del_init(&memtype->tier_sibiling); @@ -502,8 +517,14 @@ EXPORT_SYMBOL_GPL(init_node_memory_type); void clear_node_memory_type(int node, struct memory_dev_type *memtype) { mutex_lock(&memory_tier_lock); - if (node_memory_types[node] == memtype) { - node_memory_types[node] = NULL; + if (node_memory_types[node].memtype == memtype) + node_memory_types[node].map_count--; + /* + * If we umapped all the attached devices to this node, + * clear the node memory type. + */ + if (!node_memory_types[node].map_count) { + node_memory_types[node].memtype = NULL; kref_put(&memtype->kref, release_memtype); } mutex_unlock(&memory_tier_lock);