Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp791091iob; Fri, 13 May 2022 12:44:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSLfgZQOvLy1UcTtmeHbBHm1rYZeevYGdQT/9Xu10bbitqog/JLLBdg+Hysl8ABurLh8Tm X-Received: by 2002:a05:600c:4f13:b0:394:80aa:76cf with SMTP id l19-20020a05600c4f1300b0039480aa76cfmr6045489wmq.70.1652471052407; Fri, 13 May 2022 12:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652471052; cv=none; d=google.com; s=arc-20160816; b=d2SjgJMMqYyEQ9oEfTsgHJwky/9l3kfGgCa2n0o26YPHkmwU86VslU2FI71CFMGYy/ gHBbQm9rX+EFAdRavnS2wbjZdXpxk8XX3KIF5V+pAqktIqaXnd0VjJZemhSGLhOgrhfe K6hwsaCFhugVKb+d2W01KyuqfcRA6XdQ3htuNc7SUCj6AHDyQ0mhkNjr7OzLBS4u1LUm +xyFiVX5XzZ2groEwtC6XmRlbeumWRZSsVSbIqNQhnGJ+Vz4lLqFNtUr+5MpqE1WuJ1Z v0PG0YQbQhBVT3e3U2G4a56sJv2xx61Hor7FwAnUMelT3wCcFlZI4rADNlOG4WZK6AiR D3NQ== 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=dZTDnUWLhC6cjTXpBhDBsxqrgSnxn4/8Ogucz8EU94s=; b=t+6hGnk98hdDLA49MIZShDjUXApRtDd/6xrOSGJs7vnnEfjIkmcglDftA08NQjOE4g eLL1zRNTwyh72/p7resnaMgAg3Y9t8UfMsJ/LQ2lxeleQLdZUNC7BOm6jlkf52PfvsP0 200H7v3hEyBf1flKt1TZSXYMV2zhi8kQ7WMjJ8ZxxFoSofg25oEUBeBLkjPWW4PXJJqi 9YiYBADfNcqSddL1y+IoP9sdoyE+1osdwVHusoPISwQkyoH0hdk38z1VcpEFbIQAHqoj 5gB+mzK426A8FVoNsadUjgGX5ixM1fhK12+uJJXQTcE8AzmF0LbqaMmMHD+/24ExnP2F 0C5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=D4JCCyKL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a5d4dd0000000b00207a6a693dcsi2775372wru.277.2022.05.13.12.43.43; Fri, 13 May 2022 12:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=D4JCCyKL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348604AbiELEtm (ORCPT + 99 others); Thu, 12 May 2022 00:49:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348673AbiELEt2 (ORCPT ); Thu, 12 May 2022 00:49:28 -0400 Received: from mail-ua1-x931.google.com (mail-ua1-x931.google.com [IPv6:2607:f8b0:4864:20::931]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 380EC3818A for ; Wed, 11 May 2022 21:49:27 -0700 (PDT) Received: by mail-ua1-x931.google.com with SMTP id p1so1584471uak.1 for ; Wed, 11 May 2022 21:49:27 -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=dZTDnUWLhC6cjTXpBhDBsxqrgSnxn4/8Ogucz8EU94s=; b=D4JCCyKL+1RD+XHpB+jmPd5St1jxQqq2hTlRXQmLvp/mQplKm2rSHkWSxjslOs/aws DY+FuY8f/UNVG4vnlsFn8uGi6Zly00KYEZ0vGfHnh0zSQcfDdf1Oog+L/d7Lyjkc1YSE gKD5dy6CpL5eamPmyQiuMWPEyvZzOukSrH2t680iP4M9f6idiCrNLgvVct1wNxJGwOzw wuDtLo/aqerLTd5w9SylSJXEukAl0ZLagVCifcsK9rphdylVwfq32iOP5bsgVBWEnBYo xm+8vQEoAHeS2zp2c4gayV1oOyXsPDKdJYTE2mqdA08FGEbcFJ2+Fgbux8asFHByR9MY 6iYw== 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=dZTDnUWLhC6cjTXpBhDBsxqrgSnxn4/8Ogucz8EU94s=; b=xSmPiKXSCkge9FfpaPJLchNSPK9TgWcOV7mPuAbaRkHrcRGasxN16HJysZpt194MsC 8rDmXi/loERC8eRowvqrN0kIINRP4Ps23/zajsRSCMfqtBIAK1gQhwTbvw1u+ijhQ5iW Myg8NBMWbJ9xSXE5/OyGoF8kvvMJv0e3SPJZFNB5jq2+WRRXAzdcXXQJ9WwlVq3InTBN ouFQp04roEGtJ2p+I+tflcYNODS0OcW0m2dnzbRtMzbDmILuc+Mk269ybqcJG8XNtoqp 6le8fxqBueRY9lizWYT0iFFA+gFMLqYDvoiqIiGZefhgHtXLJjZ0pZjFvQVQTKS/veOF 2MWg== X-Gm-Message-State: AOAM533My4EGiZ8WFWVOGCfr0UuJwH2UML5Tl7AfQQRSMVo4V3jVVDgX nxcJUeHEHQ7lOZhxAG8AcsQLv2Xq8b2yGnEH2MLD+w== X-Received: by 2002:ab0:e14:0:b0:360:e13:e5d7 with SMTP id g20-20020ab00e14000000b003600e13e5d7mr15545369uak.95.1652330964925; Wed, 11 May 2022 21:49:24 -0700 (PDT) MIME-Version: 1.0 References: <1642ab64-7957-e1e6-71c5-ceab9c23bf41@huawei.com> <87o804r08w.fsf@nvdebian.thelocal> In-Reply-To: From: Wei Xu Date: Wed, 11 May 2022 21:49:13 -0700 Message-ID: Subject: Re: RFC: Memory Tiering Kernel Interfaces To: Aneesh Kumar K V Cc: Alistair Popple , Hesham Almatary , Yang Shi , Andrew Morton , Dave Hansen , Huang Ying , Dan Williams , Linux MM , Greg Thelen , Jagdish Gediya , Linux Kernel Mailing List , Davidlohr Bueso , Michal Hocko , Baolin Wang , Brice Goglin , Feng Tang , Tim Chen Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Wed, May 11, 2022 at 9:40 PM Aneesh Kumar K V wrote: > > On 5/11/22 12:42 PM, Alistair Popple wrote: > > > > Wei Xu writes: > > > >> On Tue, May 10, 2022 at 5:10 AM Aneesh Kumar K V > >> wrote: > >>> > >>> On 5/10/22 3:29 PM, Hesham Almatary wrote: > >>>> Hello Yang, > >>>> > >>>> On 5/10/2022 4:24 AM, Yang Shi wrote: > >>>>> On Mon, May 9, 2022 at 7:32 AM Hesham Almatary > >>>>> wrote: > >>> > >>> > >>> ... > >>> > >>>>>> > >>>>>> node 0 has a CPU and DDR memory in tier 0, node 1 has GPU and DDR memory > >>>>>> in tier 0, > >>>>>> node 2 has NVMM memory in tier 1, node 3 has some sort of bigger memory > >>>>>> (could be a bigger DDR or something) in tier 2. The distances are as > >>>>>> follows: > >>>>>> > >>>>>> -------------- -------------- > >>>>>> | Node 0 | | Node 1 | > >>>>>> | ------- | | ------- | > >>>>>> | | DDR | | | | DDR | | > >>>>>> | ------- | | ------- | > >>>>>> | | | | > >>>>>> -------------- -------------- > >>>>>> | 20 | 120 | > >>>>>> v v | > >>>>>> ---------------------------- | > >>>>>> | Node 2 PMEM | | 100 > >>>>>> ---------------------------- | > >>>>>> | 100 | > >>>>>> v v > >>>>>> -------------------------------------- > >>>>>> | Node 3 Large mem | > >>>>>> -------------------------------------- > >>>>>> > >>>>>> node distances: > >>>>>> node 0 1 2 3 > >>>>>> 0 10 20 20 120 > >>>>>> 1 20 10 120 100 > >>>>>> 2 20 120 10 100 > >>>>>> 3 120 100 100 10 > >>>>>> > >>>>>> /sys/devices/system/node/memory_tiers > >>>>>> 0-1 > >>>>>> 2 > >>>>>> 3 > >>>>>> > >>>>>> N_TOPTIER_MEMORY: 0-1 > >>>>>> > >>>>>> > >>>>>> In this case, we want to be able to "skip" the demotion path from Node 1 > >>>>>> to Node 2, > >>>>>> > >>>>>> and make demotion go directely to Node 3 as it is closer, distance wise. > >>>>>> How can > >>>>>> > >>>>>> we accommodate this scenario (or at least not rule it out as future > >>>>>> work) with the > >>>>>> > >>>>>> current RFC? > >>>>> If I remember correctly NUMA distance is hardcoded in SLIT by the > >>>>> firmware, it is supposed to reflect the latency. So I suppose it is > >>>>> the firmware's responsibility to have correct information. And the RFC > >>>>> assumes higher tier memory has better performance than lower tier > >>>>> memory (latency, bandwidth, throughput, etc), so it sounds like a > >>>>> buggy firmware to have lower tier memory with shorter distance than > >>>>> higher tier memory IMHO. > >>>> > >>>> You are correct if you're assuming the topology is all hierarchically > >>>> > >>>> symmetric, but unfortuantely, in real hardware (e.g., my example above) > >>>> > >>>> it is not. The distance/latency between two nodes in the same tier > >>>> > >>>> and a third node, is different. The firmware still provides the correct > >>>> > >>>> latency, but putting a node in a tier is up to the kernel/user, and > >>>> > >>>> is relative: e.g., Node 3 could belong to tier 1 from Node 1's > >>>> > >>>> perspective, but to tier 2 from Node 0's. > >>>> > >>>> > >>>> A more detailed example (building on my previous one) is when having > >>>> > >>>> the GPU connected to a switch: > >>>> > >>>> ---------------------------- > >>>> | Node 2 PMEM | > >>>> ---------------------------- > >>>> ^ > >>>> | > >>>> -------------- -------------- > >>>> | Node 0 | | Node 1 | > >>>> | ------- | | ------- | > >>>> | | DDR | | | | DDR | | > >>>> | ------- | | ------- | > >>>> | CPU | | GPU | > >>>> -------------- -------------- > >>>> | | > >>>> v v > >>>> ---------------------------- > >>>> | Switch | > >>>> ---------------------------- > >>>> | > >>>> v > >>>> -------------------------------------- > >>>> | Node 3 Large mem | > >>>> -------------------------------------- > >>>> > >>>> Here, demoting from Node 1 to Node 3 directly would be faster as > >>>> > >>>> it only has to go through one hub, compared to demoting from Node 1 > >>>> > >>>> to Node 2, where it goes through two hubs. I hope that example > >>>> > >>>> clarifies things a little bit. > >>>> > >>> > >>> Alistair mentioned that we want to consider GPU memory to be expensive > >>> and want to demote from GPU to regular DRAM. In that case for the above > >>> case we should end up with > >>> > >>> > >>> tier 0 - > Node3 > >>> tier 1 -> Node0, Node1 > >>> tier 2 -> Node2 > > > > I'm a little bit confused by the tiering here as I don't think it's > > quite what we want. As pointed out GPU memory is expensive and therefore > > we don't want anything demoting to it. That implies it should be in the > > top tier: > > > > > I didn't look closely at the topology and assumed that Node3 is the GPU > connected to the switch. Hence all the confusion. > > > > tier 0 -> Node1 > > tier 1 -> Node0, Node3 > > tier 2 -> Node2 > > > > Hence: > > > > node 0: allowed=2 > > node 1: allowed=0,3,2 > > node 2: allowed=empty > > node 3: allowed=2 > > looks good to be default and simple. > > > > > Alternatively Node3 could be put in tier 2 which would prevent demotion > > to PMEM via the switch/CPU: > > > > tier 0 -> Node1 > > tier 1 -> Node0 > > tier 2 -> Node2, Node3 > > > > node 0: allowed=2,3 > > node 1: allowed=0,3,2 > > node 2: allowed=empty > > node 3: allowed=empty > > > > and this can be configured via userspace? The per-node tier customization interface that I just mentioned should support such reconfigurations. > > Both of these would be an improvement over the current situation > > upstream, which demotes everything to GPU memory and doesn't support > > demoting from the GPU (meaning reclaim on GPU memory pages everything to > > disk). > > > >>> > >>> Hence > >>> > >>> node 0: allowed=2 > >>> node 1: allowed=2 > >>> node 2: allowed = empty > >>> node 3: allowed = 0-1 , based on fallback order 1, 0 > >> > >> If we have 3 tiers as defined above, then we'd better to have: > >> > >> node 0: allowed = 2 > >> node 1: allowed = 2 > >> node 2: allowed = empty > >> node 3: allowed = 0-2, based on fallback order: 1,0,2 > >> > >> The firmware should provide the node distance values to reflect that > >> PMEM is slowest and should have the largest distance away from node 3. > > > > Right. In my above example firmware would have to provide reasonable > > distance values to ensure optimal fallback order. > > > >>> -aneesh > >>> > >>> >