Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1008230iob; Fri, 13 May 2022 19:25:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQLktYIIUApFjg9YgYXLiaNm2+91RZuoc3liNVqyQ60lhKOMQ3HwUr1NGJPyMx14wYc/mv X-Received: by 2002:adf:d1c2:0:b0:20c:a916:490e with SMTP id b2-20020adfd1c2000000b0020ca916490emr5887514wrd.403.1652495134439; Fri, 13 May 2022 19:25:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652495134; cv=none; d=google.com; s=arc-20160816; b=Jt5nZeYPh8YrK5u6rfu+4uKNg0GNfwekHHwXiv4K5I1ahlO8Wq/PM+u1atoNZyURM3 FwQiqYs4q2K9YDOEYySB6HsdMOoqm0bCmI8we2dFGJUyKHykJImT3PERdPZZESNAPdwf M6mPIvY0RqQLm2cIhauhWtjYg4M+AhAGswI3YaYkeUnTivF23yCApl4KAiy/BG5gb9N3 xAyXN3BUouVY6Bj5/cPZ3DvOSoyhfAndrpwVVy4Qm6SIpBQcUYEnUTcTAniSw5YVaN0A V4+sq0AtF1Cvhixv4pCQdzTazr0DhoX01xMkd9oMuEwaSnVt25RQNroajhucKvQkN+7D 0xFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zSQtsKCtwMYCMAV1h8dxEmMkmLjgLgdq8u/If5PWyoo=; b=Vc9KejbU+Tq5aBYGDjG2GqqKYXd0QuvcIFFR9BNJzBbr5biHeQxCau6iONm6gDot+M AfCKQZSuY/0zxyWfGsCfff+BsUBb+oI52VIjwK574tFVXR0rXbfrOrRV2oZBKToWoO2L W+EdphNZYAtMWS4O2YR/5FBPuyYCFVll+sQCzqRFzTPVIssaGKONEo7UDR3M+sLCW298 aU3EryMVmYYGsq3HKusQQ+63EUm6BfgvAySkgLcYlnkPslekxWhYi9jDst0V2DS80Tw+ jL4Y1IL0QQGXyXnwImgUhAiAS6+vBwPfq1Ujaq7OALQIUAIcSZfcqeJkcHXBhPBrlWcv dPFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ghMK2Hcr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v19-20020a05600c215300b0038ed2f750edsi6343779wml.233.2022.05.13.19.25.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:25:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ghMK2Hcr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 29CAB4CAB04; Fri, 13 May 2022 17:40:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377630AbiEMHAi (ORCPT + 99 others); Fri, 13 May 2022 03:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377607AbiEMHAT (ORCPT ); Fri, 13 May 2022 03:00:19 -0400 Received: from mail-vk1-xa2b.google.com (mail-vk1-xa2b.google.com [IPv6:2607:f8b0:4864:20::a2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 774651EEE3B for ; Fri, 13 May 2022 00:00:17 -0700 (PDT) Received: by mail-vk1-xa2b.google.com with SMTP id q136so3762823vke.10 for ; Fri, 13 May 2022 00:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zSQtsKCtwMYCMAV1h8dxEmMkmLjgLgdq8u/If5PWyoo=; b=ghMK2HcrDTMpFO6IVO2QFoxB3sSruYjPWtgLSUU0nZAzAVWbjZR/I92Jcca5YBBd02 r6WXn2DlpPBcjtfKLYUsM3rJbujVUZpo9B+6oBmlT6fTD2ebulJNtpFWY0KI9ozq+F+H tjqsFvAMfaFSO6urR6ZsPMcHj49NE/SdB4lobuQ2ep22BNmxralwTYHKlx7bXPanzpna rFnsjjSsyw6fwfG58NPn/7xSS5p/Xt8qy5LUi1chzrJd1x6Bjw/ycI4X5FJBShd6dkhq ugGKY6arD6j3N9GJRI4szNel9G+zRyCErU6lq5vEMiWan5DjnrIJrDOaIzZ+taTMG6wL Id3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zSQtsKCtwMYCMAV1h8dxEmMkmLjgLgdq8u/If5PWyoo=; b=AM06CnMoTpGqohfybf7kZ3R/ivel8I/5KAJWl7jDhIs4si46kM479gOMOQrMUR6EK4 oEG0mNsXKF7PsywMkY4dY1XV8pedAe29Z3RYSrQ1wE+OwH3yZkGj6LYM7L+5x7LSoo/M xgRqf/eP+S76NLyoXp/3PIgRHl2PtNCaLv1YmIvB1adrqBLzKzl/IB1HsgWUPqsMRC/d +zLsJtLO2d0unY8H4Yajd5U3tMPcNWxBcfh50e7492cWIgteSJfh1NOPLNGp3KkzpzV0 eyFsfx0sep/FHCTSbHuT6S13PfPqsPBVYI9UXtCOdhqXhXZYQUtlR/mD2HPVTEqm/e2/ 1xqg== X-Gm-Message-State: AOAM531QZVW89CPJFxFhfbx0ZVBSPcQ9RceifN2h6wPHRuPZKsDhTWEs +Nq6icplRsQZFGy0jJZn2cp2QfQ0/prWGSeEkRGZpw== X-Received: by 2002:a1f:9b85:0:b0:32d:4d56:cf64 with SMTP id d127-20020a1f9b85000000b0032d4d56cf64mr1480204vke.31.1652425216408; Fri, 13 May 2022 00:00:16 -0700 (PDT) MIME-Version: 1.0 References: <56b41ce6922ed5f640d9bd46a603fa27576532a9.camel@intel.com> <87y1z7jj85.fsf@linux.ibm.com> In-Reply-To: From: Wei Xu Date: Fri, 13 May 2022 00:00:05 -0700 Message-ID: Subject: Re: RFC: Memory Tiering Kernel Interfaces (v2) To: "ying.huang@intel.com" Cc: "Aneesh Kumar K.V" , Andrew Morton , Greg Thelen , Yang Shi , Linux Kernel Mailing List , Jagdish Gediya , Michal Hocko , Tim C Chen , Dave Hansen , Alistair Popple , Baolin Wang , Feng Tang , Jonathan Cameron , Davidlohr Bueso , Dan Williams , David Rientjes , Linux MM , Brice Goglin , Hesham Almatary Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Thu, May 12, 2022 at 7:53 PM ying.huang@intel.com wrote: > > On Thu, 2022-05-12 at 16:37 +0800, ying.huang@intel.com wrote: > > On Thu, 2022-05-12 at 01:15 -0700, Wei Xu wrote: > > > On Thu, May 12, 2022 at 12:36 AM Aneesh Kumar K.V > > > wrote: > > > > > > > > Wei Xu writes: > > > > > > > > > On Thu, May 12, 2022 at 12:12 AM Aneesh Kumar K V > > > > > wrote: > > > > > > > > > > > > On 5/12/22 12:33 PM, ying.huang@intel.com wrote: > > > > > > > On Wed, 2022-05-11 at 23:22 -0700, Wei Xu wrote: > > > > > > > > Sysfs Interfaces > > > > > > > > ================ > > > > > > > > > > > > > > > > * /sys/devices/system/memtier/memtierN/nodelist > > > > > > > > > > > > > > > > where N = 0, 1, 2 (the kernel supports only 3 tiers for now). > > > > > > > > > > > > > > > > Format: node_list > > > > > > > > > > > > > > > > Read-only. When read, list the memory nodes in the specified tier. > > > > > > > > > > > > > > > > Tier 0 is the highest tier, while tier 2 is the lowest tier. > > > > > > > > > > > > > > > > The absolute value of a tier id number has no specific meaning. > > > > > > > > What matters is the relative order of the tier id numbers. > > > > > > > > > > > > > > > > When a memory tier has no nodes, the kernel can hide its memtier > > > > > > > > sysfs files. > > > > > > > > > > > > > > > > * /sys/devices/system/node/nodeN/memtier > > > > > > > > > > > > > > > > where N = 0, 1, ... > > > > > > > > > > > > > > > > Format: int or empty > > > > > > > > > > > > > > > > When read, list the memory tier that the node belongs to. Its value > > > > > > > > is empty for a CPU-only NUMA node. > > > > > > > > > > > > > > > > When written, the kernel moves the node into the specified memory > > > > > > > > tier if the move is allowed. The tier assignment of all other nodes > > > > > > > > are not affected. > > > > > > > > > > > > > > > > Initially, we can make this interface read-only. > > > > > > > > > > > > > > It seems that "/sys/devices/system/node/nodeN/memtier" has all > > > > > > > information we needed. Do we really need > > > > > > > "/sys/devices/system/memtier/memtierN/nodelist"? > > > > > > > > > > > > > > That can be gotten via a simple shell command line, > > > > > > > > > > > > > > $ grep . /sys/devices/system/node/nodeN/memtier | sort -n -k 2 -t ':' > > > > > > > > > > > > > > > > > > > It will be really useful to fetch the memory tier node list in an easy > > > > > > fashion rather than reading multiple sysfs directories. If we don't have > > > > > > other attributes for memorytier, we could keep > > > > > > "/sys/devices/system/memtier/memtierN" a NUMA node list there by > > > > > > avoiding /sys/devices/system/memtier/memtierN/nodelist > > > > > > > > > > > > -aneesh > > > > > > > > > > It is harder to implement memtierN as just a file and doesn't follow > > > > > the existing sysfs pattern, either. Besides, it is extensible to have > > > > > memtierN as a directory. > > > > > > > > diff --git a/drivers/base/node.c b/drivers/base/node.c > > > > index 6248326f944d..251f38ec3816 100644 > > > > --- a/drivers/base/node.c > > > > +++ b/drivers/base/node.c > > > > @@ -1097,12 +1097,49 @@ static struct attribute *node_state_attrs[] = { > > > > NULL > > > > }; > > > > > > > > +#define MAX_TIER 3 > > > > +nodemask_t memory_tier[MAX_TIER]; > > > > + > > > > +#define _TIER_ATTR_RO(name, tier_index) \ > > > > + { __ATTR(name, 0444, show_tier, NULL), tier_index, NULL } > > > > + > > > > +struct memory_tier_attr { > > > > + struct device_attribute attr; > > > > + int tier_index; > > > > + int (*write)(nodemask_t nodes); > > > > +}; > > > > + > > > > +static ssize_t show_tier(struct device *dev, > > > > + struct device_attribute *attr, char *buf) > > > > +{ > > > > + struct memory_tier_attr *mt = container_of(attr, struct memory_tier_attr, attr); > > > > + > > > > + return sysfs_emit(buf, "%*pbl\n", > > > > + nodemask_pr_args(&memory_tier[mt->tier_index])); > > > > +} > > > > + > > > > static const struct attribute_group memory_root_attr_group = { > > > > .attrs = node_state_attrs, > > > > }; > > > > > > > > + > > > > +#define TOP_TIER 0 > > > > +static struct memory_tier_attr memory_tiers[] = { > > > > + [0] = _TIER_ATTR_RO(memory_top_tier, TOP_TIER), > > > > +}; > > > > + > > > > +static struct attribute *memory_tier_attrs[] = { > > > > + &memory_tiers[0].attr.attr, > > > > + NULL > > > > +}; > > > > + > > > > +static const struct attribute_group memory_tier_attr_group = { > > > > + .attrs = memory_tier_attrs, > > > > +}; > > > > + > > > > static const struct attribute_group *cpu_root_attr_groups[] = { > > > > &memory_root_attr_group, > > > > + &memory_tier_attr_group, > > > > NULL, > > > > }; > > > > > > > > > > > > As long as we have the ability to see the nodelist, I am good with the > > > > proposal. > > > > > > > > -aneesh > > > > > > I am OK with moving back the memory tier nodelist into node/. When > > > there are more memory tier attributes needed, we can then create the > > > memory tier subtree and replace the tier nodelist in node/ with > > > symlinks. > > > > What attributes do you imagine that we may put in memory_tierX/ sysfs > > directory? If we have good candidates in mind, we may just do that. > > What I can imagine now is "demote", like "memory_reclaim" in nodeX/ or > > node/ directory you proposed before. Is it necessary to show something > > like "meminfo", "vmstat" there? > > My words may be confusing, so let me say it in another way. I can understand. :) > Just for brainstorm, if we have > > /sys/devices/system/memtier/memtierN/ > > What can we put in it in addition to "nodelist" or links to the nodes? > For example, > > /sys/devices/system/memtier/memtierN/demote > > When write a page number to it, the specified number of pages will be > demoted from memtierN to memtierN+1, like the > /sys/devices/system/node/memory_reclaim interface you proposed before. "demote" might be fine to add there. Just to clarify, we (Google) currently don't yet have the need for an interface to do system-wide demotion from one tier to another. What we need is memory.demote (similar to memory.reclaim) for memory cgroup based demotions. Other things that might be added include tier-specific properties (e.g. expected latency and bandwidth when available) and tier-specific stats. Under /sys/devices/system/memtier/, we may add global properties about memory tiers, e.g. max number of tiers, min/max tier ids (which might be useful if we hide unpopulated memory tiers). > Or, is it necessary to add > > /sys/devices/system/memtier/memtierN/meminfo > /sys/devices/system/memtier/memtierN/vmstat The userspace can aggregate such data from node/nodeN/{meminfo, vmstat} based on the memory tier nodelist. But I am not against adding these files to memtierN/ for user convenience. > I don't mean to propose these. Just want to know whether there's > requirement for these kind of stuff? And what else may be required. This sounds good. I think a memtier directory may eventually become a necessity, though I don't feel too strongly about adding it right now. > Best Regards, > Huang, Ying > > > > > > > So the revised sysfs interfaces are: > > > > > > * /sys/devices/system/node/memory_tierN (read-only) > > > > > > where N = 0, 1, 2 > > > > > > Format: node_list > > > > > > * /sys/devices/system/node/nodeN/memory_tier (read/write) > > > > > > where N = 0, 1, ... > > > > > > Format: int or empty > > > > >