From patchwork Mon Jan 15 04:52:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggyu Kim X-Patchwork-Id: 188018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1502682dyc; Sun, 14 Jan 2024 20:53:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoBj0hdmz7k8bhO+g3f8+TJmQmUWAH8LlY84mOKYXALP/gmQMN+6N4ZyuDfdzRP1G9VLTm X-Received: by 2002:a05:620a:222:b0:783:3cee:4309 with SMTP id u2-20020a05620a022200b007833cee4309mr6704506qkm.42.1705294434008; Sun, 14 Jan 2024 20:53:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705294433; cv=none; d=google.com; s=arc-20160816; b=EDQlk1mSFrgZ0qbmvRtSJI0Liifafq/wF6gXevhn1jK7C+61TXHIhHPvsfkS/Baxq2 87XfLQyskLKOCRuRU+utFp6oWWA3eXJSF3pchvuZCaIE08AhpKWSxgc6C3IpF0waed+w dscXjZ9kTiWlZo3Xji9CYuTwfTBwaDiP5iFChAQ///AKyin67RDBuZZXNQ6FydKZOd6A l6tuWK/twRtMJs7iY5ckXpXtI37ifoBxe2hHnH27CJYxmXyvreIER62pMMSAbTSeq2kV cpOlsOfg4D/uWSMdw660bbfFkv9svQSfsJT6BQIsUv39mO1zl1FYdXpLVu3Fk4fSyU2u bo1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=w9f3rfKd+jtQPwgacOekgJEcbI06gWAyOzMEzJgXU4U=; fh=+4pdq3Ryf1Wrn92l99Eqk0XM0xoUyYFHVQDNS5hOfo0=; b=AUjqsk9LI5CWAXffoRoTDkmtudhBKQlnXYV2osJeLea9s4mSnYzDXRitRBqRU3LF/k 7A/kxkwPr/6qezuflMNkcGNc5NgcwYISx2r/2SN/HUzCUEhpyPY33XL6+6u6Jybo4zlM hyZEfNB17YXKAauDK1b2vcRskx7qJOj3+uyFIZeCcs62yB8xt8EzwPW6NBHs8UwwXnl4 fAAknYqqxD2w5a1ObuyyYQGvjAB+Y8GHsh/DnK+ty3pN1pF71oW9zNWHwjF3iusyr6iz y3Fh9tHrghWMxWRhNn2OztePUMc7MCW+kWsvbuRdYMKOSIFNrsdSfN3Bcu7on4RQD0vw mZ4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25623-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25623-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y4-20020ae9f404000000b0078172889863si7400583qkl.724.2024.01.14.20.53.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 20:53:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25623-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25623-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25623-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BC2001C20F4B for ; Mon, 15 Jan 2024 04:53:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E148B6FDD; Mon, 15 Jan 2024 04:53:10 +0000 (UTC) Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 42B0A23C9; Mon, 15 Jan 2024 04:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com X-AuditID: a67dfc5b-d6dff70000001748-69-65a4ba2f659a From: Honggyu Kim To: sj@kernel.org, damon@lists.linux.dev, linux-mm@kvack.org Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel_team@skhynix.com, akpm@linux-foundation.org, apopple@nvidia.com, baolin.wang@linux.alibaba.com, dave.jiang@intel.com, linmiaohe@huawei.com, lizhijian@cn.fujitsu.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, rostedt@goodmis.org, surenb@google.com, yangx.jy@fujitsu.com, ying.huang@intel.com, ziy@nvidia.com, Hyeongtak Ji Subject: [RFC PATCH 3/4] mm/memory-tiers: add next_promotion_node to find promotion target Date: Mon, 15 Jan 2024 13:52:51 +0900 Message-ID: <20240115045253.1775-4-honggyu.kim@sk.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240115045253.1775-1-honggyu.kim@sk.com> References: <20240115045253.1775-1-honggyu.kim@sk.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPIsWRmVeSWpSXmKPExsXC9ZZnoa7BriWpBoubmCzmrF/DZrHrRojF /73HGC2e/P/NanHiZiObRef3pSwWl3fNYbO4t+Y/q8WR9WdZLNbdArI2nz3DbLF4uZrFvo4H TBaHv75hsph8aQGbxYspZxgtTs6azGIx++g9dgchj/8HJzF7LD39hs1jQxOQaNl3i91jwaZS j5Yjb1k9Fu95yeSxaVUn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cgUsLiwQJfHvgi1IOYuAqsSP RR2sIDavgJnEu54uJoiRmhKPt/9kB7E5BcwlXre/YQaxhYBqGtd+Y4eoF5Q4OfMJC4jNLCAv 0bx1NvMERp5ZSFKzkKQWMDKtYhTJzCvLTczMMdUrzs6ozMus0EvOz93ECIymZbV/Ju5g/HLZ /RCjAAejEg/vj7+LU4VYE8uKK3MPMUpwMCuJ8B58viBViDclsbIqtSg/vqg0J7X4EKM0B4uS OK9XeGqCkEB6YklqdmpqQWoRTJaJg1OqgVFvYlqLYfQvfaty+3MGra/Lrldbn5lxs/FgWkHw rcUyNSd6RMol1glfkLFMFNJfVV3YaHjvQmzkSdlGodL0GJGcxjLbDVzsHk8m9ktOyzA9kFL0 12XnrPQF5xcu2u+5hGlSfQhvwOSShpa2wz58h67veago21WaFlDhYyVXE5gSNClJdVaOEktx RqKhFnNRcSIAY1YS0aICAAA= X-CFilter-Loop: Reflected X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788130816462412124 X-GMAIL-MSGID: 1788130816462412124 From: Hyeongtak Ji This patch adds next_promotion_node that can be used to identify the appropriate promotion target based on memory tiers. When multiple promotion target nodes are available, the nearest node is selected based on numa distance. Signed-off-by: Hyeongtak Ji --- include/linux/memory-tiers.h | 11 +++++++++ mm/memory-tiers.c | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 1e39d27bee41..0788e435fc50 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -50,6 +50,7 @@ int mt_set_default_dram_perf(int nid, struct node_hmem_attrs *perf, int mt_perf_to_adistance(struct node_hmem_attrs *perf, int *adist); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); +int next_promotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); bool node_is_toptier(int node); #else @@ -58,6 +59,11 @@ static inline int next_demotion_node(int node) return NUMA_NO_NODE; } +static inline int next_promotion_node(int node) +{ + return NUMA_NO_NODE; +} + static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) { *targets = NODE_MASK_NONE; @@ -101,6 +107,11 @@ static inline int next_demotion_node(int node) return NUMA_NO_NODE; } +static inline int next_promotion_node(int node) +{ + return NUMA_NO_NODE; +} + static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) { *targets = NODE_MASK_NONE; diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 8d5291add2bc..0060ee571cf4 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -335,6 +335,49 @@ int next_demotion_node(int node) return target; } +/* + * Select a promotion target that is close to the from node among the given + * two nodes. + * + * TODO: consider other decision policy as node_distance may not be precise. + */ +static int select_promotion_target(int a, int b, int from) +{ + if (node_distance(from, a) < node_distance(from, b)) + return a; + else + return b; +} + +/** + * next_promotion_node() - Get the next node in the promotion path + * @node: The starting node to lookup the next node + * + * Return: node id for next memory node in the promotion path hierarchy + * from @node; NUMA_NO_NODE if @node is the toptier. + */ +int next_promotion_node(int node) +{ + int target = NUMA_NO_NODE; + int nid; + + if (node_is_toptier(node)) + return NUMA_NO_NODE; + + rcu_read_lock(); + for_each_node_state(nid, N_MEMORY) { + if (node_isset(node, node_demotion[nid].preferred)) { + if (target == NUMA_NO_NODE) + target = nid; + else + target = select_promotion_target(nid, target, node); + } + } + rcu_read_unlock(); + + return target; +} + static void disable_all_demotion_targets(void) { struct memory_tier *memtier;