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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22344C25B08 for ; Tue, 9 Aug 2022 05:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233528AbiHIFWR (ORCPT ); Tue, 9 Aug 2022 01:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233143AbiHIFWP (ORCPT ); Tue, 9 Aug 2022 01:22:15 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 638211EACC for ; Mon, 8 Aug 2022 22:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660022534; x=1691558534; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=jZw36392s8yGioSGls0W1Ee2CQUKcpeIqNTVzcAdsL8=; b=bvsBB71QVgpaJeXBK1d2JV9hr665I6MArNpRuV3KDh4G05aKCB/9zaQ3 09mG1YxnJsXkx1b7XYkBkGtBgacAf0J9IamKoPL862DWhHjgUFrLTEm2A tVdwBDssjSbYsE6aAhwb6cAxJv4LEqj03tF9AKuci/9rzkKQ9dPdZitWL pIQ/HCcyyGJjeY6L69uCk2MNW+2taIKClW+pWPpGhwtlxg9CYw32jrNVb o3tq1ZnFWJhRK00fZukNZy2P53Ho+6I9ljq/gC+CdVdIk8cDQG/yG9Vs5 RUTCSoUjSdPH98zmNYZRBSvtOj7xnee6M5UsSvWnAkqySp7r4E4dUXNDd Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10433"; a="377048331" X-IronPort-AV: E=Sophos;i="5.93,223,1654585200"; d="scan'208";a="377048331" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2022 22:22:13 -0700 X-IronPort-AV: E=Sophos;i="5.93,223,1654585200"; d="scan'208";a="580657593" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2022 22:22:10 -0700 From: "Huang, Ying" To: "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, akpm@linux-foundation.org, Wei Xu , Yang Shi , Davidlohr Bueso , Tim C Chen , Michal Hocko , Linux Kernel Mailing List , Hesham Almatary , Dave Hansen , Jonathan Cameron , Alistair Popple , Dan Williams , Johannes Weiner , jvgediya.oss@gmail.com Subject: Re: [PATCH v13 6/9] mm/demotion: Add pg_data_t member to track node memory tier details References: <20220808062601.836025-1-aneesh.kumar@linux.ibm.com> <20220808062601.836025-7-aneesh.kumar@linux.ibm.com> Date: Tue, 09 Aug 2022 13:21:58 +0800 In-Reply-To: <20220808062601.836025-7-aneesh.kumar@linux.ibm.com> (Aneesh Kumar K. V.'s message of "Mon, 8 Aug 2022 11:55:58 +0530") Message-ID: <87bksugfex.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Aneesh Kumar K.V" writes: > Also update different helpes to use NODE_DATA()->memtier. Since > node specific memtier can change based on the reassignment of > NUMA node to a different memory tiers, accessing NODE_DATA()->memtier > needs to happen under an rcu read lock or memory_tier_lock. > > Signed-off-by: Aneesh Kumar K.V > --- > include/linux/mmzone.h | 3 +++ > mm/memory-tiers.c | 38 ++++++++++++++++++++++++++++++++------ > 2 files changed, 35 insertions(+), 6 deletions(-) > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index aab70355d64f..353812495a70 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -928,6 +928,9 @@ typedef struct pglist_data { > /* Per-node vmstats */ > struct per_cpu_nodestat __percpu *per_cpu_nodestats; > atomic_long_t vm_stat[NR_VM_NODE_STAT_ITEMS]; > +#ifdef CONFIG_NUMA > + struct memory_tier __rcu *memtier; > +#endif > } pg_data_t; > > #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) > diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c > index 02e514e87d5c..3778ac6a44a1 100644 > --- a/mm/memory-tiers.c > +++ b/mm/memory-tiers.c > @@ -5,6 +5,7 @@ > #include > #include > #include > +#include > #include > > #include "internal.h" > @@ -137,12 +138,18 @@ static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memty > > static struct memory_tier *__node_get_memory_tier(int node) > { > - struct memory_dev_type *memtype; > + pg_data_t *pgdat; > > - memtype = node_memory_types[node]; > - if (memtype && node_isset(node, memtype->nodes)) > - return memtype->memtier; > - return NULL; After adding pgdat->memtier, it appears there's unnecessary to keep memtype->memtier? Best Regards, Huang, Ying > + pgdat = NODE_DATA(node); > + if (!pgdat) > + return NULL; > + /* > + * Since we hold memory_tier_lock, we can avoid > + * RCU read locks when accessing the details. No > + * parallel updates are possible here. > + */ > + return rcu_dereference_check(pgdat->memtier, > + lockdep_is_held(&memory_tier_lock)); > } > > #ifdef CONFIG_MIGRATION > @@ -295,6 +302,8 @@ static struct memory_tier *set_node_memory_tier(int node) > { > struct memory_tier *memtier; > struct memory_dev_type *memtype; > + pg_data_t *pgdat = NODE_DATA(node); > + > > lockdep_assert_held_once(&memory_tier_lock); > > @@ -307,6 +316,8 @@ static struct memory_tier *set_node_memory_tier(int node) > memtype = node_memory_types[node]; > node_set(node, memtype->nodes); > memtier = find_create_memory_tier(memtype); > + if (!IS_ERR(memtier)) > + rcu_assign_pointer(pgdat->memtier, memtier); > return memtier; > } > > @@ -319,12 +330,25 @@ static void destroy_memory_tier(struct memory_tier *memtier) > static bool clear_node_memory_tier(int node) > { > bool cleared = false; > + pg_data_t *pgdat; > struct memory_tier *memtier; > > + pgdat = NODE_DATA(node); > + if (!pgdat) > + return false; > + > + /* > + * Make sure that anybody looking at NODE_DATA who finds > + * a valid memtier finds memory_dev_types with nodes still > + * linked to the memtier. We achieve this by waiting for > + * rcu read section to finish using synchronize_rcu. > + */ > memtier = __node_get_memory_tier(node); > if (memtier) { > struct memory_dev_type *memtype; > > + rcu_assign_pointer(pgdat->memtier, NULL); > + synchronize_rcu(); > memtype = node_memory_types[node]; > node_clear(node, memtype->nodes); > if (nodes_empty(memtype->nodes)) { > @@ -422,8 +446,10 @@ static int __init memory_tier_init(void) > panic("%s() failed to register memory tier: %ld\n", > __func__, PTR_ERR(memtier)); > > - for_each_node_state(node, N_MEMORY) > + for_each_node_state(node, N_MEMORY) { > __init_node_memory_type(node, default_dram_type); > + rcu_assign_pointer(NODE_DATA(node)->memtier, memtier); > + } > > mutex_unlock(&memory_tier_lock); > #ifdef CONFIG_MIGRATION