From nobody Thu May 16 19:01:00 2024 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60587199AD for ; Wed, 20 Mar 2024 06:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710915050; cv=none; b=H9CQ22Za3QwnVAZxVAoLUQXZOKC8vsgOAhM0MR1lJNiH8d3wTM9Bi1ESLvsHDxYwjUclGe6Lh2BN3c2zmbf8V9qVfwQVDjbWqEd+U88VYZjmkRxHTJP5oAWXwqDpmt+Xm9dKP8LGAsk+FAu+qR5uIDFH4f0zrxuZ8X4jKoMt+u8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710915050; c=relaxed/simple; bh=nPM0FNUHl2H8tDvyjY1tnvNPrdJjAxEbdlobBKBsCwA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h54doXgPrw5z2dujzOrn3b/zoRDrEu4YJfa6cGeDOycow8IzEAB43woroM8WspD+AV4uzl7bUEQtN2PUQqnnQFzjGQFUhC4iDOlfmd9tySfvTuMXF428xiVRjpkIx+A3QzZ+Tyvs/I/h4kLVA9JUY1Wp0trjLQ8UqvRFrYterjc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=Y1jHCETP; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="Y1jHCETP" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-789d76ad270so372571785a.0 for ; Tue, 19 Mar 2024 23:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1710915047; x=1711519847; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ERz1B7CkAMP0XI8jiGkcKeihtxJbJIbVUzaDZdJGjjc=; b=Y1jHCETPDe2uR9quEUYumHrIJw9So/1yFUGekPGFNud9YttR9S0Y/7i1wPz/H+tUfU JK6bnGMkIV9LOzSye04K6kMLA/IgcxVZ4rH5ji8r/CuRYfBcvf0XfmgLvUF/9/IFjIr9 yqlkDlTj5v5I7ywXfZeoQ9dvDjgNx6IG0flYwJ0PqXcZQ+/BjQeiAcb3c3t66SCPGDCE CsjfCVlSS3yxCGZPAyAUUGdRtJiExK/1FsXSShDC5o9atGU9rba11S6Qki8cI+Wo593a QWnoJikp7CrTvCTOLlhMazr4JFZrO7NNsN3FJCjcdLx8pQ3Fre811q2v5btubL9A8TuW LsIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710915047; x=1711519847; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ERz1B7CkAMP0XI8jiGkcKeihtxJbJIbVUzaDZdJGjjc=; b=RILO+pWDIOrbKIcQKtOrwHXxgz+oub1czC4KmdCKCsFSLH5qGSodE8saBVNnG6dkRw 1LZkHcVvYWGKxjmt8r4BopDUTxFoNQn+yRTlEckZaVsjcdioz4lILyLwUQthcjPLvQUc 8hbNIZxOhD9CXsJdF3X4hb5SHdQ64Q8yfJ4GlgZ1YD4mcTN0NSQHu540E6eHVk4L59Ex pVp5w9Kd/PPXZA00WRJ8MRDbgGwF+bpaVU1uuqf0DemWxk3F1FZTsejNLqPwlyBOAo+o uDC19+QIADxdelMvvJbZ5cdyfMSee9Rrz9Sr5DeayuDvULfoj/xQMPj/VeMfNlJ9df6c A8XQ== X-Forwarded-Encrypted: i=1; AJvYcCXI/LcbpGRods9ES/7amjxybPdJrM+kwChWIkt5kANTvsx4obHkDU/3gZOg8vwHyoBwbJTEoEW7AD7nBKVWFDUC6YRMvr/1hZ2V5X46 X-Gm-Message-State: AOJu0Yxr1VMnEs7bcLsvmrizg5bKBc4AscCmN6WNXyYp6Y5I1/WMTU0z CyqLd03p6Ig6IZGq1JfY5WKbXUyb5kaSNN0qoCvXYuJY1zHhQXc/yBL7TAL0DUg= X-Google-Smtp-Source: AGHT+IFd61Cf+hhll8BkkKkcQ5sTHn50l75EQClN97QQIN2IQKz/s0QGwRvVZ3WiMi85sO8BQ6K+lw== X-Received: by 2002:a05:620a:1673:b0:789:e1f2:b0f0 with SMTP id d19-20020a05620a167300b00789e1f2b0f0mr993376qko.35.1710915047238; Tue, 19 Mar 2024 23:10:47 -0700 (PDT) Received: from n231-228-171.byted.org ([130.44.215.123]) by smtp.gmail.com with ESMTPSA id r15-20020a05620a03cf00b0078a042376absm2295914qkm.22.2024.03.19.23.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 23:10:47 -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, Hao Xiang Subject: [PATCH v3 1/2] memory tier: dax/kmem: create CPUless memory tiers after obtaining HMAT info Date: Wed, 20 Mar 2024 06:10:39 +0000 Message-Id: <20240320061041.3246828-2-horenchuang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240320061041.3246828-1-horenchuang@bytedance.com> References: <20240320061041.3246828-1-horenchuang@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current implementation treats emulated memory devices, such as CXL1.1 type3 memory, as normal DRAM when they are emulated as normal memory (E820_TYPE_RAM). However, these emulated devices have different characteristics than traditional DRAM, making it important to distinguish them. Thus, we modify the tiered memory initialization process to introduce a delay specifically for CPUless NUMA nodes. This delay ensures that the memory tier initialization for these nodes is deferred until HMAT information is obtained during the boot process. Finally, demotion tables are recalculated at the end. More details: * late_initcall(memory_tier_late_init); Some device drivers may have initialized memory tiers between `memory_tier_init()` and `memory_tier_late_init()`, potentially bringing online memory nodes and configuring memory tiers. They should be excluded in the late init. * Abstract common functions into `mt_find_alloc_memory_type()` Since different memory devices require finding or allocating a memory type, these common steps are abstracted into a single function, `mt_find_alloc_memory_type()`, enhancing code scalability and conciseness. * Handle cases where there is no HMAT when creating memory tiers There is a scenario where a CPUless node does not provide HMAT information. If no HMAT is specified, it falls back to using the default DRAM tier. * Change adist calculation code to use another new lock, `mt_perf_lock`. In the current implementation, iterating through CPUlist nodes requires holding the `memory_tier_lock`. However, `mt_calc_adistance()` will end up trying to acquire the same lock, leading to a potential deadlock. Therefore, we propose introducing a standalone `mt_perf_lock` to protect `default_dram_perf`. This approach not only avoids deadlock but also prevents holding a large lock simultaneously. * Upgrade `set_node_memory_tier` to support additional cases, including default DRAM, late CPUless, and hot-plugged initializations. To cover hot-plugged memory nodes, `mt_calc_adistance()` and `mt_find_alloc_memory_type()` are moved into `set_node_memory_tier()` to handle cases where memtype is not initialized and where HMAT information is available. * Introduce `default_memory_types` for those memory types that are not initialized by device drivers. Because late initialized memory and default DRAM memory need to be managed, a default memory type is created for storing all memory types that are not initialized by device drivers and as a fallback. Signed-off-by: Ho-Ren (Jack) Chuang Signed-off-by: Hao Xiang --- drivers/dax/kmem.c | 13 +---- include/linux/memory-tiers.h | 7 +++ mm/memory-tiers.c | 94 +++++++++++++++++++++++++++++++++--- 3 files changed, 95 insertions(+), 19 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 42ee360cf4e3..de1333aa7b3e 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -55,21 +55,10 @@ static LIST_HEAD(kmem_memory_types); =20 static struct memory_dev_type *kmem_find_alloc_memory_type(int adist) { - bool found =3D false; struct memory_dev_type *mtype; =20 mutex_lock(&kmem_memory_type_lock); - list_for_each_entry(mtype, &kmem_memory_types, list) { - if (mtype->adistance =3D=3D adist) { - found =3D true; - break; - } - } - if (!found) { - mtype =3D alloc_memory_type(adist); - if (!IS_ERR(mtype)) - list_add(&mtype->list, &kmem_memory_types); - } + mtype =3D mt_find_alloc_memory_type(adist, &kmem_memory_types); mutex_unlock(&kmem_memory_type_lock); =20 return mtype; diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 69e781900082..b2135334ac18 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -48,6 +48,8 @@ int mt_calc_adistance(int node, int *adist); int mt_set_default_dram_perf(int nid, struct access_coordinate *perf, const char *source); int mt_perf_to_adistance(struct access_coordinate *perf, int *adist); +struct memory_dev_type *mt_find_alloc_memory_type(int adist, + struct list_head *memory_types); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); @@ -136,5 +138,10 @@ static inline int mt_perf_to_adistance(struct access_c= oordinate *perf, int *adis { return -EIO; } + +struct memory_dev_type *mt_find_alloc_memory_type(int adist, struct list_h= ead *memory_types) +{ + return NULL; +} #endif /* CONFIG_NUMA */ #endif /* _LINUX_MEMORY_TIERS_H */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 0537664620e5..d9b96b21b65a 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -6,6 +6,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -36,6 +37,11 @@ struct node_memory_type_map { =20 static DEFINE_MUTEX(memory_tier_lock); static LIST_HEAD(memory_tiers); +/* + * The list is used to store all memory types that are not created + * by a device driver. + */ +static LIST_HEAD(default_memory_types); static struct node_memory_type_map node_memory_types[MAX_NUMNODES]; struct memory_dev_type *default_dram_type; =20 @@ -505,7 +511,8 @@ static inline void __init_node_memory_type(int node, st= ruct memory_dev_type *mem static struct memory_tier *set_node_memory_tier(int node) { struct memory_tier *memtier; - struct memory_dev_type *memtype; + struct memory_dev_type *memtype, *mtype =3D NULL; + int adist =3D MEMTIER_ADISTANCE_DRAM; pg_data_t *pgdat =3D NODE_DATA(node); =20 =20 @@ -514,7 +521,18 @@ static struct memory_tier *set_node_memory_tier(int no= de) if (!node_state(node, N_MEMORY)) return ERR_PTR(-EINVAL); =20 - __init_node_memory_type(node, default_dram_type); + mt_calc_adistance(node, &adist); + if (adist !=3D MEMTIER_ADISTANCE_DRAM && + node_memory_types[node].memtype =3D=3D NULL) { + mtype =3D mt_find_alloc_memory_type(adist, &default_memory_types); + if (IS_ERR(mtype)) { + mtype =3D default_dram_type; + pr_info("Failed to allocate a memory type. Fall back.\n"); + } + } else + mtype =3D default_dram_type; + + __init_node_memory_type(node, mtype); =20 memtype =3D node_memory_types[node].memtype; node_set(node, memtype->nodes); @@ -623,6 +641,55 @@ void clear_node_memory_type(int node, struct memory_de= v_type *memtype) } EXPORT_SYMBOL_GPL(clear_node_memory_type); =20 +struct memory_dev_type *mt_find_alloc_memory_type(int adist, struct list_h= ead *memory_types) +{ + bool found =3D false; + struct memory_dev_type *mtype; + + list_for_each_entry(mtype, memory_types, list) { + if (mtype->adistance =3D=3D adist) { + found =3D true; + break; + } + } + if (!found) { + mtype =3D alloc_memory_type(adist); + if (!IS_ERR(mtype)) + list_add(&mtype->list, memory_types); + } + + return mtype; +} +EXPORT_SYMBOL_GPL(mt_find_alloc_memory_type); + +/* + * This is invoked via late_initcall() to create + * CPUless memory tiers after HMAT info is ready or + * when there is no HMAT. + */ +static int __init memory_tier_late_init(void) +{ + int nid; + + mutex_lock(&memory_tier_lock); + for_each_node_state(nid, N_MEMORY) + if (!node_state(nid, N_CPU) && + node_memory_types[nid].memtype =3D=3D NULL) + /* + * Some device drivers may have initialized memory tiers + * between `memory_tier_init()` and `memory_tier_late_init()`, + * potentially bringing online memory nodes and + * configuring memory tiers. Exclude them here. + */ + set_node_memory_tier(nid); + + establish_demotion_targets(); + mutex_unlock(&memory_tier_lock); + + return 0; +} +late_initcall(memory_tier_late_init); + static void dump_hmem_attrs(struct access_coordinate *coord, const char *p= refix) { pr_info( @@ -631,12 +698,16 @@ static void dump_hmem_attrs(struct access_coordinate = *coord, const char *prefix) coord->read_bandwidth, coord->write_bandwidth); } =20 +/* + * The lock is used to protect the default_dram_perf. + */ +static DEFINE_MUTEX(mt_perf_lock); int mt_set_default_dram_perf(int nid, struct access_coordinate *perf, const char *source) { int rc =3D 0; =20 - mutex_lock(&memory_tier_lock); + mutex_lock(&mt_perf_lock); if (default_dram_perf_error) { rc =3D -EIO; goto out; @@ -684,7 +755,7 @@ int mt_set_default_dram_perf(int nid, struct access_coo= rdinate *perf, } =20 out: - mutex_unlock(&memory_tier_lock); + mutex_unlock(&mt_perf_lock); return rc; } =20 @@ -700,7 +771,7 @@ int mt_perf_to_adistance(struct access_coordinate *perf= , int *adist) perf->read_bandwidth + perf->write_bandwidth =3D=3D 0) return -EINVAL; =20 - mutex_lock(&memory_tier_lock); + mutex_lock(&mt_perf_lock); /* * The abstract distance of a memory node is in direct proportion to * its memory latency (read + write) and inversely proportional to its @@ -713,7 +784,7 @@ int mt_perf_to_adistance(struct access_coordinate *perf= , int *adist) (default_dram_perf.read_latency + default_dram_perf.write_latency) * (default_dram_perf.read_bandwidth + default_dram_perf.write_bandwidth) / (perf->read_bandwidth + perf->write_bandwidth); - mutex_unlock(&memory_tier_lock); + mutex_unlock(&mt_perf_lock); =20 return 0; } @@ -826,7 +897,8 @@ static int __init memory_tier_init(void) * For now we can have 4 faster memory tiers with smaller adistance * than default DRAM tier. */ - default_dram_type =3D alloc_memory_type(MEMTIER_ADISTANCE_DRAM); + default_dram_type =3D mt_find_alloc_memory_type( + MEMTIER_ADISTANCE_DRAM, &default_memory_types); if (IS_ERR(default_dram_type)) panic("%s() failed to allocate default DRAM tier\n", __func__); =20 @@ -836,6 +908,14 @@ static int __init memory_tier_init(void) * types assigned. */ for_each_node_state(node, N_MEMORY) { + if (!node_state(node, N_CPU)) + /* + * Defer memory tier initialization on CPUless numa nodes. + * These will be initialized after firmware and devices are + * initialized. + */ + continue; + memtier =3D set_node_memory_tier(node); if (IS_ERR(memtier)) /* --=20 Ho-Ren (Jack) Chuang From nobody Thu May 16 19:01:00 2024 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 941761D52C for ; Wed, 20 Mar 2024 06:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710915051; cv=none; b=lFIS8JIn8GcDnYAnZxJzQd0MVIn1f7SnUst01/2tIyhJz1BaNY3EPg0/Is+EIZyUdriIaPm2Aigfh346C4OA6bDGz9QBMeqkkUnsCQAue8UVS+iTTB7Jnj7UqaPWRiopHRJQDggJGMES5JrHSds03bmY3b2AsICBwdwKT/zQuTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710915051; c=relaxed/simple; bh=J8aboBH2NNf/knR7707BomgJdaL1PmX4mVybR7fdxQs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X1NwHg2rGZawHRUNz/iezJaiSlYjVHEHCXARVFXXjMlK34AgkQw0cOGFHA2AhdskSdpYQrlObKzjU3oPW/6KtKzl8dJduBxCZ3VRukKpVYwzSGembomu5VIFSst38mk29LVtmGtj6rMf8ed4/WRqhflEoaxeklV18H8zlkLlGJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=QApSrugh; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="QApSrugh" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-789e2bf854dso273609385a.3 for ; Tue, 19 Mar 2024 23:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1710915048; x=1711519848; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SwGW4X7oulIIcxRnBbYYicnOB+KsMIm/U2BqanKa/fk=; b=QApSrughB8bNRoVI7ESz5xpm7w+O0Rvl6SWYFVjloNX/ZFs9k8RBK4X6mDEKpz4zdk sm9OoPRe/mUSITvsiUH6hwG2i9z55RkN/DWnb8VocsWpXlHMQBJ2TnwkGzu5B9ddEQmk hRPEi7v8AtGUDz6NlRHoWfjIIMOE67fpN35rqljXQOFSgJ4WY04zhIljDslt8AmkZE+J 6l90rr7xUC4ULA8FoRlyEIaFI5Ku1tJZUMGr3l56daicjoduHtCF8a5cnWzTo+pa+zWX w014nvMZh5QKthcZrKaoAZFt1KFqlQ2aCzTa5D8tA5NBxaWthhipIyXh95P0wTW68Bs7 9oaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710915048; x=1711519848; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SwGW4X7oulIIcxRnBbYYicnOB+KsMIm/U2BqanKa/fk=; b=TFD/8kWWIO7LFXkWfQktzGuPfWU+X6KS+bLHPQcDbYTglFFG5spdnswIsiUsYKC86d d7uyFxAt4+pLZ0ZTBp1xgFWkuk8cDU/XORh33ZWwue5SucecRg/jyYip6XB1BuFElY1J PUDx3Eti9eeanDoZaB8Z/Xq2xl3F9wt2ptSPaAyxJZ8hu1WK43ViBeqVmOUYyrfB7Ums nFdTh6MXS/zSMHXcbZSxxa9BblUkepsTSF73E7TsdkIl98KPIQgcCOkEdiN36Xapaso6 WMRlHuaa+Z/9Zjyoz/g6s3uEUUvFf613R0GSmc3sSG80IgDoN7Fevi9pjMymZRLVaJ8K kbqg== X-Forwarded-Encrypted: i=1; AJvYcCUC20WS7t+iR9+6trTkkfFaiiVQ0F+OsaSizYG1rboupmzSUYSurWuBk/rPgz8aiPNvLWgrt7ctPM78iNjhaTypXsQADqAxhfdYWGC3 X-Gm-Message-State: AOJu0YwQwHCCqjFuXcF5tdh8wTz+g4PgAU/PzGxpldi+V8OknebbE3qs 6EvamTVZ1ojChevwKK6jFfk9ltD4giGc1dm36vhIu7+8hsZUfXYfQ41rNHJL35A= X-Google-Smtp-Source: AGHT+IHdkJX6NQs9WDxlJlRWWOdNZMk+MQxYM/ZXt6WuZ6YnuVS9Rv2sdEvJFxxXOqmF9Wn7sJFtAA== X-Received: by 2002:a05:620a:884:b0:78a:4d4:92f1 with SMTP id b4-20020a05620a088400b0078a04d492f1mr4703702qka.72.1710915048681; Tue, 19 Mar 2024 23:10:48 -0700 (PDT) Received: from n231-228-171.byted.org ([130.44.215.123]) by smtp.gmail.com with ESMTPSA id r15-20020a05620a03cf00b0078a042376absm2295914qkm.22.2024.03.19.23.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 23:10:48 -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 v3 2/2] memory tier: dax/kmem: abstract memory types put Date: Wed, 20 Mar 2024 06:10:40 +0000 Message-Id: <20240320061041.3246828-3-horenchuang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240320061041.3246828-1-horenchuang@bytedance.com> References: <20240320061041.3246828-1-horenchuang@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Abstract `kmem_put_memory_types()` into `mt_put_memory_types()` to accommodate various memory types and enhance flexibility, similar to `mt_find_alloc_memory_type()`. Signed-off-by: Ho-Ren (Jack) Chuang --- drivers/dax/kmem.c | 7 +------ include/linux/memory-tiers.h | 6 ++++++ mm/memory-tiers.c | 12 ++++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index de1333aa7b3e..01399e5b53b2 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -66,13 +66,8 @@ static struct memory_dev_type *kmem_find_alloc_memory_ty= pe(int adist) =20 static void kmem_put_memory_types(void) { - struct memory_dev_type *mtype, *mtn; - mutex_lock(&kmem_memory_type_lock); - list_for_each_entry_safe(mtype, mtn, &kmem_memory_types, list) { - list_del(&mtype->list); - put_memory_type(mtype); - } + mt_put_memory_types(&kmem_memory_types); mutex_unlock(&kmem_memory_type_lock); } =20 diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index b2135334ac18..a44c03c2ba3a 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -50,6 +50,7 @@ int mt_set_default_dram_perf(int nid, struct access_coord= inate *perf, int mt_perf_to_adistance(struct access_coordinate *perf, int *adist); struct memory_dev_type *mt_find_alloc_memory_type(int adist, struct list_head *memory_types); +void mt_put_memory_types(struct list_head *memory_types); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); @@ -143,5 +144,10 @@ struct memory_dev_type *mt_find_alloc_memory_type(int = adist, struct list_head *m { return NULL; } + +void mt_put_memory_types(struct list_head *memory_types) +{ + +} #endif /* CONFIG_NUMA */ #endif /* _LINUX_MEMORY_TIERS_H */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index d9b96b21b65a..6246c28546ba 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -662,6 +662,18 @@ struct memory_dev_type *mt_find_alloc_memory_type(int = adist, struct list_head *m } EXPORT_SYMBOL_GPL(mt_find_alloc_memory_type); =20 + +void mt_put_memory_types(struct list_head *memory_types) +{ + struct memory_dev_type *mtype, *mtn; + + list_for_each_entry_safe(mtype, mtn, memory_types, list) { + list_del(&mtype->list); + put_memory_type(mtype); + } +} +EXPORT_SYMBOL_GPL(mt_put_memory_types); + /* * This is invoked via late_initcall() to create * CPUless memory tiers after HMAT info is ready or --=20 Ho-Ren (Jack) Chuang