Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2331310iof; Wed, 8 Jun 2022 02:40:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygryH3iLZDN3N4MbbXiLcSGL4L8e3r+SFEyWOkh3hZBMzVHUrBSbuqMo0mt5Hh05W7yl1n X-Received: by 2002:a05:6a00:996:b0:50b:76b8:3bb1 with SMTP id u22-20020a056a00099600b0050b76b83bb1mr34113746pfg.9.1654681233547; Wed, 08 Jun 2022 02:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654681233; cv=none; d=google.com; s=arc-20160816; b=q/0bC/ViLrU64kXz/nY2A3oQKaFPOrMxluYHy+XsCviR349gNnR4etgAIUFJ9und6U y+yW+Viql0yaFVavblU/QTcJiFderfI0xglofGR2kcx9yJo6dWxUGlZqycPLN68Idw2H xT/b7DqPpSapN40Qek6z2Xc4gk7HDOC0kO8uOnRtRPCr9tKXHKvUEJUBgZWWlNr+pKpB mrfsdzPB09ADEdJj4w7IuzY5S3TTMCjHjayxeOIqeTyJzwU4zNLCSvRf4DM5SeCAHJZs ITPrjgxHd1s89mjTn4fBAT5nbuQTXOzIQNhdKFvmMRfPC5HVYMLHZrcjySnCOpB0JYVr ea9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=ILLCgQ/DfF75tlDh2t7mveGzfGcqnk/wUDC0q3h3Dzw=; b=F07jb+ZACVGLFsGQzsDzVxE+BReIYVBd46jFrR5A+rRDi2yh/b9DC9yI3E6d88V4yO cyzIVkEjYQoBSpNd/EcMmC+b3Y21xYetEWYG96ixG9EsI/FoDQlmjuu0aeWdS06lXnLG u0+mY+eIwDmIHWFmUqLDM6Ydu1yXb2RrsxLhZigl9hl8k+ur+z+YXm7GISFeCftJy3L+ Lwm0EE3zysQT+rwK8nNFnEFlmbN/PtFN1m9x9NdHER39GLxrEq1+dVpHJ5uXBjYnYdwS e3PuipU+YaRczBwPTxIW9xwcFfi+EZA7u+9rTWLjXQYjMwH5zx6Pc2vN+xqyMLSn+UBg ac2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F6FmLGBS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u71-20020a63854a000000b003fd1b36af89si19743222pgd.801.2022.06.08.02.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 02:40:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F6FmLGBS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 581E51CB718; Wed, 8 Jun 2022 02:12:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234332AbiFHJLD (ORCPT + 99 others); Wed, 8 Jun 2022 05:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234152AbiFHJJl (ORCPT ); Wed, 8 Jun 2022 05:09:41 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CAB71DFC7F for ; Wed, 8 Jun 2022 01:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654676972; x=1686212972; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=6M2Lzi3AGThX+50BydU84KfhNGFSIyUBnMAloNA6clY=; b=F6FmLGBS0HVF+w88Rt+gzCREF7bcDJdECg6Gg8QLdG/JG+A//qvFaDX1 iE8JhD7Q0C5woGBnnhDj1GLy6CMYneE05HY3do1arCPKfcWARneHLXDMG O4g4/qSDwMIZafBjcxH25MiFpu4QCxvNMCjFEOY3FPbL/MqmU7Y7Rl3rq O0WU2R3DuXM1mls6fneFmnZQZEpz/hNznQTXpxWKBch5ZAbTvT0qFS/c1 3As/qnmSQPtOrIIIzmULX7sKurZe7IXZ0lvQ2U7xIUoqlYGGv/FDQurLJ dSI+0JMujM8o0AqYO0CQjMmYjJzv6h76Wi9KAGCWhqe4KjM5s/CwWRtoI A==; X-IronPort-AV: E=McAfee;i="6400,9594,10371"; a="275578918" X-IronPort-AV: E=Sophos;i="5.91,285,1647327600"; d="scan'208";a="275578918" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2022 01:29:32 -0700 X-IronPort-AV: E=Sophos;i="5.91,285,1647327600"; d="scan'208";a="579961629" Received: from xding11-mobl.ccr.corp.intel.com ([10.254.214.239]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2022 01:29:26 -0700 Message-ID: <6be904db28e3be0b0455ae750b595ee76edd08cf.camel@intel.com> Subject: Re: [RFC PATCH v4 2/7] mm/demotion: Expose per node memory tier to sysfs From: Ying Huang To: Aneesh Kumar K V , linux-mm@kvack.org, akpm@linux-foundation.org Cc: 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 Date: Wed, 08 Jun 2022 16:29:23 +0800 In-Reply-To: References: <20220527122528.129445-1-aneesh.kumar@linux.ibm.com> <20220527122528.129445-3-aneesh.kumar@linux.ibm.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2022-06-08 at 13:55 +0530, Aneesh Kumar K V wrote: > On 6/8/22 12:48 PM, Ying Huang wrote: > > On Fri, 2022-05-27 at 17:55 +0530, Aneesh Kumar K.V wrote: > > > From: Jagdish Gediya > > > > > > Add support to read/write the memory tierindex 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, writing to the above file > > > create the tier and assign the NUMA node to that tier. > > > > > > mutex memory_tier_lock is introduced to protect memory tier > > > related chanegs as it can happen from sysfs as well on hot > > > plug events. > > > > > > Signed-off-by: Jagdish Gediya > > > Signed-off-by: Aneesh Kumar K.V > > > --- > > >   drivers/base/node.c | 35 ++++++++++++++ > > >   include/linux/migrate.h | 4 +- > > >   mm/migrate.c | 103 ++++++++++++++++++++++++++++++++++++++++ > > >   3 files changed, 141 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/base/node.c b/drivers/base/node.c > > > index ec8bb24a5a22..cf4a58446d8c 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,45 @@ static ssize_t node_read_distance(struct device *dev, > > >   } > > >   static DEVICE_ATTR(distance, 0444, node_read_distance, NULL); > > >    > > > > > > > > > > > > > > > +#ifdef CONFIG_TIERED_MEMORY > > > +static ssize_t memtier_show(struct device *dev, > > > + struct device_attribute *attr, > > > + char *buf) > > > +{ > > > + int node = dev->id; > > > + > > > + return sysfs_emit(buf, "%d\n", node_get_memory_tier(node)); > > > +} > > > + > > > +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 = kstrtoul(buf, 10, &tier); > > > + if (ret) > > > + return ret; > > > + > > > + ret = node_reset_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_TIERED_MEMORY > > > + &dev_attr_memtier.attr, > > > +#endif > > >    NULL > > >   }; > > >    > > > > > > > > > > > > > > > diff --git a/include/linux/migrate.h b/include/linux/migrate.h > > > index 0ec653623565..d37d1d5dee82 100644 > > > --- a/include/linux/migrate.h > > > +++ b/include/linux/migrate.h > > > @@ -177,13 +177,15 @@ enum memory_tier_type { > > >   }; > > >    > > > > > > > > > > > > > > >   int next_demotion_node(int node); > > > - > > >   extern void migrate_on_reclaim_init(void); > > >   #ifdef CONFIG_HOTPLUG_CPU > > >   extern void set_migration_target_nodes(void); > > >   #else > > >   static inline void set_migration_target_nodes(void) {} > > >   #endif > > > +int node_get_memory_tier(int node); > > > +int node_set_memory_tier(int node, int tier); > > > +int node_reset_memory_tier(int node, int tier); > > >   #else > > >   #define numa_demotion_enabled false > > >   static inline int next_demotion_node(int node) > > > diff --git a/mm/migrate.c b/mm/migrate.c > > > index f28ee93fb017..304559ba3372 100644 > > > --- a/mm/migrate.c > > > +++ b/mm/migrate.c > > > @@ -2132,6 +2132,7 @@ static struct bus_type memory_tier_subsys = { > > >    .dev_name = "memtier", > > >   }; > > >    > > > > > > > > > > > > > > > +DEFINE_MUTEX(memory_tier_lock); > > >   static struct memory_tier *memory_tiers[MAX_MEMORY_TIERS]; > > >    > > > > > > > > > > > > > > >   static ssize_t nodelist_show(struct device *dev, > > > @@ -2225,6 +2226,108 @@ static const struct attribute_group *memory_tier_attr_groups[] = { > > >    NULL, > > >   }; > > >    > > > > > > > > > > > > > > > +static int __node_get_memory_tier(int node) > > > +{ > > > + int tier; > > > + > > > + for (tier = 0; tier < MAX_MEMORY_TIERS; tier++) { > > > + if (memory_tiers[tier] && node_isset(node, memory_tiers[tier]->nodelist)) > > > + return tier; > > > + } > > > + > > > + return -1; > > > +} > > > + > > > +int node_get_memory_tier(int node) > > > +{ > > > + int tier; > > > + > > > + /* > > > + * Make sure memory tier is not unregistered > > > + * while it is being read. > > > + */ > > > + mutex_lock(&memory_tier_lock); > > > + > > > + tier = __node_get_memory_tier(node); > > > + > > > + mutex_unlock(&memory_tier_lock); > > > + > > > + return tier; > > > +} > > > + > > > +int __node_set_memory_tier(int node, int tier) > > > +{ > > > + int ret = 0; > > > + /* > > > + * As register_memory_tier() for new tier can fail, > > > + * try it before modifying existing tier. register > > > + * tier makes tier visible in sysfs. > > > + */ > > > + if (!memory_tiers[tier]) { > > > + ret = register_memory_tier(tier); > > > + if (ret) { > > > + goto out; > > > + } > > > + } > > > + > > > + node_set(node, memory_tiers[tier]->nodelist); > > > + > > > +out: > > > + return ret; > > > +} > > > + > > > +int node_reset_memory_tier(int node, int tier) > > > > I think "reset" isn't a good name here. Maybe something like "change" > > or "move"? > > > > how about node_update_memory_tier()? That sounds OK for me. Best Regards, Huang, Ying