From patchwork Wed Mar 27 07:27:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ho-Ren (Jack) Chuang" X-Patchwork-Id: 13605709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36676C47DD9 for ; Wed, 27 Mar 2024 07:27:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C10846B0099; Wed, 27 Mar 2024 03:27:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC0A76B009B; Wed, 27 Mar 2024 03:27:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A614A6B009C; Wed, 27 Mar 2024 03:27:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 979A66B0099 for ; Wed, 27 Mar 2024 03:27:35 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5BCBEA0F25 for ; Wed, 27 Mar 2024 07:27:35 +0000 (UTC) X-FDA: 81941988870.24.C480AFA Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by imf18.hostedemail.com (Postfix) with ESMTP id B735F1C000B for ; Wed, 27 Mar 2024 07:27:32 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=eqtdUI5Y; spf=pass (imf18.hostedemail.com: domain of horenchuang@bytedance.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=horenchuang@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711524453; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=IldNgoyaPcCzFmZ/bstRqOq1SS9MI1jIO9UfiXXSAU4=; b=GiOAqZICxQ8x15aev7KeO0ejElJ7EWY2FQ5I2NmeM72NGbS1FFR+o5RxTCdanMv27jA3OV KrXrvGWbEuzxCIGJCcL0cxeM8kl9y6UBQUv85zkFi5T6S8qpyk4nnaFjlUt3Ye3Mg6rNV+ 7Iyh9fkKm1mih3zLmol71mQLaf5QOJk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711524453; a=rsa-sha256; cv=none; b=28Bx50I6w34DC5icw6s2wlrTbeKD8xV9DGYpSVMEtYz8oyAAKQIbqQnwt/0zNeUqmiZqAl UfM0etNXTwRZvxRKLu4To9xm9idZgGL+3sHBy7qtxmn3t6a4g31GhA0STaYGaKjx/Q4AFN vnq6Wp2HDLMhCtIjLgIWKhNaqEJugY4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=eqtdUI5Y; spf=pass (imf18.hostedemail.com: domain of horenchuang@bytedance.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=horenchuang@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-430a7497700so42498611cf.1 for ; Wed, 27 Mar 2024 00:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1711524451; x=1712129251; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IldNgoyaPcCzFmZ/bstRqOq1SS9MI1jIO9UfiXXSAU4=; b=eqtdUI5Y/23HT9jZp1wwHqMUQQyQLJhEJDDnxTff8D8QkGBWldrf95ZssUJqcgYR1l E+61BJMUqL5FKCRkcBKaj6f7Ga3k5vvq+zvozAh6XMaZMzmj/XTv6bDbK7Hmu1P3HPYj XqA+uikviTBiSzqz4Yr0UKSB3XMa4J36gFN4wXki36rXKBgSqvFTz99JCBteYlQaikLB A+nzt7/sxl+EyszRiwYiELPhRXTKBP4R0cuwlz7JIrBwxtpnNI5XW1jA2da2ixn0/Ipj eqR1/Iei1cLCYeBQakCpi0XPqSvLyehpkUvrBfGxGX0ZG+inz/Y0txZVi/3YmarGGcJr BFJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711524451; x=1712129251; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IldNgoyaPcCzFmZ/bstRqOq1SS9MI1jIO9UfiXXSAU4=; b=R6R+90SEEc+D7q3cvRwtTQVCDbs1FkbPdluiE1npSKUXgOjQluOeSwx20xV1NkyT1y lpmWglVrW6ZrTsQALQf0J7osrxq8EF/JTOlApQbMVTcHJiJp0IVT4+Kbm9LyZGeBgDHi f/4+IiZ4RgIGEXjRdG3rcBk5rqbZ3RqhjReaP4W3wV5rnsQ716aVB4ZFLulZn44jcO4Y 4PMMIW6CglKbzPgZnsrYJ3NDXzqDgt5t3m+owl+FJ9JwTwNna6If3OBxOWXxGjRugBPZ gfzbtFveE+Vk0bdo2RA1YCL4D1riRj50wLuT1xWxBuN1dxtn/OWoH+3iumAUahxu3Y6b hdDg== X-Forwarded-Encrypted: i=1; AJvYcCUItiQdUxT4lfTMMvYcuuMn7KWYzHdbvTtZ6rG1FKvRXHurO+NR4D2xBsIPpWO79ArUsCwsIT7s9ZOzaLpfFNnh2JY= X-Gm-Message-State: AOJu0YzhYF4y5eSbnuWZfdwlGOZXTRjMhXeM/rAMhlKTwCmWR8sb2DUl ItFU//q1CqKdC0wNucUMN3UXkkL9iV2xCa/qyqXuidGkwIAPWx3ouztD+PAkIkU= X-Google-Smtp-Source: AGHT+IGtqBvkGEFUH7xveuxcSGh3Y9WoJxG4fW6RKgQd9gCeDvnBocFndsK1ZVijAA2duJEKfAsBiA== X-Received: by 2002:ac8:7f8e:0:b0:431:5f0e:bfa9 with SMTP id z14-20020ac87f8e000000b004315f0ebfa9mr5633221qtj.34.1711524451618; Wed, 27 Mar 2024 00:27:31 -0700 (PDT) Received: from n231-228-171.byted.org ([130.44.212.102]) by smtp.gmail.com with ESMTPSA id bq15-20020a05622a1c0f00b00431604af3c1sm2383555qtb.20.2024.03.27.00.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 00:27:31 -0700 (PDT) From: "Ho-Ren (Jack) Chuang" To: "Huang, Ying" , "Gregory Price" , aneesh.kumar@linux.ibm.com, mhocko@suse.com, tj@kernel.org, john@jagalactic.com, "Eishan Mirakhur" , "Vinicius Tavares Petrucci" , "Ravis OpenSrc" , "Alistair Popple" , "Srinivasulu Thanneeru" , Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: "Ho-Ren (Jack) Chuang" , "Ho-Ren (Jack) Chuang" , "Ho-Ren (Jack) Chuang" , qemu-devel@nongnu.org Subject: [PATCH v6 0/2] Improved Memory Tier Creation for CPUless NUMA Nodes Date: Wed, 27 Mar 2024 07:27:26 +0000 Message-Id: <20240327072729.3381685-1-horenchuang@bytedance.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Stat-Signature: sop8rsrp1gw19qsdydjgajp8d7183kj6 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B735F1C000B X-Rspam-User: X-HE-Tag: 1711524452-742503 X-HE-Meta: U2FsdGVkX189YRc/F1gcBOuDsT08cZvF2xf1vzwRQrmS3O0wwOuWe/PVdmuRqIWIVa+OzU6yXeYgwh/LPMGId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wKFnHoYxB//yMpGLRKv7N8xkxgQtuXRi8ZJog56cF5/growY2HI6AcissI3LTJqWF0MrwSNOgRtbvmEbW5XvQsP39fvMDOrnFwyaoG7CoyLpEY53zToO7b2f80X0pjqX/stEHy581tITQRxhG9ADUnyCG6F9KkVmhjgUKD5bNGXiL+Y1xb5yh4kiErFPFx9jbeStPRxuCVDWNhMTueJmFE02pr8LRB2//+1/DIjahJzpzWcifCdyUupmb5OVMDEzMgIX09OjsKl0FY3VqQqX8zJx+u8xYX8HYYs8NI3UUBp3vdz3O3prvTb/qC8qZ751at/ukGaifBo/Nj11WHdlh80V+EceBfQ5a+roRNjE6U1+pzdk7CNL+CM1u6L7lAC6s3PPEkDwVVujdyBh1g6jiCjF/ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When a memory device, such as CXL1.1 type3 memory, is emulated as normal memory (E820_TYPE_RAM), the memory device is indistinguishable from normal DRAM in terms of memory tiering with the current implementation. The current memory tiering assigns all detected normal memory nodes to the same DRAM tier. This results in normal memory devices with different attributions being unable to be assigned to the correct memory tier, leading to the inability to migrate pages between different types of memory. https://lore.kernel.org/linux-mm/PH0PR08MB7955E9F08CCB64F23963B5C3A860A@PH0PR08MB7955.namprd08.prod.outlook.com/T/ This patchset automatically resolves the issues. It delays the initialization of memory tiers for CPUless NUMA nodes until they obtain HMAT information and after all devices are initialized at boot time, eliminating the need for user intervention. If no HMAT is specified, it falls back to using `default_dram_type`. Example usecase: We have CXL memory on the host, and we create VMs with a new system memory device backed by host CXL memory. We inject CXL memory performance attributes through QEMU, and the guest now sees memory nodes with performance attributes in HMAT. With this change, we enable the guest kernel to construct the correct memory tiering for the memory nodes. -v6: Thanks to Ying's comments, * Move `default_dram_perf_lock` to the function's beginning for clarity * Fix double unlocking at v5 -v5: Thanks to Ying's comments, * Add comments about what is protected by `default_dram_perf_lock` * Fix an uninitialized pointer mtype * Slightly shorten the time holding `default_dram_perf_lock` * Fix a deadlock bug in `mt_perf_to_adistance` * https://lore.kernel.org/lkml/20240327041646.3258110-1-horenchuang@bytedance.com/T/#u -v4: Thanks to Ying's comments, * Remove redundant code * Reorganize patches accordingly * https://lore.kernel.org/lkml/20240322070356.315922-1-horenchuang@bytedance.com/T/#u -v3: Thanks to Ying's comments, * Make the newly added code independent of HMAT * Upgrade set_node_memory_tier to support more cases * Put all non-driver-initialized memory types into default_memory_types instead of using hmat_memory_types * find_alloc_memory_type -> mt_find_alloc_memory_type * https://lore.kernel.org/lkml/20240320061041.3246828-1-horenchuang@bytedance.com/T/#u -v2: Thanks to Ying's comments, * Rewrite cover letter & patch description * Rename functions, don't use _hmat * Abstract common functions into find_alloc_memory_type() * Use the expected way to use set_node_memory_tier instead of modifying it * https://lore.kernel.org/lkml/20240312061729.1997111-1-horenchuang@bytedance.com/T/#u -v1: * https://lore.kernel.org/lkml/20240301082248.3456086-1-horenchuang@bytedance.com/T/#u Ho-Ren (Jack) Chuang (2): memory tier: dax/kmem: introduce an abstract layer for finding, allocating, and putting memory types memory tier: create CPUless memory tiers after obtaining HMAT info drivers/dax/kmem.c | 20 +----- include/linux/memory-tiers.h | 13 ++++ mm/memory-tiers.c | 126 ++++++++++++++++++++++++++++++----- 3 files changed, 125 insertions(+), 34 deletions(-)