From patchwork Wed Jul 12 07:49:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13309694 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 4D296EB64D9 for ; Wed, 12 Jul 2023 07:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB4506B0071; Wed, 12 Jul 2023 03:49:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D653A6B007B; Wed, 12 Jul 2023 03:49:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C36E16B007E; Wed, 12 Jul 2023 03:49:36 -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 B57ED6B007B for ; Wed, 12 Jul 2023 03:49:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 831A71C7C07 for ; Wed, 12 Jul 2023 07:49:36 +0000 (UTC) X-FDA: 81002185152.15.90186CF Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf23.hostedemail.com (Postfix) with ESMTP id 6DFA3140010 for ; Wed, 12 Jul 2023 07:49:34 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=j2Vu5ABt; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf23.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689148174; 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=QV8Teo1j0CFA6btKhSsxBE6pLS/TyY9NOfA3+UQFqbU=; b=m6WYoGYnZKphtDJSSX37BQFQWnrgRH1/kdmrPNzcUsocga1YRqIW2yaqby4GEZBh5Z8CPp dvPY7dKRfjXGUbIsHWXFZyPfnWZ3XA93/UjRJ5mIkOVNZyjCMy34VTwnXAQbIA5RU3Jepf MJ4+9KUjbubyfPsXHAIstwepvr/PcXU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=j2Vu5ABt; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf23.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689148174; a=rsa-sha256; cv=none; b=73G8PnTuxZnVxWntOfDrc1VF8/MBFtdwbs0P4IuwG2hFz1qJxbc6sjvCA74C0TZBa69MNX gSx/lUwVuFoS64tMHV46Ktia+Vza5v4Vz5HSqR9+DwG3sH+6BUm9mqtQvnIRqqaDxhXlye dJtYSaU7TtbdPSDo25A5GtVVZec5DPo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689148174; x=1720684174; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WgH5xLOkBW2Y/oZqJhHhP4ppJv8kSHk1fii5X3wpokk=; b=j2Vu5ABtCQknjfJ9Ox4IzukC7ujq5jzaWSPUPu+/yWVsinkzQR20z5Sl 2pZrkAnBiald3r4/OweZwstyz2uy9OKfzyU0ww3rbqpHS4jiZG6Jx+Bo/ sv8MRLnW+9it49Ga2k2M6hHs68UljTWcBHMlFHwnbMc5j/H1LgSHopoc1 xdhDNRb5MygdgUE4ctzTYf0OAKGFDWyfvLLD3jYkc1rkpSZfnzP5/OGjK bNJ7uA+krCTJhQ3mr1UXR4oUm/3TJYWdt691bmP1MmRr06Z18Kh9B18zz UITR42DC1m/0tw4U43jX4je0FAiCdDlGToR7z9Z6wNiAi+7zbhxn0h3rw g==; X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="354734625" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="354734625" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10768"; a="698744941" X-IronPort-AV: E=Sophos;i="6.01,199,1684825200"; d="scan'208";a="698744941" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.30]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2023 00:49:28 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , "Aneesh Kumar K . V" , Wei Xu , Alistair Popple , Dan Williams , Dave Hansen , Davidlohr Bueso , Johannes Weiner , Jonathan Cameron , Michal Hocko , Yang Shi , Rafael J Wysocki Subject: [PATCH 4/4] dax, kmem: calculate abstract distance with general interface Date: Wed, 12 Jul 2023 15:49:00 +0800 Message-Id: <20230712074900.404064-5-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230712074900.404064-1-ying.huang@intel.com> References: <20230712074900.404064-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: zsx8absknqpqgjbo7ed1cqmm55hhfp1s X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6DFA3140010 X-HE-Tag: 1689148174-558165 X-HE-Meta: U2FsdGVkX19wX/G9b6ZXQKyxCE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ma2u0yKUQxL52efiTfFwGAVWKaV0/qPA8gTsTi9pWKmzzaWgH3GaNiihRsNGZF0MoSYpDuQ3caGdP3cwzZ9tX1xQcAMLcTYLVwVSJWymzAD6/phM9A2K7qawwdBV8+brxC2nrQ7jXX0X5YKMDbVJw1g0P4BJCeZLY1+PZWDsdNLf9FpRRMSPlTc+XAUKz5+pnXgGTkHn4d8TMFPQTG76wmmBhhcyMLI+/yTrnEdtFj30BwGvqj2jhLDbiDVxKHV+VCaR1kPul9YEWYUtkqVQpVrMmBiEepX976ZHO3OeQGT+VoaIKHdmSIuaq7NGwiClRIK1gZMrfqcccCwWXt0lOup0rFEO/zHA= 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: Previously, a fixed abstract distance MEMTIER_DEFAULT_DAX_ADISTANCE is used for slow memory type in kmem driver. This limits the usage of kmem driver, for example, it cannot be used for HBM (high bandwidth memory). So, we use the general abstract distance calculation mechanism in kmem drivers to get more accurate abstract distance on systems with proper support. The original MEMTIER_DEFAULT_DAX_ADISTANCE is used as fallback only. Now, multiple memory types may be managed by kmem. These memory types are put into the "kmem_memory_types" list and protected by kmem_memory_type_lock. Signed-off-by: "Huang, Ying" Cc: Aneesh Kumar K.V Cc: Wei Xu Cc: Alistair Popple Cc: Dan Williams Cc: Dave Hansen Cc: Davidlohr Bueso Cc: Johannes Weiner Cc: Jonathan Cameron Cc: Michal Hocko Cc: Yang Shi Cc: Rafael J Wysocki --- drivers/dax/kmem.c | 54 +++++++++++++++++++++++++++--------- include/linux/memory-tiers.h | 2 ++ mm/memory-tiers.c | 2 +- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 898ca9505754..837165037231 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -49,14 +49,40 @@ struct dax_kmem_data { struct resource *res[]; }; -static struct memory_dev_type *dax_slowmem_type; +static DEFINE_MUTEX(kmem_memory_type_lock); +static LIST_HEAD(kmem_memory_types); + +static struct memory_dev_type *kmem_find_alloc_memorty_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); + } + mutex_unlock(&kmem_memory_type_lock); + + return mtype; +} + static int dev_dax_kmem_probe(struct dev_dax *dev_dax) { struct device *dev = &dev_dax->dev; unsigned long total_len = 0; struct dax_kmem_data *data; + struct memory_dev_type *mtype; int i, rc, mapped = 0; int numa_node; + int adist = MEMTIER_DEFAULT_DAX_ADISTANCE; /* * Ensure good NUMA information for the persistent memory. @@ -71,6 +97,11 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) return -EINVAL; } + mt_calc_adistance(numa_node, &adist); + mtype = kmem_find_alloc_memorty_type(adist); + if (IS_ERR(mtype)) + return PTR_ERR(mtype); + for (i = 0; i < dev_dax->nr_range; i++) { struct range range; @@ -88,7 +119,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) return -EINVAL; } - init_node_memory_type(numa_node, dax_slowmem_type); + init_node_memory_type(numa_node, mtype); rc = -ENOMEM; data = kzalloc(struct_size(data, res, dev_dax->nr_range), GFP_KERNEL); @@ -167,7 +198,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) err_res_name: kfree(data); err_dax_kmem_data: - clear_node_memory_type(numa_node, dax_slowmem_type); + clear_node_memory_type(numa_node, mtype); return rc; } @@ -219,7 +250,7 @@ static void dev_dax_kmem_remove(struct dev_dax *dev_dax) * for that. This implies this reference will be around * till next reboot. */ - clear_node_memory_type(node, dax_slowmem_type); + clear_node_memory_type(node, NULL); } } #else @@ -251,12 +282,6 @@ static int __init dax_kmem_init(void) if (!kmem_name) return -ENOMEM; - dax_slowmem_type = alloc_memory_type(MEMTIER_DEFAULT_DAX_ADISTANCE); - if (IS_ERR(dax_slowmem_type)) { - rc = PTR_ERR(dax_slowmem_type); - goto err_dax_slowmem_type; - } - rc = dax_driver_register(&device_dax_kmem_driver); if (rc) goto error_dax_driver; @@ -264,18 +289,21 @@ static int __init dax_kmem_init(void) return rc; error_dax_driver: - destroy_memory_type(dax_slowmem_type); -err_dax_slowmem_type: kfree_const(kmem_name); return rc; } static void __exit dax_kmem_exit(void) { + struct memory_dev_type *mtype, *mtn; + dax_driver_unregister(&device_dax_kmem_driver); if (!any_hotremove_failed) kfree_const(kmem_name); - destroy_memory_type(dax_slowmem_type); + list_for_each_entry_safe(mtype, mtn, &kmem_memory_types, list) { + list_del(&mtype->list); + destroy_memory_type(mtype); + } } MODULE_AUTHOR("Intel Corporation"); diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 9377239c8d34..aca22220cb5c 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -24,6 +24,8 @@ struct memory_tier; struct memory_dev_type { /* list of memory types that are part of same tier as this type */ struct list_head tier_sibiling; + /* list of memory types that are managed by one driver */ + struct list_head list; /* abstract distance for this specific memory type */ int adistance; /* Nodes of same abstract distance */ diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 9a734ef2edfb..38005c60fa2d 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -581,7 +581,7 @@ EXPORT_SYMBOL_GPL(init_node_memory_type); void clear_node_memory_type(int node, struct memory_dev_type *memtype) { mutex_lock(&memory_tier_lock); - if (node_memory_types[node].memtype == memtype) + if (node_memory_types[node].memtype == memtype || !memtype) node_memory_types[node].map_count--; /* * If we umapped all the attached devices to this node,