Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4187661rdb; Thu, 14 Sep 2023 14:48:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1sGRm9DjoTnVb3hPCu3yj2G/P/X0+26u0aHyJl3Tl73Jjt+J89pqMEyU/NESUEZ5GLv0X X-Received: by 2002:a17:902:c10d:b0:1c0:e87e:52ba with SMTP id 13-20020a170902c10d00b001c0e87e52bamr3831851pli.2.1694728104251; Thu, 14 Sep 2023 14:48:24 -0700 (PDT) Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id u1-20020a170902e5c100b001b8904eadb8si2235495plf.460.2023.09.14.14.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 14:48:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OfFVVMk8; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 2EDBA8316EDF; Thu, 14 Sep 2023 10:32:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233045AbjINRcM (ORCPT + 99 others); Thu, 14 Sep 2023 13:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239402AbjINRcK (ORCPT ); Thu, 14 Sep 2023 13:32:10 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7BFA2102 for ; Thu, 14 Sep 2023 10:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694712726; x=1726248726; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=7Xk0zT0EziXnUTiT2gf/zH3/Ph3X0ew0dMKDe5fFlnE=; b=OfFVVMk88BDKh5Sy8Ft9cBKVpWL0n+s6P66Ap615N5f+Dx8z6UKz9dsf u2DUBVDQgGGiSic6lqhYzlbtLfi8+sdRCwMNk0VnrVU8kx5yoJzoI9nSY YyS3HtnUCw8JnFkAd/AgbVu5q/1GEhp+wgRNkWenvysZOSAnF3kJyuwrX GHbwBH9X225gpPvqoDYN7zau3uK/0JXCirpiXSCdm9LsEW3hTCSWZzYpM WZNf5pBcxAru851PcegP/FhztwqOAIfTeMbL4nRxgVXwR6g+8hG208GEw QOjLDv99RpSW8v76XeEfZ1h5R2YnGKlf+qW5g/NpwiAYfWMvxwsVDV+3E w==; X-IronPort-AV: E=McAfee;i="6600,9927,10833"; a="376359904" X-IronPort-AV: E=Sophos;i="6.02,146,1688454000"; d="scan'208";a="376359904" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2023 10:31:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10833"; a="887898715" X-IronPort-AV: E=Sophos;i="6.02,146,1688454000"; d="scan'208";a="887898715" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 14 Sep 2023 10:31:19 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Thu, 14 Sep 2023 10:31:50 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Thu, 14 Sep 2023 10:31:50 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32 via Frontend Transport; Thu, 14 Sep 2023 10:31:50 -0700 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.173) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.32; Thu, 14 Sep 2023 10:31:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y299hhri+xoHvfAc9YHCtYF6wF0HnWdTcMixm7tlCYStxv8FZhYg90VTm2/32m9ezEWoQdaC0O6sv3bqrUVFi4zl1bRTNVF+n/l5BVK73TumRomZ3fGhTD1QsXcgUs4xgvPZdEPDIWcXL75k2n0TGUzu6zkrCKFZ89u3flwYAm/qM+FWo7mrgu90kuy85b3c0FTE53GSGWMa19jakb5LyfvQpoE6s31iauaWiTCItVjIFgRy9e9XY0x1Xu7NFpvOtXe+6QJ98O8VyFaC6U7LmtSGkkqXzwHe1xUhjQU5KBTXbecVj7WBzCxJc08cKvUuw2n1g4Kg+G4KcBJHtNuk/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6ERpHi3/xgaP15u8zoA7RT/n4IxdBKg5jXgVI9tL+24=; b=WfafXwKl3PzVDwQmkc73TBiyS6Zp+9remaMos223E9ahze/Ez7VrzgszxPuhamJBoeG+0vFQ6ySmDAmxbpo49FN1ZRRul27PA4w/1M56C6HA6yjZtzSgBf+Btuz2cZ6hb7HJoratXhsFVkqYVX98fGOdwu1VzcojEYt9fqKwAPScozzVl4aV4R6IZEMM8nUSv2RyRAUJBsedqIH1Exb27NNX4awCJz2+yBeuIQyfGxHELZ+LR35eFwmmwEQzmVL2TlSI5R3mXZdZBT9Tmpjyjcw/NsoW2CtOJzxG+Pvx7eE6vnc+zGjupgXbNSPxtkGQVMYhUULWpGsj0VVMoI0zuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from PH7PR11MB5984.namprd11.prod.outlook.com (2603:10b6:510:1e3::15) by PH7PR11MB6476.namprd11.prod.outlook.com (2603:10b6:510:1f0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20; Thu, 14 Sep 2023 17:31:47 +0000 Received: from PH7PR11MB5984.namprd11.prod.outlook.com ([fe80::9563:9642:bbde:293f]) by PH7PR11MB5984.namprd11.prod.outlook.com ([fe80::9563:9642:bbde:293f%7]) with mapi id 15.20.6768.029; Thu, 14 Sep 2023 17:31:46 +0000 Message-ID: Date: Thu, 14 Sep 2023 10:31:42 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Betterbird/102.13.0 Subject: Re: [PATCH -V3 4/4] dax, kmem: calculate abstract distance with general interface To: Huang Ying , Andrew Morton CC: , , Bharata B Rao , "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 References: <20230912082101.342002-1-ying.huang@intel.com> <20230912082101.342002-5-ying.huang@intel.com> Content-Language: en-US From: Dave Jiang In-Reply-To: <20230912082101.342002-5-ying.huang@intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BY5PR03CA0008.namprd03.prod.outlook.com (2603:10b6:a03:1e0::18) To PH7PR11MB5984.namprd11.prod.outlook.com (2603:10b6:510:1e3::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR11MB5984:EE_|PH7PR11MB6476:EE_ X-MS-Office365-Filtering-Correlation-Id: 392843a1-8f5a-4971-26c4-08dbb5487871 X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aOsHzH6q1DAbb8OqgRl/Ccp2XWNY7vqRNWr5gtxbiupANeZZ2feuzqSH2x2/Nos9H3XoJO8EJ4r0BGbp0xSY/gHZ2GEu9j+7nnADpeCcnZvnf8Rpzmxv2jY+oRFbry6i8fb9ABciminPJ6LiKGozx8ayEQYAhyCVfUPabbJ4D9lwxORpR6z2fOhkbNpiprsk1714t2LAIuJo7fkvUdXE0Nh1esCld6ntKWPDTHftO/2p6697/UGGObuDgzhyEtsYVm/X8bSwXuOqkQwDSlbpiu5YSV9+ZF/om8eUIrFhxl/uBFs32B/H3JKHVNQsIsbSX2/t8hQ0S8dewE20eEMyojN0e1yMfLF1RL5y/2afv8L2wdyK1eug9I/ilIocpRVPHqR/WJ+YnyaSmo3mPBHZxuv6cC83mdH4PdZ0AUFvre4JJLhh011GGYDiVQ/lq9FGBIyvmU4ahDw/9U2oDq7gHaCWyclop5E4CAgncwUE3x6HCz+VGvYx8rwu4yd5UC0dlBAYdEPlduWQhF92ECcRS2Bw+mgj5J1Ry8GUnHbJDk3bclutpUPzp/l6DZcpk5FQmotn2dJdwi/Ey8jKIZbas4XFBqbc7lpE4zMV3RlhhPHrZV8i3AJbU04y8HWm+7cxaC1cnCUS6y1KcnYURC/Tbw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR11MB5984.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(366004)(39860400002)(346002)(396003)(136003)(186009)(451199024)(1800799009)(7416002)(2906002)(36756003)(86362001)(38100700002)(31696002)(82960400001)(8676002)(4326008)(8936002)(2616005)(66946007)(5660300002)(26005)(31686004)(53546011)(107886003)(6486002)(6506007)(66476007)(66556008)(54906003)(110136005)(316002)(6512007)(6666004)(41300700001)(478600001)(83380400001)(44832011)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?NUpiaXVJWTZVZ0NKVC9xOVZEMGlWVUlPSURhYStRMENKNWo1d1ZjNzZsaDdG?= =?utf-8?B?aW5NUVErd3AxYjRLUklRbG9IQUc4citheUtZN1hyWng0dzNRSG53YmRieVEy?= =?utf-8?B?SHJ5N2Eyc0t2UXVHc3VRR2RSb3lYM1dRUTRXSDNTR3I3ampUWjQ3ZE41eDZS?= =?utf-8?B?OW96MXM5SkQ3Y1VPYzFvcUh3Uk10UEp2OFVhdjIwcDlxeXpPZ0hGZGFJeFpz?= =?utf-8?B?Nkk1bS82aGZqRE9XSkhzVnBuSXlwbkMyakw1MlJPYVlCcWk1b0lMUTVYQXpV?= =?utf-8?B?bVFHWGlpcW9IK0tnaEpibCt6TUh2bHlLTHAyamEzMVlQSlVNZnJxN3dpVnIz?= =?utf-8?B?YzVt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21GOVo0em94SVBYNkdlUWdB?= =?utf-8?B?Znc9PQ==?= X-MS-Exchange-CrossTenant-Network-Message-Id: 392843a1-8f5a-4971-26c4-08dbb5487871 X-MS-Exchange-CrossTenant-AuthSource: PH7PR11MB5984.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2023 17:31:46.7623 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ASmN57I54iqk9GIJcbn8lQGDoRg/ZuEdtbLwCZATtDKS4GMnRFBZB2NW8f5K5HucC4jIjlsoCxkgmkBrGbJGbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6476 X-OriginatorOrg: intel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 10:32:26 -0700 (PDT) X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email On 9/12/23 01:21, Huang Ying wrote: > 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" > Tested-by: Bharata B Rao > 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: Dave Jiang > Cc: Rafael J Wysocki Reviewed-by: Dave Jiang > --- > drivers/dax/kmem.c | 62 ++++++++++++++++++++++++++++-------- > include/linux/memory-tiers.h | 2 ++ > mm/memory-tiers.c | 2 +- > 3 files changed, 52 insertions(+), 14 deletions(-) > > diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c > index c57acb73e3db..369c698b7706 100644 > --- a/drivers/dax/kmem.c > +++ b/drivers/dax/kmem.c > @@ -49,14 +49,52 @@ 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_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); > + } > + mutex_unlock(&kmem_memory_type_lock); > + > + return mtype; > +} > + > +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); > + } > + mutex_unlock(&kmem_memory_type_lock); > +} > + > 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 +109,11 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) > return -EINVAL; > } > > + mt_calc_adistance(numa_node, &adist); > + mtype = kmem_find_alloc_memory_type(adist); > + if (IS_ERR(mtype)) > + return PTR_ERR(mtype); > + > for (i = 0; i < dev_dax->nr_range; i++) { > struct range range; > > @@ -88,7 +131,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 +210,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 +262,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 +294,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,8 +301,7 @@ static int __init dax_kmem_init(void) > return rc; > > error_dax_driver: > - put_memory_type(dax_slowmem_type); > -err_dax_slowmem_type: > + kmem_put_memory_types(); > kfree_const(kmem_name); > return rc; > } > @@ -275,7 +311,7 @@ static void __exit dax_kmem_exit(void) > dax_driver_unregister(&device_dax_kmem_driver); > if (!any_hotremove_failed) > kfree_const(kmem_name); > - put_memory_type(dax_slowmem_type); > + kmem_put_memory_types(); > } > > MODULE_AUTHOR("Intel Corporation"); > diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h > index 9d27ca3b143e..ab6651402d7e 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 fa1a8b418f9a..ca68ef17554b 100644 > --- a/mm/memory-tiers.c > +++ b/mm/memory-tiers.c > @@ -586,7 +586,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,