Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1328495rbb; Mon, 26 Feb 2024 06:10:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVx0SShbWPsjYRD4Z1gfLouYrQVla4QRsOZkspuobgPREzqqd51ouF44NALLKoJpJLesOjvZ/O+s1jFKt2WnrWOK1jLzmZTNumyrus3Xw== X-Google-Smtp-Source: AGHT+IHng3RW3I/1pks/iqvTJdOQMdTSBTyYMvcbppFo0bBcBiQ32ffkxar4rvKHvkScjqxcD65J X-Received: by 2002:a05:6512:48d:b0:512:ec7b:4be6 with SMTP id v13-20020a056512048d00b00512ec7b4be6mr4256936lfq.11.1708956630233; Mon, 26 Feb 2024 06:10:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708956630; cv=pass; d=google.com; s=arc-20160816; b=0N2MCGucX2TPqQCDfi43eKeqI976liPBy3C2kac229uMAdi5fH6XI1tqv+rCnW8CPC rSlnRWh3lWE/nEjXfXipQDPzLPAXK4E5b60uuL7CZt29YFXrO6GS0jG2ARqnPXQiHrTL 6egljCck2D+vVh7TuK9QZlghJ+cQd+7pUVOzjVijrL6syWD7RaA/ursSwxqDFwqoz0Yl W4MLEdqF9dLnpW+t3HOQfzJQ0ToEFJ/6gPQ8SftdF5NW0vsA5HNTXfS3LcQAqD4CXs9i HAz2aB3P/dJJEiqZ2lYmdzTU0vzrZVe5rGidtsmrXDtZmIoL0iS+Czdwu44ld119Vq50 bD3A== ARC-Message-Signature: i=2; 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=egwJU2bb679B4Zi0WdxyKykgfACRkSkUGxyHY52POxM=; b=vcYn06t/iDYHvlT9NbQbdpJBvDEzzk58Qdu66nefes0z3SNXfTjffq6LbTaELfSI3X Z4T8rdnvJad7Q8Nqo1iMGq9Bh+PFP0/RXk7hztlqA4dNHiQ5HpArLpwJ6Idse/H8oH2u KYb+XgfOFm/049CBWWGkIgvOz2eY7YZ2uevNgl6HVrkchlnVdcgvlrHAWJGBUeQEgmpm NZtxCQ0bXRLlnrEMs6RNd3Dl3bR2aTEXKCX6JXeYEJY/aepmYi2f17d6ymiTEtDLaz3P 41GxdRUyAPXxxESoZHmQ3d8HQGL1WrgnhkKY+8I4RR6TyODrxkjruFK6016MApH63AwG IEig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-81584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81584-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gq5-20020a170906e24500b00a3e9055c0d7si2049541ejb.947.2024.02.26.06.10.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 06:10:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=sk.com); spf=pass (google.com: domain of linux-kernel+bounces-81584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81584-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id ED6E11F2BDAA for ; Mon, 26 Feb 2024 14:10:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B75A12CD86; Mon, 26 Feb 2024 14:06:24 +0000 (UTC) Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 118CF12C53D; Mon, 26 Feb 2024 14:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.125.252.92 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708956383; cv=none; b=eJT2kB8XUbZHIB0mJqgshuzgHbPwNG2+gfFgJ9MHnlEpkL7i2NCf57I7rSKkpDPMUHvGe17uWs3Ju6+qmjeU8zFCAcbs8qHceZ8bbdtZ2TvtbdI0n7gSshY+WumTZxCXjZl8wZrUqLVGggsvjkAj5BXoToSZ6coY5ehiq3SfppA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708956383; c=relaxed/simple; bh=tP11PJE+B44zfRXa8blWSPevKcbSiOSl0SgRA/mAjGs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tvySXC2re05mUgHRLI9PI54eGCY53kaKFYpSMQZe6FWF1T1fOZ74z/mVunr7rp5SjUYWQZlMulK4GvPjPm3TOf9L8d4tvi5F/cKgm9esdFHNBkbW29PV4duMFmHlQ2x98uKGracACylobV6Hez+8cazLrQyxSANX4eihyfFNYbU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com; spf=pass smtp.mailfrom=sk.com; arc=none smtp.client-ip=166.125.252.92 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-7c-65dc9ad909a7 From: Honggyu Kim To: sj@kernel.org, damon@lists.linux.dev, linux-mm@kvack.org Cc: akpm@linux-foundation.org, apopple@nvidia.com, baolin.wang@linux.alibaba.com, dave.jiang@intel.com, honggyu.kim@sk.com, hyeongtak.ji@sk.com, kernel_team@skhynix.com, linmiaohe@huawei.com, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, lizhijian@cn.fujitsu.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, rakie.kim@sk.com, rostedt@goodmis.org, surenb@google.com, yangx.jy@fujitsu.com, ying.huang@intel.com, ziy@nvidia.com, 42.hyeyoo@gmail.com Subject: [PATCH v2 4/7] mm/memory-tiers: add next_promotion_node to find promotion target Date: Mon, 26 Feb 2024 23:05:50 +0900 Message-ID: <20240226140555.1615-5-honggyu.kim@sk.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240226140555.1615-1-honggyu.kim@sk.com> References: <20240226140555.1615-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 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRmVeSWpSXmKPExsXC9ZZnoe6tWXdSDb7/YrOY2GNgMWf9GjaL XTdCLP7vPcZo8eT/b1aLEzcb2Sw6vy9lsbi8aw6bxb01/1ktjqw/y2Kx7haQtfnsGWaLxcvV LPZ1PGCyOPz1DZPF5EsL2CxeTDnDaHFy1mQWi9lH77E7CHv8PziJ2WPp6TdsHhuagMTOWXfZ PVr23WL3WLCp1KPlyFtWj8V7XjJ5bFrVyeax6dMkdo8TM36zeOx8aOnxYvNMRo/e5ndsHp83 yQXwR3HZpKTmZJalFunbJXBl7FvZwFrwSLziz+vJzA2M+4S7GDk5JARMJF6+3sMGY1/cspYJ xGYTUJO48nISkM3BISLgILHqq0IXIxcHs0ADi8SPz5dYQGqEBSIlZkxuYgWxWQRUJVpPXWIE sXkFzCSuP9nHCjFTU+Lx9p/sIDangLnE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EmlhWXJl7iFGCg1lJhDdc5maqEG9KYmVV alF+fFFpTmrxIUZpDhYlcV6v8NQEIYH0xJLU7NTUgtQimCwTB6dUA+PaINdoLfZf91+us46d M+uS9dVZPGz5fwVbW9xXNF27aR175kvOuZl+M6Tc2xjtV9hLXT3SNv32Qf/yvKWX7ZYkSpxm ur3k8ve/hVWzpmVtMmFR29aY9PC4cbLtp4U72J6/UF6+XuXSfvaQ7p0GDrz/q7uEtlbM5zYx mm2td+9xbItPYfdB704lluKMREMt5qLiRABxHBSHsQIAAA== X-CFilter-Loop: Reflected 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; -- 2.34.1