From patchwork Wed Jun 22 08:25:08 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: 12890305 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 2C378C433EF for ; Wed, 22 Jun 2022 08:34:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4B478E0091; Wed, 22 Jun 2022 04:34:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F8CF8E008A; Wed, 22 Jun 2022 04:34:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 899E98E0091; Wed, 22 Jun 2022 04:34:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 79FC48E008A for ; Wed, 22 Jun 2022 04:34:24 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3EEB435601 for ; Wed, 22 Jun 2022 08:26:33 +0000 (UTC) X-FDA: 79605190266.24.35E8339 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf11.hostedemail.com (Postfix) with ESMTP id 9C9BA4000E for ; Wed, 22 Jun 2022 08:26:27 +0000 (UTC) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25M87Ns6005522; Wed, 22 Jun 2022 08:26:21 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=bUKtfnF5lp5n6saH/VnpP793cWjuWytUL0WlkyT0+FI=; b=PZf1B45LzunNfHXChAdQFqx1ipoQmMvJ+cGMaCoEeaP0EUsrxllI4HpqtwehgEa28JNf kxIEq9XyksmlMDM89cKbb30YuNXVrCPClrwP3J5BBBWKt9hSUgtXnb7JyPn/ubSqTwaZ Obgq3bWhklyw8DISTt+YN/3vKoU5NrztiXPdY6anqCnb0ItQshfrkBtKfINKkVkUxjoL SChu8E5ROo5eSqg0CqIinNEiI+OYf8dTEM4eqXoVZJhmy1uxreiG4LZM58IoFdtYmEJD fQR7DflaKMlwHJPACBHBSMMqHuy7Dj8RHOWXKjMo/fWySpwymemMndHU55wSblG/7+NP eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3guxfs1paw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Jun 2022 08:26:21 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25M87rVO009673; Wed, 22 Jun 2022 08:26:20 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 3guxfs1p9e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Jun 2022 08:26:20 +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 25M8LYXR009059; Wed, 22 Jun 2022 08:26:16 GMT Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by ppma02wdc.us.ibm.com with ESMTP id 3gs6ba9b86-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Jun 2022 08:26:16 +0000 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25M8QFet31654154 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 22 Jun 2022 08:26:15 GMT Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A35416E052; Wed, 22 Jun 2022 08:26:15 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B08D36E04E; Wed, 22 Jun 2022 08:26:09 +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:26:09 +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" , Jagdish Gediya Subject: [PATCH v7 07/12] mm/demotion: Add per node memory tier attribute to sysfs Date: Wed, 22 Jun 2022 13:55:08 +0530 Message-Id: <20220622082513.467538-8-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-ORIG-GUID: 0YdBwUUsaz4ZRLw-J9z8Uzn5kDBksQdl X-Proofpoint-GUID: 8_fWbKy7kZW7cxuAx2OFLGe300MdV-vJ 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-22_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=999 impostorscore=0 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 priorityscore=1501 adultscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206220039 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655886387; a=rsa-sha256; cv=none; b=ak6Vi6kxWgHDZQPAmoucVzYv4GsaNYc4jSS8qoBJEj+wNkVeoVshQKacBy6Q7ZtUn8aj2g 1usIRhxJOrN41hHlgy0s7QLRZ9+J2d3JTClYFlErIUA+4AskGvsVldykIM1f3NDWv7hg/k WrauyRP82apxSpkMs/Sh6Vie69/N134= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655886387; 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=bUKtfnF5lp5n6saH/VnpP793cWjuWytUL0WlkyT0+FI=; b=oeNDdWiyalYDgEQbdroKzxKI/5yjmSUA46yLmzwsQHtb8x+pjZopm4GvjJBQ3Rt0V6WH5Z gc5psPr9+DFNNJWPwaqRNEg5EmMtdkyqM37ygssFxhGuGnyxgnRQ1YExSBCWT5JkJjIDMB zSu4KJ+N1O9OLlKhykXxIoin1KaJLvE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=PZf1B45L; dmarc=pass (policy=none) header.from=ibm.com; spf=temperror (imf11.hostedemail.com: error in processing during lookup of aneesh.kumar@linux.ibm.com: DNS error) smtp.mailfrom=aneesh.kumar@linux.ibm.com X-Rspam-User: X-Rspamd-Queue-Id: 9C9BA4000E Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=PZf1B45L; dmarc=pass (policy=none) header.from=ibm.com; spf=temperror (imf11.hostedemail.com: error in processing during lookup of aneesh.kumar@linux.ibm.com: DNS error) smtp.mailfrom=aneesh.kumar@linux.ibm.com X-Stat-Signature: y159qbr3z36nzs5aadu6mxsjrk3xna3s X-Rspamd-Server: rspam09 X-HE-Tag: 1655886387-98031 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: Add support to modify the memory tier for a NUMA node. /sys/devices/system/node/nodeN/memtier where N = node id When read, It list the memory tier that the node belongs to. When written, the kernel moves the node into the specified memory tier, the tier assignment of all other nodes are not affected. If the memory tier does not exist, it is created. Suggested-by: Wei Xu Signed-off-by: Jagdish Gediya Signed-off-by: Aneesh Kumar K.V --- drivers/base/node.c | 42 ++++++++++++++++++++++++++++++++++++ include/linux/memory-tiers.h | 2 ++ mm/memory-tiers.c | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/drivers/base/node.c b/drivers/base/node.c index 0ac6376ef7a1..667f37eecf3a 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -20,6 +20,7 @@ #include #include #include +#include static struct bus_type node_subsys = { .name = "node", @@ -560,11 +561,52 @@ static ssize_t node_read_distance(struct device *dev, } static DEVICE_ATTR(distance, 0444, node_read_distance, NULL); +#ifdef CONFIG_NUMA +static ssize_t memtier_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int node = dev->id; + int tier_index = node_get_memory_tier_id(node); + + /* + * CPU only NUMA node is not part of memory tiers. + */ + if (tier_index != -1) + return sysfs_emit(buf, "%d\n", tier_index); + return 0; +} + +static ssize_t memtier_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long tier; + int node = dev->id; + int ret; + + ret = kstrtoul(buf, 10, &tier); + if (ret) + return ret; + + ret = node_update_memory_tier(node, tier); + if (ret) + return ret; + + return count; +} + +static DEVICE_ATTR_RW(memtier); +#endif + static struct attribute *node_dev_attrs[] = { &dev_attr_meminfo.attr, &dev_attr_numastat.attr, &dev_attr_distance.attr, &dev_attr_vmstat.attr, +#ifdef CONFIG_NUMA + &dev_attr_memtier.attr, +#endif NULL }; diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 3234301c2537..453f6e5d357c 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -23,6 +23,8 @@ static inline int next_demotion_node(int node) return NUMA_NO_NODE; } #endif +int node_get_memory_tier_id(int node); +int node_update_memory_tier(int node, int tier); #else diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 4acf7570ae1b..b7cb368cb9c0 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -288,6 +288,48 @@ static int node_set_memory_tier(int node, int tier) return ret; } +int node_get_memory_tier_id(int node) +{ + int tier = -1; + struct memory_tier *memtier; + /* + * Make sure memory tier is not unregistered + * while it is being read. + */ + mutex_lock(&memory_tier_lock); + memtier = __node_get_memory_tier(node); + if (memtier) + tier = memtier->dev.id; + mutex_unlock(&memory_tier_lock); + + return tier; +} + +int node_update_memory_tier(int node, int tier) +{ + struct memory_tier *current_tier; + int ret = 0; + + mutex_lock(&memory_tier_lock); + + current_tier = __node_get_memory_tier(node); + if (!current_tier || current_tier->dev.id == tier) + goto out; + + node_clear(node, current_tier->nodelist); + + ret = __node_create_and_set_memory_tier(node, tier); + + if (nodes_empty(current_tier->nodelist)) + unregister_memory_tier(current_tier); + + establish_migration_targets(); +out: + mutex_unlock(&memory_tier_lock); + + return ret; +} + #ifdef CONFIG_MIGRATION /** * next_demotion_node() - Get the next node in the demotion path