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 EF31EEE4996 for ; Mon, 21 Aug 2023 23:35:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3805094001A; Mon, 21 Aug 2023 19:35:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3304994000B; Mon, 21 Aug 2023 19:35:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D1F094001A; Mon, 21 Aug 2023 19:35:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0E59794000B for ; Mon, 21 Aug 2023 19:35:42 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D816FC0144 for ; Mon, 21 Aug 2023 23:35:41 +0000 (UTC) X-FDA: 81149721282.26.372AE16 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf28.hostedemail.com (Postfix) with ESMTP id ACEB5C0010 for ; Mon, 21 Aug 2023 23:35:39 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GRw6AS7i; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 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=1692660940; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FOKzGEJMYYwVaXE4SweRmXtTrsExyntufvzefhq9skg=; b=PUhB+9x04ghZilXb5+aw66dW2IiAj7z2CE8s6oyvnLcKCjUP5r8UQag9d54tLQG92owPY1 8+HC+hmtN9RrvbG+t+lFxQOCntZdDMBtR4io6JHF0KKU1bVxyZelkB8rXMD75KbWp/guMe U2vVbL099nbOpM/rZcJhW+Oc++74R0g= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GRw6AS7i; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf28.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692660940; a=rsa-sha256; cv=none; b=BnG/qHPBW9Nbg9s/0qbqDK/GIBHpRT3Cqg/ZqUdf6h1fGuNiYJ1oNbimh4XsdhQ073M199 OIw8iHGjx/IBF90KMw+6TPKAt0ELhsNN1FciUJw72NMdHsCBC+X/yVMN/FZCjSYe3Dc8xb LtBaWGVNU+n+9utdRHgLqXARVmnF6ms= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692660938; x=1724196938; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=lyG/72iRKaKPXkXbLzVHa9J51DlyHySbY0/hxJRW8/0=; b=GRw6AS7iUm2cl/LL/pmxkuiNWPcIaO+QQ916Gz/NSPZfv36FWPTIPfmU kAyF5S1J6SbK8E2r2UnrLTMqcfZk0daOEi1HB1XXSJoo7WYIaloVrXfeo t05L58z7UjKJhfCwcSbFxwSRHheeXDuV8eEE0sNGrX6FRoUf3UvJt2BVM CQ0K0qlwBld44rde/na9Z5Sj4wyBPcPFqSkyldA8Hsd0DgMJ9/nyWVhKP +DhdLIqfxbt8/AGDnV25FBZP5+GSA2w6Hc7ce53VBqmSFpVXrHIPOI3bs xL4t7J/P1mNPJZo0NXlKgGt9Y2wLTvKKulQXUtH4n9zQD/04cFZO6wh4a g==; X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="440097318" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="440097318" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:35:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="850368628" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="850368628" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 16:35:33 -0700 From: "Huang, Ying" To: Alistair Popple Cc: Andrew Morton , , , , , , "Aneesh Kumar K . V" , Wei Xu , Dan Williams , Dave Hansen , "Davidlohr Bueso" , Johannes Weiner , "Jonathan Cameron" , Michal Hocko , Yang Shi , Rafael J Wysocki Subject: Re: [PATCH RESEND 4/4] dax, kmem: calculate abstract distance with general interface References: <20230721012932.190742-1-ying.huang@intel.com> <20230721012932.190742-5-ying.huang@intel.com> <87edkwznsf.fsf@nvdebian.thelocal> <87cz0gxylp.fsf@yhuang6-desk2.ccr.corp.intel.com> <871qfwwqi3.fsf@nvdebian.thelocal> Date: Tue, 22 Aug 2023 07:33:28 +0800 In-Reply-To: <871qfwwqi3.fsf@nvdebian.thelocal> (Alistair Popple's message of "Mon, 21 Aug 2023 22:03:43 +1000") Message-ID: <87a5ukc6nr.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspamd-Queue-Id: ACEB5C0010 X-Rspam-User: X-Rspamd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ZLYJYhE4jNQEBFUzKsGYj+geGc+vxUfkyQTmrYSbLtZ6vq6Od9v51hxWzlzqtEuPYklvEQdFhV9IvfWOyqyMbWxLW8P8Rnakt4/ICoTRFleDlZQ/1nb1lakeWJ4bSMbY8O7I/rTMQ1fvb28Y5bo7PeEwsCrRf9vjWed0BIsk7Ce6PBsoaEfqh2ucEEa9u/KwD+uINFUnBFrDu/V6YJVxwObIHHd7E7eVcEVNHsibUN2Eywms/ES4H2JBR46SI7hBTxdcMTAxSu0KkI1hjyKx2bKNwOl8yPvCRTIpCB6bbuNfzxdHnAO7FNidojROC5QwgjXkcbMp7MunsuSfm8MhNL6xuHReHI/zUHoBEs98ZVMldftSXFqulvaNZRoMDXTxLz1UNurPNtUIWQnOiHo+hn0KcaHBzCcgQ3bXfm3GMM/hlry6vdRa9WUwlZi+gUTfsqfDrChhsUYU3Qz37Y/DFGqkgURu6Ez5iKg9ASgbDntuxFWVn1yUeOIcJZFvMgJt6icMvy6ggdtUgs= 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: Alistair Popple writes: > "Huang, Ying" writes: > >> Alistair Popple writes: >> >>> Huang Ying writes: >>> >>>> 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. >>> >>> See below but I wonder if kmem_memory_types could be a common helper >>> rather than kdax specific? >>> >>>> 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); >>>> + >>> >>> I wrote my own quick and dirty module to test this and wrote basically >>> the same code sequence. >>> >>> I notice your using a list of memory types here though. I think it would >>> be nice to have a common helper that other users could call to do the >>> mt_calc_adistance() / kmem_find_alloc_memory_type() / >>> init_node_memory_type() sequence and cleanup as my naive approach would >>> result in a new memory_dev_type per device even though adist might be >>> the same. A common helper would make it easy to de-dup those. >> >> If it's useful, we can move kmem_find_alloc_memory_type() to >> memory-tier.c after some revision. But I tend to move it after we have >> the second user. What do you think about that? > > Usually I would agree, but this series already introduces a general > interface for calculating adist even though there's only one user and > implementation. So if we're going to add a general interface I think it > would be better to make it more usable now rather than after variations > of it have been cut and pasted into other drivers. In general, I would like to introduce complexity when necessary. So, we can discuss the necessity of the general interface firstly. We can do that in [1/4] of the series. -- Best Regards, Huang, Ying