Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1263269rdb; Mon, 2 Oct 2023 04:37:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOvzZC+6vhvJlDdui8UTlAo+slJxcrWlFEtcSl9Ggp+h0eQOaw7YrSbgCHMZ2K9k7syO9/ X-Received: by 2002:a17:90b:a42:b0:263:829:2de with SMTP id gw2-20020a17090b0a4200b00263082902demr8948388pjb.2.1696246658744; Mon, 02 Oct 2023 04:37:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696246658; cv=none; d=google.com; s=arc-20160816; b=fhShjH5ZO+TZyhe1J1teyruOxHuuXnj1cRLUl4VGNqZuuVBc+xdQFhZGDicr1vx3FZ Gqh0TV+C0n0VYO7MoowzWTaEM5svLc1PuckWGpqLZUl3vuiYoycjX3KtUdpEQwRQC1Ai Xttm2pgdWyEi9IOYvwp216w0Ke25GBR+Nfevd7QIshxRQD4QnZwLmY0Dh+hq+a5pz/mD xYCaZnT4aGp3HaGRd4MReK79c+QIP0Pqijx/NyDIieOcl/wb8Tmo6GhmHhEUEliHgkW1 sdc2s1To4svD6nODdMGpw5jw90AfAogFV3CPE2iq9DPC1vKSKFVMtr14AlUV5+o0Md26 JsIQ== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=d2F4WUrQdsmNh4EJWsOUAodG4cO1HrCSebSQPRctNXU=; fh=7LczcLkV9zbJ0YhNciB8EVx8xBLMb90+YFUgv68Lurk=; b=FPPbY912Or/KjtJ5LgFokyeSw+hauNgkSJ2xYHbcul596X0P2t5qxk9cRWFkW5LsBB 12jzzPw0uED7qGVO8SwzGRxoIXBJurqO6BUETpEgbb4G0RITulwXlAo5KozmfwAQXQUL 9aUg4XGKxKnRUQqnsngZ0amcVQWHLApXdpYahBnO0RycFm78BSFboF9ZHEk9StwfLRV/ pR7mtWnyGGdXV2t5tnhpI26Qm7+pezLQNK1Rb8h8gieEaoNPbYBfRYKeCzmw5QfAkgFV R+oKHv08jmaM05lt57pt1t7c4+p5mESL5BALRvTXUnWp8bj3bUDlPawegV99a9DgJZix vGXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id nh19-20020a17090b365300b00269584b6a10si7136698pjb.15.2023.10.02.04.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 04:37:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 00EF0806A95C; Mon, 2 Oct 2023 03:26:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236460AbjJBK0f (ORCPT + 99 others); Mon, 2 Oct 2023 06:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236516AbjJBK0b (ORCPT ); Mon, 2 Oct 2023 06:26:31 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DC29A6; Mon, 2 Oct 2023 03:26:26 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RzcYh1lwxz67nbv; Mon, 2 Oct 2023 18:26:16 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 2 Oct 2023 11:26:22 +0100 Date: Mon, 2 Oct 2023 11:26:22 +0100 From: Jonathan Cameron To: Ravi Jonnalagadda CC: , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH 1/2] memory tier: Introduce sysfs for tier interleave weights. Message-ID: <20231002112622.0000220a@Huawei.com> In-Reply-To: <20230927095002.10245-2-ravis.opensrc@micron.com> References: <20230927095002.10245-1-ravis.opensrc@micron.com> <20230927095002.10245-2-ravis.opensrc@micron.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml100004.china.huawei.com (7.191.162.219) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 03:26:46 -0700 (PDT) On Wed, 27 Sep 2023 15:20:01 +0530 Ravi Jonnalagadda wrote: > From: Srinivasulu Thanneeru > > Allocating pages across tiers is accomplished by provisioning > interleave weights for each tier, with the distribution based on > these weight values. > By default, all tiers will have a weight of 1, which means > default standard page allocation. By default all nodes within > tier will have weight of 1. > > Signed-off-by: Srinivasulu Thanneeru > Co-authored-by: Ravi Jonnalagadda ABI docs? Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers A few trivial comments inline. > --- > include/linux/memory-tiers.h | 2 ++ > mm/memory-tiers.c | 46 +++++++++++++++++++++++++++++++++++- > 2 files changed, 47 insertions(+), 1 deletion(-) > > diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h > index 437441cdf78f..c62d286749d0 100644 > --- a/include/linux/memory-tiers.h > +++ b/include/linux/memory-tiers.h > @@ -19,6 +19,8 @@ > */ > #define MEMTIER_ADISTANCE_DRAM ((4 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE >> 1)) > > +#define MAX_TIER_INTERLEAVE_WEIGHT 100 > + > struct memory_tier; > struct memory_dev_type { > /* list of memory types that are part of same tier as this type */ > diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c > index 37a4f59d9585..7e06c9e0fa41 100644 > --- a/mm/memory-tiers.c > +++ b/mm/memory-tiers.c > @@ -13,6 +13,11 @@ struct memory_tier { > struct list_head list; > /* list of all memory types part of this tier */ > struct list_head memory_types; > + /* > + * By default all tiers will have weight as 1, which means they > + * follow default standard allocation. > + */ > + unsigned short interleave_weight; If you are going to use fixed size, keep it going. u16 (u8 as per below comment probably makes more sense) > /* > * start value of abstract distance. memory tier maps > * an abstract distance range, > @@ -145,8 +150,45 @@ static ssize_t nodelist_show(struct device *dev, > } > static DEVICE_ATTR_RO(nodelist); > > +static ssize_t interleave_weight_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + int ret; > + struct memory_tier *tier = to_memory_tier(dev); > + > + mutex_lock(&memory_tier_lock); > + ret = sysfs_emit(buf, "%u\n", tier->interleave_weight); > + mutex_unlock(&memory_tier_lock); For this one guard(mutex)(&memory_tier_lock); return sysfs_emit()... would perhaps be slightly nicer (see below) > + > + return ret; > +} > + > +static ssize_t interleave_weight_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t size) > +{ > + unsigned short value; > + int ret; > + struct memory_tier *tier = to_memory_tier(dev); > + > + ret = kstrtou16(buf, 0, &value); Why u16? Max is 100. I'd not mind if you just put it in an unsigned int, but seems odd to chose a specific size and pick one that is twice as big as needed! > + > + if (ret) > + return ret; > + if (value > MAX_TIER_INTERLEAVE_WEIGHT) > + return -EINVAL; > + > + mutex_lock(&memory_tier_lock); You could play with the new cleanup.h toys though it doesn't save a lot here. scoped_guard(mutex)(&memory_tier_lock) tier->interleave_weight = value; > + tier->interleave_weight = value; > + mutex_unlock(&memory_tier_lock); > + > + return size; > +} > +static DEVICE_ATTR_RW(interleave_weight); > + > static struct attribute *memtier_dev_attrs[] = { > &dev_attr_nodelist.attr, > + &dev_attr_interleave_weight.attr, > NULL > }; > > @@ -489,8 +531,10 @@ static struct memory_tier *set_node_memory_tier(int node) > memtype = node_memory_types[node].memtype; > node_set(node, memtype->nodes); > memtier = find_create_memory_tier(memtype); > - if (!IS_ERR(memtier)) > + if (!IS_ERR(memtier)) { > rcu_assign_pointer(pgdat->memtier, memtier); > + memtier->interleave_weight = 1; > + } > return memtier; > } >