From patchwork Fri Jun 10 13:49:59 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: 12877620 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 60CF8C433EF for ; Fri, 10 Jun 2022 13:53:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD6E58D00A3; Fri, 10 Jun 2022 09:53:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D86BF8D009C; Fri, 10 Jun 2022 09:53:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB2438D00A3; Fri, 10 Jun 2022 09:53:09 -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 A95428D009C for ; Fri, 10 Jun 2022 09:53:09 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 74AC22C1 for ; Fri, 10 Jun 2022 13:53:09 +0000 (UTC) X-FDA: 79562467698.31.043074F Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf25.hostedemail.com (Postfix) with ESMTP id D0527A007B for ; Fri, 10 Jun 2022 13:53:08 +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 25ADInhN023728; Fri, 10 Jun 2022 13:51:39 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=dDKqIfopwnXr6PuIPbN3tqtguXFEUdVD0LR6XZqxlbc=; b=BBYEhv3lPpfS/FdP/vIgP9XMmW3yjWm6fxB9nQKdPre03eeF0OdoYeLRnDDdMKHiD+Lk UN5GCJTqYWQEgVg/CRQLcCKdabaQrHOt8BTOR8uSAgY7AZQ9FYMM+tbrM3WlxjshuIzd ti8r9APLXCZ5nz3hIopchZ/RInf9tSXREYZ3qwecnEcrVRUcO/A2/1tXgCU4QnknALM6 GZY4XnYcyrh9plKenwICGtRWSb+TzVGNw60GPsSYO4Kq9/kvS+S462GcRq+QhLyp1W4/ LxVYAeFMgS7pPNBHYVf3UXR6+kW7GXARoZ1+mqonLd53ufxSlTGqH8RsD5RhR6fBYolg kg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gm6qurppw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 13:51:38 +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 25ADmfNE017844; Fri, 10 Jun 2022 13:51:38 GMT Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gm6qurppj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 13:51:38 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25ADasNU031681; Fri, 10 Jun 2022 13:51:36 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma01wdc.us.ibm.com with ESMTP id 3gfy1a919u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 13:51:36 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25ADpZRG42795324 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jun 2022 13:51:35 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA9046A04D; Fri, 10 Jun 2022 13:51:35 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 491926A057; Fri, 10 Jun 2022 13:51:27 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.90.151]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 10 Jun 2022 13:51:26 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Wei Xu , Huang Ying , Greg Thelen , Yang Shi , Davidlohr Bueso , Tim C Chen , Brice Goglin , Michal Hocko , Linux Kernel Mailing List , Hesham Almatary , Dave Hansen , Jonathan Cameron , Alistair Popple , Dan Williams , Feng Tang , Jagdish Gediya , Baolin Wang , David Rientjes , "Aneesh Kumar K.V" Subject: [PATCH v6 06/13] mm/demotion: Expose memory tier details via sysfs Date: Fri, 10 Jun 2022 19:19:59 +0530 Message-Id: <20220610135006.182507-7-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610135006.182507-1-aneesh.kumar@linux.ibm.com> References: <20220610135006.182507-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: gDU27QRiSx_R1KIVd-F5W2iknnEld0EG X-Proofpoint-ORIG-GUID: nXhSiGoHHGkrNFZeEjphZaBgDUEXvizA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-10_06,2022-06-09_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 phishscore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 suspectscore=0 malwarescore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206100056 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654869189; 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=dDKqIfopwnXr6PuIPbN3tqtguXFEUdVD0LR6XZqxlbc=; b=32yZHUZb4nWcAWB+1/IBLWtvxRr4+MCH4wlf/XxhBcm9991ckmvgUWYhk+lrbyaJAlEjis 4CWdKNz8Eqoo6xEwoyGBsWTPcFYf3SGbjFolPEJUOzZcSPiPngWmnm3gu6Mm4LoZjcNDTP UUqWbRM5zc5+kZpO8CZmOyAaVKSBYu8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654869189; a=rsa-sha256; cv=none; b=v1+srnajK+wsSA7SWAYul/5wX0vdBxsy7JS2GyrnW9DfhR15X5xeyyr9OiflLtQ0aD71PD GPXWUA0zVUkKUuSQjV0X1Dt8eUv249HJk22sVoHOZ6sD2czBKsHlKqtDST07Rh8EGHzt5u b9h+531XTA/n4XovnNFuxQX9zrBthmQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=BBYEhv3l; 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 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=BBYEhv3l; 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: rspam08 X-Rspam-User: X-Stat-Signature: 1s6w6cwpqb8dy61ce7t7p8uzbuzikqrc X-Rspamd-Queue-Id: D0527A007B X-HE-Tag: 1654869188-852214 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: This patch adds /sys/devices/system/memtier/ where all memory tier related details can be found. All created memory tiers will be listed there as /sys/devices/system/memtier/memtierN/ The nodes which are part of a specific memory tier can be listed via /sys/devices/system/memtier/memtierN/nodelist The rank value of a memory tier can be listed via via /sys/devices/system/memtier/memtierN/rank /sys/devices/system/memtier/max_tier shows the maximum number of memory tiers that can be created. /sys/devices/system/memtier/default_tier shows the memory tier to which NUMA nodes get added by default if not assigned a specific memory tier. Signed-off-by: Aneesh Kumar K.V --- mm/memory-tiers.c | 99 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 4 deletions(-) diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 2f116912de43..51210f5efc1f 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -11,8 +11,8 @@ struct memory_tier { struct list_head list; + struct device dev; nodemask_t nodelist; - int id; int rank; }; @@ -20,6 +20,7 @@ struct demotion_nodes { nodemask_t preferred; }; +#define to_memory_tier(device) container_of(device, struct memory_tier, dev) static void establish_migration_targets(void); static DEFINE_MUTEX(memory_tier_lock); static LIST_HEAD(memory_tiers); @@ -86,6 +87,52 @@ static LIST_HEAD(memory_tiers); */ static struct demotion_nodes *node_demotion __read_mostly; +static struct bus_type memory_tier_subsys = { + .name = "memtier", + .dev_name = "memtier", +}; + +static ssize_t nodelist_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct memory_tier *memtier = to_memory_tier(dev); + + return sysfs_emit(buf, "%*pbl\n", + nodemask_pr_args(&memtier->nodelist)); +} +static DEVICE_ATTR_RO(nodelist); + +static ssize_t rank_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct memory_tier *memtier = to_memory_tier(dev); + + return sysfs_emit(buf, "%d\n", memtier->rank); +} +static DEVICE_ATTR_RO(rank); + +static struct attribute *memory_tier_dev_attrs[] = { + &dev_attr_nodelist.attr, + &dev_attr_rank.attr, + NULL +}; + +static const struct attribute_group memory_tier_dev_group = { + .attrs = memory_tier_dev_attrs, +}; + +static const struct attribute_group *memory_tier_dev_groups[] = { + &memory_tier_dev_group, + NULL +}; + +static void memory_tier_device_release(struct device *dev) +{ + struct memory_tier *tier = to_memory_tier(dev); + + kfree(tier); +} + /* * Keep it simple by having direct mapping between * tier index and rank value. @@ -121,6 +168,7 @@ static void insert_memory_tier(struct memory_tier *memtier) static struct memory_tier *register_memory_tier(unsigned int tier, unsigned int rank) { + int error; struct memory_tier *memtier; if (tier >= MAX_MEMORY_TIERS) @@ -130,11 +178,20 @@ static struct memory_tier *register_memory_tier(unsigned int tier, if (!memtier) return ERR_PTR(-ENOMEM); - memtier->id = tier; + memtier->dev.id = tier; memtier->rank = rank; + memtier->dev.bus = &memory_tier_subsys; + memtier->dev.release = memory_tier_device_release; + memtier->dev.groups = memory_tier_dev_groups; insert_memory_tier(memtier); + error = device_register(&memtier->dev); + if (error) { + list_del(&memtier->list); + put_device(&memtier->dev); + return ERR_PTR(error); + } return memtier; } @@ -154,7 +211,7 @@ static struct memory_tier *__get_memory_tier_from_id(int id) struct memory_tier *memtier; list_for_each_entry(memtier, &memory_tiers, list) { - if (memtier->id == id) + if (memtier->dev.id == id) return memtier; } return NULL; @@ -199,7 +256,7 @@ int node_create_and_set_memory_tier(int node, int tier) goto out; } - if (current_tier->id == tier) + if (current_tier->dev.id == tier) goto out; node_clear(node, current_tier->nodelist); @@ -435,10 +492,44 @@ static void __init migrate_on_reclaim_init(void) hotplug_memory_notifier(migrate_on_reclaim_callback, 100); } +static ssize_t +max_tier_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%d\n", MAX_MEMORY_TIERS); +} +static DEVICE_ATTR_RO(max_tier); + +static ssize_t +default_tier_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "memtier%d\n", DEFAULT_MEMORY_TIER); +} +static DEVICE_ATTR_RO(default_tier); + +static struct attribute *memory_tier_attrs[] = { + &dev_attr_max_tier.attr, + &dev_attr_default_tier.attr, + NULL +}; + +static const struct attribute_group memory_tier_attr_group = { + .attrs = memory_tier_attrs, +}; + +static const struct attribute_group *memory_tier_attr_groups[] = { + &memory_tier_attr_group, + NULL, +}; + static int __init memory_tier_init(void) { + int ret; struct memory_tier *memtier; + ret = subsys_system_register(&memory_tier_subsys, memory_tier_attr_groups); + if (ret) + pr_err("%s() failed to register subsystem: %d\n", __func__, ret); + /* * Register only default memory tier to hide all empty * memory tier from sysfs.