Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2751850rwb; Fri, 11 Nov 2022 14:20:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf5E74nOXqjaPHoLjF5Juk2yjE2CbS4v0ZwckMW4WmAFlRjEG9JUNGArhhSMGqevYILZInzH X-Received: by 2002:a17:90a:ee94:b0:214:28d5:b2e0 with SMTP id i20-20020a17090aee9400b0021428d5b2e0mr3876746pjz.218.1668205207307; Fri, 11 Nov 2022 14:20:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668205207; cv=none; d=google.com; s=arc-20160816; b=YBScgCAjMRZPaUQhCK08/ugPNILIlfp5hwu4ofT+W4w9m+F7vrtCc2UKhWLTA4YsAP 7VHGoZADA7VzBrAbfF+70lFCC7NEIcilHTOBuL12nJHIGjhJLSuMj9Usdpd7s2tLbYU2 ENer2+A3Fm+myPzBTSF+VfF5y8Vskx5KCcYuyGiV5dDT+6j2o07A03AgNAfjwpun8Mlq OIODgoJUByqlFGRYYKjfZSYdRka6mrSdNf8gBW0aCqCyp6hwTPYmT3kvA9wp2PiSlVZT Kdh63g65FH8OI8mLcfEyBYVQCeR7457YhE/tu/bKbgVK8mQO9IpU+Olgteebdxnt+OQf JebA== 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=FBLvh8HDrSTVyJY825uCLCQg+DtN/s4Hedrzyz0sKsQ=; b=yTLbI3jsluLCq+ClndLttjNd2ysNMZS69T2OuzMDnBTHJEI5Xb+RtHVi+zVq7lGmuE Xoi5S0ZouWMjLGePfsB0IeVc58hLZbQen4RZEZzY/cz8h/FUDbP6lvozF3zl/3x0b1H/ Ljxq1crMvp8B/xnokM6C9CzFyjyZT2y9xN12WWwK1fUQhBhX4sjtALxKXQST3NgK88Ud ytX3QMLSMqX2q6+HTdD6EcJOa/TaqkyDGTaQ09tBxsL9BfKZSkzMreSOrqpoV6xCfM7t sLACbI/0wsvBTF3Pt7IdKVN6m4cbAfrUHOPrkhD637bHLfaJziwF7JRQJmljRZGcWXHc Gs4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qRUpMGjO; 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 n12-20020a170902e54c00b00186c56d9829si4178135plf.328.2022.11.11.14.19.55; Fri, 11 Nov 2022 14:20:07 -0800 (PST) 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=qRUpMGjO; 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 S232918AbiKKVzN (ORCPT + 90 others); Fri, 11 Nov 2022 16:55:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbiKKVzL (ORCPT ); Fri, 11 Nov 2022 16:55:11 -0500 Received: from mail-vk1-xa32.google.com (mail-vk1-xa32.google.com [IPv6:2607:f8b0:4864:20::a32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F68419C31 for ; Fri, 11 Nov 2022 13:55:10 -0800 (PST) Received: by mail-vk1-xa32.google.com with SMTP id g4so2391113vkk.6 for ; Fri, 11 Nov 2022 13:55:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FBLvh8HDrSTVyJY825uCLCQg+DtN/s4Hedrzyz0sKsQ=; b=qRUpMGjO41oswo0eWuEJnL4lA6NTT3EottV/MKOhv1tfm/fvdBrbl39qD6To/pMojR IwOBWiSNm7tAIA4WarulF7NmnuUTnSQlYsVRd+fJJuwyIVVv09kapCofm75y04VBq8mk NcITIDrEsTVstEUdOc6P1N9ujcKvGH7WtxppnDUYH8jfs0HonyGc9freox75/pgD0Yjd c3aYqH6tbuXg5y7bssFWlZnSPDGYJk3pVMDsNJN0fbqJXKjcPrnt3iHCEtjqMaUU/PFz rT3+NWDi9DWgY2SP04fOx8pSp9qR3pi1fhEuNKxivQdoLtdmNmTjlbeMsrXPhDKgJ1rR 30ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FBLvh8HDrSTVyJY825uCLCQg+DtN/s4Hedrzyz0sKsQ=; b=aOko2C+G9bDDWn04/82ByWRrYoKCNbtQXGhsEXAMtONO4K8LYkc85mMa54l9S8Wp9E b5PGjclpAklaVpOVETM5q/w1P3iVBYxGH3mib+rYN8vR6s8RjshkoJjUw3+DYZZpmRl/ vFQ1f0CNCwyMnTp4kg0FIdIs0qxM7Ulta5ItVaUCFnZo0yMX9S76MWdyrT/3lTBFskNM N7U5ASnVEv1/2HKfk8yfcaYmJ3pikfN3c+MLdYgh6h1z+fODrIHRi59f1WyLWrX4wnVX V+vRg0Uy1Bm+JRMid5RiEz8j4vMI2t+Wc2saUXpmWvx6IEU01l7bZgKufZ/BrWIYNBZT 2yFQ== X-Gm-Message-State: ANoB5pmAC4J+Nw4lMftetlzw7GLume2M5O+N70Va52Xn9YsVdJkRfr8B QBHG4ysm5jKTFUwvoCZ9PWHrPbg0krDA9a+M6Mto5w== X-Received: by 2002:a05:6122:852:b0:3b8:68cc:1d1d with SMTP id 18-20020a056122085200b003b868cc1d1dmr2098111vkk.14.1668203709387; Fri, 11 Nov 2022 13:55:09 -0800 (PST) MIME-Version: 1.0 References: <20221017171118.1588820-1-sammler@google.com> <6359ab83d6e4d_4da3294d0@dwillia2-xfh.jf.intel.com.notmuch> In-Reply-To: <6359ab83d6e4d_4da3294d0@dwillia2-xfh.jf.intel.com.notmuch> From: Mina Almasry Date: Fri, 11 Nov 2022 13:54:58 -0800 Message-ID: Subject: Re: [PATCH v1] virtio_pmem: populate numa information To: Dan Williams Cc: Pankaj Gupta , Michael Sammler , Vishal Verma , Dave Jiang , Ira Weiny , Pasha Tatashin , nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org 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, 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, Oct 26, 2022 at 2:50 PM Dan Williams wrote: > > Pankaj Gupta wrote: > > > > > Compute the numa information for a virtio_pmem device from the memory > > > > > range of the device. Previously, the target_node was always 0 since > > > > > the ndr_desc.target_node field was never explicitly set. The code for > > > > > computing the numa node is taken from cxl_pmem_region_probe in > > > > > drivers/cxl/pmem.c. > > > > > > > > > > Signed-off-by: Michael Sammler Tested-by: Mina Almasry I don't have much expertise on this driver, but with the help of this patch I was able to get memory tiering [1] emulation going on qemu. As far as I know there is no alternative to this emulation, and so I would love to see this or equivalent merged, if possible. This is what I have going to get memory tiering emulation: In qemu, added these configs: -object memory-backend-file,id=m4,share=on,mem-path="$path_to_virtio_pmem_file",size=2G \ -smp 2,sockets=2,maxcpus=2 \ -numa node,nodeid=0,memdev=m0 \ -numa node,nodeid=1,memdev=m1 \ -numa node,nodeid=2,memdev=m2,initiator=0 \ -numa node,nodeid=3,initiator=0 \ -device virtio-pmem-pci,memdev=m4,id=nvdimm1 \ On boot, ran these commands: ndctl_static create-namespace -e namespace0.0 -m devdax -f 1&> /dev/null echo dax0.0 > /sys/bus/dax/drivers/device_dax/unbind echo dax0.0 > /sys/bus/dax/drivers/kmem/new_id for i in `ls /sys/devices/system/memory/`; do state=$(cat "/sys/devices/system/memory/$i/state" 2&>/dev/null) if [ "$state" == "offline" ]; then echo online_movable > "/sys/devices/system/memory/$i/state" fi done Without this CL, I see the memory onlined in node 0 always, and is not a separate memory tier. With this CL and qemu configs, the memory is onlined in node 3 and is set as a separate memory tier, which enables qemu-based development: ==> /sys/devices/virtual/memory_tiering/memory_tier22/nodelist <== 3 ==> /sys/devices/virtual/memory_tiering/memory_tier4/nodelist <== 0-2 AFAIK there is no alternative to enabling memory tiering emulation in qemu, and would love to see this or equivalent merged, if possible. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers > > > > > --- > > > > > drivers/nvdimm/virtio_pmem.c | 11 +++++++++-- > > > > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/drivers/nvdimm/virtio_pmem.c b/drivers/nvdimm/virtio_pmem.c > > > > > index 20da455d2ef6..a92eb172f0e7 100644 > > > > > --- a/drivers/nvdimm/virtio_pmem.c > > > > > +++ b/drivers/nvdimm/virtio_pmem.c > > > > > @@ -32,7 +32,6 @@ static int init_vq(struct virtio_pmem *vpmem) > > > > > static int virtio_pmem_probe(struct virtio_device *vdev) > > > > > { > > > > > struct nd_region_desc ndr_desc = {}; > > > > > - int nid = dev_to_node(&vdev->dev); > > > > > struct nd_region *nd_region; > > > > > struct virtio_pmem *vpmem; > > > > > struct resource res; > > > > > @@ -79,7 +78,15 @@ static int virtio_pmem_probe(struct virtio_device *vdev) > > > > > dev_set_drvdata(&vdev->dev, vpmem->nvdimm_bus); > > > > > > > > > > ndr_desc.res = &res; > > > > > - ndr_desc.numa_node = nid; > > > > > + > > > > > + ndr_desc.numa_node = memory_add_physaddr_to_nid(res.start); > > > > > + ndr_desc.target_node = phys_to_target_node(res.start); > > > > > + if (ndr_desc.target_node == NUMA_NO_NODE) { > > > > > + ndr_desc.target_node = ndr_desc.numa_node; > > > > > + dev_dbg(&vdev->dev, "changing target node from %d to %d", > > > > > + NUMA_NO_NODE, ndr_desc.target_node); > > > > > + } > > > > > > > > As this memory later gets hotplugged using "devm_memremap_pages". I don't > > > > see if 'target_node' is used for fsdax case? > > > > > > > > It seems to me "target_node" is used mainly for volatile range above > > > > persistent memory ( e.g kmem driver?). > > > > > > > I am not sure if 'target_node' is used in the fsdax case, but it is > > > indeed used by the devdax/kmem driver when hotplugging the memory (see > > > 'dev_dax_kmem_probe' and '__dax_pmem_probe'). > > > > Yes, but not currently for FS_DAX iiuc. > > The target_node is only used by the dax_kmem driver. In the FSDAX case > the memory (persistent or otherwise) is mapped behind a block-device. > That block-device has affinity to a CPU initiator, but that memory does > not itself have any NUMA affinity or identity as a target. > > So: > > block-device NUMA node == closest CPU initiator node to the device > > dax-device target node == memory only NUMA node target, after onlining