From mboxrd@z Thu Jan 1 00:00:00 1970 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 7E688CD1284 for ; Fri, 29 Mar 2024 00:48:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD5736B0089; Thu, 28 Mar 2024 20:48:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0EEB6B008A; Thu, 28 Mar 2024 20:48:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC2E96B008C; Thu, 28 Mar 2024 20:48:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 90B496B0089 for ; Thu, 28 Mar 2024 20:48:22 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 61604C0FB2 for ; Fri, 29 Mar 2024 00:48:22 +0000 (UTC) X-FDA: 81948240444.17.184143D Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf16.hostedemail.com (Postfix) with ESMTP id 857A918000E for ; Fri, 29 Mar 2024 00:48:20 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=TZhL6RJ1; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf16.hostedemail.com: domain of horenchuang@bytedance.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=horenchuang@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711673300; 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:in-reply-to:references:references:dkim-signature; bh=nM2K0D/X61aNkdsdtPeKZ1y9TeOUsh6nA3RvZQfcaBY=; b=4aZPVKBqi7cG/QpkniaknXumms54gOtMqRjPuT1UtT7DZERB0KRLx5LSXclxlvsm8jhVZa jS6VZydTKDFDVxgASFza/mZjViYG7tcMZivzKasbXLom8ReTyRnmvsWUTwqyWG//UHTcsg pYq07lzWlNYTT25hL8syK2GvKoRJXtk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=TZhL6RJ1; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf16.hostedemail.com: domain of horenchuang@bytedance.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=horenchuang@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711673300; a=rsa-sha256; cv=none; b=Sz6Ue6ILGjmq5oMGm1Dz9BJ9oE9Q3YrV8ZpdICmwvTbez79+c5nGeaGGlc1HUQwE5MTMwE fVDhKDzCG553NAMse05VgTP6sLYvErpogHa8iKFYvPnLV+0XLE6YiPYh1Giu+peDxS4et4 nfwqtMgdYtk7z7i7DA44AbNagPXpjYE= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-dcc80d6004bso1556378276.0 for ; Thu, 28 Mar 2024 17:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1711673299; x=1712278099; darn=kvack.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=nM2K0D/X61aNkdsdtPeKZ1y9TeOUsh6nA3RvZQfcaBY=; b=TZhL6RJ1NEV9P04xWeBe7X49MwRX6XSPfG3xQVtZcG3VBjknLXSnJVOmBj5FCR9iTz 0MeIJQ4w+BSD8g4wswLij1kIFIhB9VHRieAPSgjnXS+i7LsLiUIEmOkWKWdYI4/nYmDd lrEcHT2J7x/L+MRPMIPNe4HKgGumpXouYa973GOhXWbuElOZxxW2aZCcfYjqln/0imdO kFNeWQMjF0aF//0lvg5Jnlh1R6bclfmiKTkqNfWc8vpMwu8Z8Ocy2qgIqw0z8DhrLJDA wR1yIR5ZuC2zzed2tPOGKXsEVPCqhfAAwD3kmSUzd3bx4pO0lIHQOO71VwNTuOO5Iuzm wrYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711673299; x=1712278099; 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=nM2K0D/X61aNkdsdtPeKZ1y9TeOUsh6nA3RvZQfcaBY=; b=EzBO91SjDncU6CdBcrrrKgdsf2Y2+LpCt+kuAMrqTqhNLAGIire0TZVN+LZzpwIS/B L6xOExn19taBoASfXF6rux5tmHTzbDpH2I5hwCh6Ig88Dnoh2F8WzqQsp/tQN0Apb/8K 1YDMR8sntZfyiXrs8cUeO+Ahq+YnD0kohnlp5BvcwDVcXEuPv9Z54eIDI2hZk7zYn0FI S/n4IN9inigluZpQ/xYADW+ESl3ibv+hEB9T76jD4bDqrDuJ0JwGM7jdexI/iFfozBUs bxCgrgMTfbeRpDDdxdVwSga9RLPMD7mBHqedGDRbkhM+hyd/j/k8j8+VjDCJDKDgoFT1 vIsg== X-Forwarded-Encrypted: i=1; AJvYcCUAszcqYe3ph0zwIfJgW58PU+6vYcpJ26MpLT0dWcE1UeOFnJYkIeNUxmFVjb8YGeqe8HTnXOwgm8EXesxKU3T0PhM= X-Gm-Message-State: AOJu0YwOVQ7fc1NC8O4eqmI+bsFnIiUeHMCpZBPZw8/OnSJJ4OFdZ/q6 430yqelB9VTDDHiMPlukbv8bIFcaGDdbZnPEzS2xL2Ya2H+QlG4rZuV4z1xjOPQ= X-Google-Smtp-Source: AGHT+IEWc8MJ8W6U6KVvKlVOAwYm9Oc+qt201hxUZthUjnrGBEx4qZhRjNwiP6o45lr2jPQ2OBCapQ== X-Received: by 2002:a5b:1c1:0:b0:dda:a9f7:4ec2 with SMTP id f1-20020a5b01c1000000b00ddaa9f74ec2mr1063844ybp.56.1711673299513; Thu, 28 Mar 2024 17:48:19 -0700 (PDT) Received: from n231-228-171.byted.org ([130.44.212.125]) by smtp.gmail.com with ESMTPSA id v26-20020ac8749a000000b00430afbb6b50sm1102414qtq.51.2024.03.28.17.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 17:48:19 -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 v8 1/2] memory tier: dax/kmem: introduce an abstract layer for finding, allocating, and putting memory types Date: Fri, 29 Mar 2024 00:48:13 +0000 Message-Id: <20240329004815.195476-2-horenchuang@bytedance.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20240329004815.195476-1-horenchuang@bytedance.com> References: <20240329004815.195476-1-horenchuang@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 857A918000E X-Stat-Signature: gsn981qdmmjoo6eun53hx19ng6pgd4i6 X-HE-Tag: 1711673300-812890 X-HE-Meta: U2FsdGVkX1/oP1A8e3uNwpwQxFfuGaEzYYgoloUpITnf3s6jwWaxAX+VbNnAOA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UoYRlwpF/GrLTpi4KXVQzKy2tUhtenGzqaDsUrBovmJ75GJrpPMEhr4cQJdwj0fPwuveP2rRehO6d6nUWh8uK9OFl/LzMAfusBlNYMS8xXmZV1aIJX1nhpQfuIZX/yWR8lK3x1uVNLXL2t7Ah8Lj2w4jiMnE5S2vPM8UmBpR4AA285X0zXu5MG1bsaI1g73PILBXxPatZLnuba0A19oW9fcR4GggqrhEfOwGJUI9D7oCki+6Ig4CVwO0k1wkjWMgHYNyCTnv 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: Since different memory devices require finding, allocating, and putting memory types, these common steps are abstracted in this patch, enhancing the scalability and conciseness of the code. Signed-off-by: Ho-Ren (Jack) Chuang Reviewed-by: "Huang, Ying" --- drivers/dax/kmem.c | 20 ++------------------ include/linux/memory-tiers.h | 13 +++++++++++++ mm/memory-tiers.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 42ee360cf4e3..01399e5b53b2 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -55,21 +55,10 @@ static LIST_HEAD(kmem_memory_types); static struct memory_dev_type *kmem_find_alloc_memory_type(int adist) { - bool found = false; struct memory_dev_type *mtype; mutex_lock(&kmem_memory_type_lock); - list_for_each_entry(mtype, &kmem_memory_types, list) { - if (mtype->adistance == adist) { - found = true; - break; - } - } - if (!found) { - mtype = alloc_memory_type(adist); - if (!IS_ERR(mtype)) - list_add(&mtype->list, &kmem_memory_types); - } + mtype = mt_find_alloc_memory_type(adist, &kmem_memory_types); mutex_unlock(&kmem_memory_type_lock); return mtype; @@ -77,13 +66,8 @@ static struct memory_dev_type *kmem_find_alloc_memory_type(int adist) 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); } diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 69e781900082..a44c03c2ba3a 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -48,6 +48,9 @@ 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); +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); @@ -136,5 +139,15 @@ static inline int mt_perf_to_adistance(struct access_coordinate *perf, int *adis { return -EIO; } + +struct memory_dev_type *mt_find_alloc_memory_type(int adist, struct list_head *memory_types) +{ + 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 0537664620e5..974af10cfdd8 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -623,6 +623,38 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype) } EXPORT_SYMBOL_GPL(clear_node_memory_type); +struct memory_dev_type *mt_find_alloc_memory_type(int adist, struct list_head *memory_types) +{ + bool found = false; + struct memory_dev_type *mtype; + + list_for_each_entry(mtype, memory_types, list) { + if (mtype->adistance == adist) { + found = true; + break; + } + } + if (!found) { + mtype = alloc_memory_type(adist); + if (!IS_ERR(mtype)) + list_add(&mtype->list, memory_types); + } + + return mtype; +} +EXPORT_SYMBOL_GPL(mt_find_alloc_memory_type); + +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); + static void dump_hmem_attrs(struct access_coordinate *coord, const char *prefix) { pr_info( -- Ho-Ren (Jack) Chuang