Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2221633rwd; Fri, 16 Jun 2023 00:30:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51GDivOUZW2qpe8q+Ep5YZBpd6L5urqcaZ8q2x/TzLEc2Y6qwDnehduMroRW7jDrUUxH7S X-Received: by 2002:a17:902:c651:b0:1b3:e55f:5a4a with SMTP id s17-20020a170902c65100b001b3e55f5a4amr867423pls.54.1686900624691; Fri, 16 Jun 2023 00:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686900624; cv=none; d=google.com; s=arc-20160816; b=Qm6cicn+MgKrDo0t1UeAg38Lfk5JEJLY981kMaNTTnw7wNCJKP8rom0qHU7SK4PYVZ L1Nzd7eNvHjbEDfhzUvj0sBKS1aRrhvtHN8Uaj0UAtOcpHTok062CON/QPBccmV7FpQd Acrg5n6gwjFb061UIzVV4lbZW6ApMnVhdVk2CWrOlXO5UtBkHrPvN0KommwHLsW4r35H xGkg4REyJd6yP82qBbehvj4VtCDD+0PSc/uG6s2x1az0ptwOJG4BJo4k5m0mZBdM22Xk FprfUAM2koGLKfyqWzGnadaL8dmCrt5J6TQojjUIisWxvi2OYrW7NavTBaSg+iVUe66f Q3yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5gIuz0aTjS9U0fh0qkl+B3NT7lwCN2asmsH/d+KsHDc=; b=Vu62g4E9xomPvit1goc6PRy8FyQpPKA4hS7vzhA4S4wZvRNJMqnk08fbHwCdNfAjX/ m7IsYS5ZDYl65sTV0MUKTabxV0gIhWphUZfL3t+m8MFlzayy0l6/t2+5Ne6FofNC9Lvs eYn1V7cTO6843Xt1QejFVYjqnobdRe5uq/O/XJ6woL5sI1TRJ4WKmkaKakBuOHivHkoq b+uePgo9Wg+gkKOTGynSehUbxr72yRahIdM4rnCRGSsMQbI5TkVyyycm2PoRvj/KMu/R my51sRSVUKRRF6JZ2UPbRSDDKHQSi/AHM0uVKp2R79gIo/SAx87EyLBkZf6vIrTe7mNd a8Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DrVHYQVs; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf9-20020a170902b90900b001a9ba4690casi14011010plb.295.2023.06.16.00.30.12; Fri, 16 Jun 2023 00:30:24 -0700 (PDT) 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=@intel.com header.s=Intel header.b=DrVHYQVs; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244582AbjFPHHf (ORCPT + 99 others); Fri, 16 Jun 2023 03:07:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244213AbjFPHG7 (ORCPT ); Fri, 16 Jun 2023 03:06:59 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A47CD35A7 for ; Fri, 16 Jun 2023 00:06:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686899200; x=1718435200; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RTaDfZ9VPFX57fvR1Dzfk2rQNkh7YYvcsGhFjCOwvYY=; b=DrVHYQVsrS9SNvXu1Xu8wOZnOy9U3DrxuL2anlKEpN79UtZXvl+4dq8D zyEArjfMgCFsh8rh3M6FpS2jdklU/2PFvuU04VodKuLkCSliY1tPQUmVR Zuzk5nZmkgjR5nUQ2f+sp4Y/ZaHA5VigCy1qkRSshE6RIe8btdTdebYDB XdgpgxD0boXzzhPLsFiv8Il+O8c4dOewtq3MGLNs1/ab1GROixZBkVVLT 7Xx5aKhuoKuy4AZ0vliuZY92VaAi2qCelgHqC8P+5UNRTgK4fmLTS6u1Z 8YvJqC3UfJUAGcBrixa7Yw5O7SyCpTAKUFby2QTZiObl5PynGuYX1SDOn w==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="361668883" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="361668883" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 00:06:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="782784018" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="782784018" Received: from cpeng15-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.31.216]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 00:06:19 -0700 From: Huang Ying To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , 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: [RFC 4/4] dax, kmem: calculate abstract distance with general interface Date: Fri, 16 Jun 2023 15:05:38 +0800 Message-Id: <20230616070538.190042-5-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230616070538.190042-1-ying.huang@intel.com> References: <20230616070538.190042-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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 7b36db6f1cbd..079f53315562 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 3aabc7240402..8a763a765238 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -582,7 +582,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, -- 2.39.2