Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp104928iof; Sun, 5 Jun 2022 22:31:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbTLiui/Pxw1+DHc5M014mNxJ+LTNUKH6PMuwGDRQbYsdnRqpRscADJytG9+b7Z22I6iLZ X-Received: by 2002:a17:902:d2cb:b0:164:11ff:e55b with SMTP id n11-20020a170902d2cb00b0016411ffe55bmr22382225plc.111.1654493494549; Sun, 05 Jun 2022 22:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654493494; cv=none; d=google.com; s=arc-20160816; b=e6qxGAlceSgRd3sCs7pjiWCwueurcI1Y3t+WBhuAjPM3RsiwONaOhW4nxQMIz9MVRs otpjwLEDH3Bnbjy7XbQ6wT1aFZfLCooBj1f95hj4jDUo6hYpzDyKcG09O6hntNufxKWi AarBrRnRw07jRFj90Q5VWIvf3HVB29b/1PCoHj8gu1EIepfFKNe/hDumL8+aR/OeHLva wMN7WopPPPzsF9im3Qzy7E+Xf8I2BNZbikj9DBHpp9mCuGZohy6+geFAGLGq+dyfwAgI s1BqegtPVLk2Qu6Pb7DI+HAh3/R3PdK2rZwfyqmE/PRyRwMN+qjRhqICYWmpXIie9ecs zHtA== 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=BUCn0BY2ZXsWri4dRdU95JjN/8kb3U+L/F9XlYqa2Bg=; b=1EiWuk9N/1HgfSq3wbOqksBXj9iiuGiyV2a+pS/nNkU9vNopzbvw4/NW1CeTuYLlJr 0XulU86fe4uZYmCJNuKZyXTQZyWUKaKdLozdmMxux9KUS5N7v9hkZoaFxUyY/ATi7QWx 27pFlPiLrMclKvNjDYyZq7eXd4j2RdyrkUzaNLZ+KQSjdzxPtsMlhUkmCjWBxADJ48J8 Qy8B3vign2FuXD3IJ5M8F+nr7P4FlU6oA7YZNQwFOall5IVJh23ltQg5nIeI8gLzaTPs gLnT3s8CuDI5CMjdaAgj/FGcVIyJAjIfi5BRtYjz2MvHl5zDDNIMQJWv5uSdfeEvAQvj ydtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=BVnWdjju; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q7-20020a17090ab98700b001e32a639040si21669627pjr.67.2022.06.05.22.31.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:31:34 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=BVnWdjju; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC47621255A; Sun, 5 Jun 2022 21:32:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244757AbiFCNpB (ORCPT + 99 others); Fri, 3 Jun 2022 09:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244819AbiFCNor (ORCPT ); Fri, 3 Jun 2022 09:44:47 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01B933A5D6 for ; Fri, 3 Jun 2022 06:44:45 -0700 (PDT) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 253CFLgN002903; Fri, 3 Jun 2022 13:44:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=BUCn0BY2ZXsWri4dRdU95JjN/8kb3U+L/F9XlYqa2Bg=; b=BVnWdjjulZzHbLLJyBuVL9VJJrL5p7elwwnZV1I9qfuEPb78HGwg8g7g0KD6NX1rarjq 9qjNMLIwKb0RIrS5nNaHca8k78ZVCHLQ8UDKstvqXGXStThoW9crb6NyCYXUCVV/8bka OB3d55aXErE9cfaAdwDxqTijwxoiRq/45WXA+FnJSVjE/rm44Pq50a/CU+MRsqjJyW90 YySszjPwPz0HZ1eP1MxJwKLzIzuE+XYxSSyCOeKXXdLaBzDqyeH3hQN0kkwc8Qs30sYY eVN1TZCHKm0067GYxYT+DlTtyX1psgvifpxlXWehSaq3qrw5t95OfOlIfTfQo/dCdGXq zQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gfgg8b99f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jun 2022 13:44:36 +0000 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 253Cwqok004481; Fri, 3 Jun 2022 13:44:36 GMT Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gfgg8b996-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jun 2022 13:44:36 +0000 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 253DaUVL027611; Fri, 3 Jun 2022 13:44:35 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma04dal.us.ibm.com with ESMTP id 3gd4n68dq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jun 2022 13:44:35 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 253DiYHU9830668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Jun 2022 13:44:34 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 190F0112063; Fri, 3 Jun 2022 13:44:34 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 84AC2112062; Fri, 3 Jun 2022 13:44:26 +0000 (GMT) Received: from skywalker.ibmuc.com (unknown [9.43.93.173]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 3 Jun 2022 13:44:26 +0000 (GMT) From: "Aneesh Kumar K.V" To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Wei Xu , Huang Ying , Greg Thelen , Yang Shi , Davidlohr Bueso , Tim C Chen , Brice Goglin , Michal Hocko , Linux Kernel Mailing List , Hesham Almatary , Dave Hansen , Jonathan Cameron , Alistair Popple , Dan Williams , Feng Tang , Jagdish Gediya , Baolin Wang , David Rientjes , "Aneesh Kumar K.V" Subject: [PATCH v5 9/9] mm/demotion: Update node_is_toptier to work with memory tiers Date: Fri, 3 Jun 2022 19:12:37 +0530 Message-Id: <20220603134237.131362-10-aneesh.kumar@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603134237.131362-1-aneesh.kumar@linux.ibm.com> References: <20220603134237.131362-1-aneesh.kumar@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: h6x5ag3c0QcohwVDA3Yn5j1SGQueDgDx X-Proofpoint-GUID: xxrlc1sSbC-F3CxfgTlo2b9hGvdng3ck X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-03_04,2022-06-03_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 impostorscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206030059 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 With memory tiers support we can have memory on NUMA nodes in the top tier from which we want to avoid promotion tracking NUMA faults. Update node_is_toptier to work with memory tiers. To avoid taking locks, a nodemask is maintained for all demotion targets. All NUMA nodes are by default top tier nodes and as we add new lower memory tiers NUMA nodes get added to the demotion targets thereby moving them out of the top tier. Signed-off-by: Aneesh Kumar K.V --- include/linux/memory-tiers.h | 16 ++++++++++++++++ include/linux/node.h | 5 ----- mm/huge_memory.c | 1 + mm/memory-tiers.c | 10 ++++++++++ mm/migrate.c | 1 + mm/mprotect.c | 1 + 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index cd6e71f702ad..32e0e6fabf02 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -16,12 +16,23 @@ #define MAX_MEMORY_TIERS 3 extern bool numa_demotion_enabled; +extern nodemask_t demotion_target_mask; int next_demotion_node(int node); void node_remove_from_memory_tier(int node); int node_get_memory_tier_id(int node); int node_set_memory_tier(int node, int tier); int node_reset_memory_tier(int node, int tier); void node_get_allowed_targets(int node, nodemask_t *targets); + +/* + * By default all nodes are top tiper. As we create new memory tiers + * we below top tiers we add them to NON_TOP_TIER state. + */ +static inline bool node_is_toptier(int node) +{ + return !node_isset(node, demotion_target_mask); +} + #else #define numa_demotion_enabled false static inline int next_demotion_node(int node) @@ -33,6 +44,11 @@ static inline void node_get_allowed_targets(int node, nodemask_t *targets) { *targets = NODE_MASK_NONE; } + +static inline bool node_is_toptier(int node) +{ + return true; +} #endif /* CONFIG_TIERED_MEMORY */ #endif diff --git a/include/linux/node.h b/include/linux/node.h index 40d641a8bfb0..9ec680dd607f 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -185,9 +185,4 @@ static inline void register_hugetlbfs_with_node(node_registration_func_t reg, #define to_node(device) container_of(device, struct node, dev) -static inline bool node_is_toptier(int node) -{ - return node_state(node, N_CPU); -} - #endif /* _LINUX_NODE_H_ */ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a77c78a2b6b5..294873d4be2b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 592d939ec28d..df8e9910165a 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -31,6 +31,7 @@ static struct bus_type memory_tier_subsys = { static void establish_migration_targets(void); static DEFINE_MUTEX(memory_tier_lock); static LIST_HEAD(memory_tiers); +nodemask_t demotion_target_mask; /* * node_demotion[] examples: @@ -541,6 +542,15 @@ static void establish_migration_targets(void) */ list_for_each_entry(memtier, &memory_tiers, list) nodes_or(allowed, allowed, memtier->nodelist); + /* + * Add nodes to demotion target mask so that we can find + * top tier easily. + */ + memtier = list_first_entry(&memory_tiers, struct memory_tier, list); + if (memtier) + nodes_andnot(demotion_target_mask, allowed, memtier->nodelist); + else + demotion_target_mask = NODE_MASK_NONE; /* * Removes nodes not yet in N_MEMORY. */ diff --git a/mm/migrate.c b/mm/migrate.c index 0b554625a219..78615c48fc0f 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -50,6 +50,7 @@ #include #include #include +#include #include diff --git a/mm/mprotect.c b/mm/mprotect.c index ba5592655ee3..92a2fc0fa88b 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include -- 2.36.1