From patchwork Thu Nov 30 22:04:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivasulu Opensrc X-Patchwork-Id: 172143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp713471vqy; Thu, 30 Nov 2023 14:05:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5wYQ7Z0pXMa7Fjp95WhN/mdt+G3hIgJA8GoKRpn0BCbtPFQuti7Tn7mi5Mds5DW9kErlV X-Received: by 2002:a17:902:7209:b0:1cf:d650:380a with SMTP id ba9-20020a170902720900b001cfd650380amr11995134plb.13.1701381905725; Thu, 30 Nov 2023 14:05:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701381905; cv=pass; d=google.com; s=arc-20160816; b=MhSX0pNms7uzfsd29nfu12X7VAdOKcab4Gzpt3oQJQDeC1Hpdu8du2hjIdPt72aiIb orhvu7hMHBOQeorCKRzGHAq9xOZsdlYRvERGREsDrLkaNFavIJSQGgpehkZ9ai7xTdLF zqrldfsn2+n9CEb4WNmVn5FLsx9Shrd85xHxkR2cnl3JLZOP7GHSalykwDqooSLOjukQ A9wD7/6bmUhpiFgyist7mfe4A6XH2hKLyOZwrLEKPrdscEViuyhR1JwY+3wq3xxXFLTc ssMqVih28P5ERER12wT2CP4FfjXUIhDYDrBCb62vVxw46mK2d5rnPwSJZkEHW1Z5aDBp tuag== ARC-Message-Signature: i=2; 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=o52l5LIU7CxjEEjkP4vOMXqkkPzqcXZT78iTMDIBX8k=; fh=Cgo4V2P8BGjAjwk693cPR/x9zaor11aNkj67+Cv4lDg=; b=PN7rUDffUf/PEBFzj9zSTd/ye6jxir+0PMOrV+4jCCP13uO7WDPXvbg5mjTT9FQRNC qN5JJRoXVX+u2N3gkB/BbvrYIceVF59a3fnNSN0mNQjwdyywaM1Da8X+PEKYZDFP3R+n lfryPIQmy30jAp/4NXAo14Ty6h4Nk6uShgPW3g5PeOQ8e4u7TtEzr7CfQ62FCwbzxhul Da7zwNerdn1ZyQnk/4dItACPRbRxJO6OTEkEaf52cbeUhsSzhEDagXKKNXXFLSGGYnNR jbnNdARI12FbomCzbMiu4Fy+v+KC0RfSu2eQXNjJWkLJlhEwKWarTv3yoe+gbjOO55Qo KDrQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@micron.com header.s=selector2 header.b=OC0sbkev; arc=pass (i=1 spf=pass spfdomain=micron.com dmarc=pass fromdomain=micron.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=micron.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 1-20020a170902c10100b001cfdd05b56esi1933087pli.202.2023.11.30.14.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 14:05:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@micron.com header.s=selector2 header.b=OC0sbkev; arc=pass (i=1 spf=pass spfdomain=micron.com dmarc=pass fromdomain=micron.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=micron.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 71A3B807C85A; Thu, 30 Nov 2023 14:05:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377104AbjK3WE4 (ORCPT + 99 others); Thu, 30 Nov 2023 17:04:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377117AbjK3WEx (ORCPT ); Thu, 30 Nov 2023 17:04:53 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD8B31712; Thu, 30 Nov 2023 14:04:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P5/MHUZndkKKy/wMTpGNxP4CwB9gp4fk81t8/4nRgX5fgSJ6HwxffXGQakIZJ1Hxp9MgZk2xMZLzZgC+AnnVBJZ+OpMB/7CtF6o+QindtEt0HGN5WNdxSZssMG4JpvPVsRVyPOssI0IzN+1aqrd8uJL2pIYRpXursBC2j3M+kZu3MnCy3PunbsbAzBcbs2gj9AemzwStruLuuwxeOIaIG6/gmar4TZAlUA0BlhzpNEIVWoP+4a0mcfcVFkjk/fcfHz8y9IgyGEm+ElpLxZZqQ1PvQyvqb0QamJgOuaVDoCWvIZjyuV8P/jacRky/u8H2to+D9yaKsh5NyFXcuwuY5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=o52l5LIU7CxjEEjkP4vOMXqkkPzqcXZT78iTMDIBX8k=; b=Nn61Y/hMg/QrdvU8327z3ijwhpbbGF8D0N7aJBqK9/uH5L1NXrrV2kvLEP6KPwN1PuIdbJtL04ypbL5VdlpR2QmTBoYMnVGDiW/4mUdtarxZHtLNB6iWxwAtQj4CFbquDvc3tbuNkjM7xfxrXoSg6RH1T2P4xmhHXIDRNlINHBqiTWV9rcT8OSH/33VrnXm5fKKPy4Av21AAS9bazbEQVexTgoM+TQjKpcs0BLqN93wtXXz3wXfHqpeaDtFrF3fuZsvCKNtL6+dxpvD2obNOeCIPNrCJX6qKjYDit4tJw3sA+89YAxKScqy2Db2fTglC7VowT1MJ4aNRJurkZUShZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 137.201.242.130) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=micron.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=micron.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=micron.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o52l5LIU7CxjEEjkP4vOMXqkkPzqcXZT78iTMDIBX8k=; b=OC0sbkevzytx7VJ2def5zr6kxiRZ+xq3UAXPOq7fpzZPbO9L8mobZFmx0euVk4elNMj6JgsAOIa8d+c8IXULycJm4ei0yDz5FmcLhwmhbEAR5FuHTrH8eqDGKu7Es0dU642liUpUJDaTh6FojGF1NDEsPx0zenb1XnPXwzX0r6X54/jTw3RLzlSOjaVOfc+T44+QqaSx+7sNQQbl09FpDgo/VKh6oWNfHt83auZyBeB09klQO16O5NQ4n/rTNbKShMTPN4QEhF/scLMCdY9jD5x8HXQgG+/Ri5sCt+AndOMAVkxTu4wM/Qhkhjuhz6JJ1B/v4m+NjtApXFe7IPv5qw== Received: from BYAPR08CA0063.namprd08.prod.outlook.com (2603:10b6:a03:117::40) by DM4PR08MB8723.namprd08.prod.outlook.com (2603:10b6:8:18e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.24; Thu, 30 Nov 2023 22:04:54 +0000 Received: from CO1PEPF000042AD.namprd03.prod.outlook.com (2603:10b6:a03:117:cafe::80) by BYAPR08CA0063.outlook.office365.com (2603:10b6:a03:117::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.24 via Frontend Transport; Thu, 30 Nov 2023 22:04:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 137.201.242.130) smtp.mailfrom=micron.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=micron.com; Received-SPF: Pass (protection.outlook.com: domain of micron.com designates 137.201.242.130 as permitted sender) receiver=protection.outlook.com; client-ip=137.201.242.130; helo=mail.micron.com; pr=C Received: from mail.micron.com (137.201.242.130) by CO1PEPF000042AD.mail.protection.outlook.com (10.167.243.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.17 via Frontend Transport; Thu, 30 Nov 2023 22:04:54 +0000 Received: from BOW36EX19B.micron.com (137.201.85.154) by BOW17EX19B.micron.com (137.201.21.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.27; Thu, 30 Nov 2023 15:04:53 -0700 Received: from micron.com (10.3.67.194) by RestrictedRelayBOW36EX19B.micron.com (137.201.85.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.27 via Frontend Transport; Thu, 30 Nov 2023 15:04:46 -0700 From: To: , , , CC: , , , , , , , , , , , , , , , , , Ravi Jonnalagadda Subject: [RFC PATCH 1/2] base/node: Add sysfs for adistance_offset Date: Fri, 1 Dec 2023 03:34:21 +0530 Message-ID: <20231130220422.2033-2-sthanneeru.opensrc@micron.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231130220422.2033-1-sthanneeru.opensrc@micron.com> References: <20231130220422.2033-1-sthanneeru.opensrc@micron.com> MIME-Version: 1.0 X-MT-Whitelisted: matched X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042AD:EE_|DM4PR08MB8723:EE_ X-MS-Office365-Filtering-Correlation-Id: bfaaae28-bc5a-4169-8721-08dbf1f061f8 X-LD-Processed: f38a5ecd-2813-4862-b11b-ac1d563c806f,ExtAddr X-EXT-ByPass: 1 X-MT-RULE-Whitelisted: Triggered X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x2VBLTR1tz4GORoXEczCGqoXuiPkeA6sMBLpOq7fwb3ENEZAIXoHLCKVhZnsMv63KJSAxD9ilwVEsaa+gefmedO0kx737yE4e3t5lTktjzL6/9QlbjOewHr1WqjK42bH1B2NSfUkBQMz7byUR7rd4C0pyky6RP2X/b/WfCgQD/Mjjz/1oyAMPCRWFPuWuQmgzCBhxMqne0TN4pJakdqCpHn7pUxl5U+9629UM56WLIgVTPdeT5aIEDCjWX+YYBH+CcT40HA3kWz7QWsftfkpINN2dh40mqmxA+/gF5++rPVwdDmD4+zoBWRW9vPP2jIES2n/B4OOCZQXTYpArX3elbd+PkuwkHOBtCgFWVmxuYPw3rvhsF5EpdFf3FTmVdlEFQeYAl/6mRgoq3Lrbht041PzHRQAC+w1H0oVDnoR86AyY7EAw075bkVAfdWAfSSqlp2C2+mzv1JavWRmY0hhx4ZSQVOp5QfvCRV77+8Z26p2g6VoSSMykbhzwt2+7wrkCwCtvyY5DmKMy36S53A7jApupvtEJrverYRTPZHBr030ZncSOqiKtOKRAhzXjMyqDcp3aZRkIo5uKGeF4E1L/m41p8beirxzmlNl2zwrk0G8tMWLJJGYZiWLMA0LbsEf/USGjH0AWyQsk/ADvCg1B6SuVhL8SrTx9Y1uexIG8kOKl0jCS/97flWMsejsCjkssu0QQvceTvUKuk4R84wcmO+Bwvj+EpM5n2zZCCOvl0prET3+41iNKlns8caEK6YJoWNPH+zda5ioC7/ero1SLA== X-Forefront-Antispam-Report: CIP:137.201.242.130;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.micron.com;PTR:masquerade.micron.com;CAT:NONE;SFS:(13230031)(4636009)(346002)(396003)(376002)(39860400002)(136003)(230922051799003)(64100799003)(186009)(82310400011)(451199024)(1800799012)(46966006)(40470700004)(36840700001)(55016003)(40480700001)(7049001)(86362001)(40460700003)(70586007)(70206006)(54906003)(7636003)(356005)(82740400003)(36756003)(47076005)(426003)(36860700001)(1076003)(6286002)(26005)(83380400001)(2616005)(107886003)(6666004)(7696005)(110136005)(2906002)(2876002)(316002)(4326008)(8676002)(5660300002)(478600001)(7416002)(8936002)(336012)(41300700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: micron.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:04:54.0242 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bfaaae28-bc5a-4169-8721-08dbf1f061f8 X-MS-Exchange-CrossTenant-Id: f38a5ecd-2813-4862-b11b-ac1d563c806f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f38a5ecd-2813-4862-b11b-ac1d563c806f;Ip=[137.201.242.130];Helo=[mail.micron.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000042AD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR08MB8723 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 14:05:04 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784028232973910788 X-GMAIL-MSGID: 1784028232973910788 From: Srinivasulu Thanneeru This patch introduces a new attribute called adistance_offset to the node_devices structure. Using adistance_offset, a node can be migrated to a targeted tier. Target tier's adjacent distance(adistance) is calculated by taking the adistance offset into account. Signed-off-by: Srinivasulu Thanneeru Signed-off-by: Ravi Jonnalagadda --- drivers/base/node.c | 45 ++++++++++++++++++++++++++++++++++++ include/linux/memory-tiers.h | 6 +++++ include/linux/node.h | 1 + mm/memory-tiers.c | 14 +++++++++++ 4 files changed, 66 insertions(+) diff --git a/drivers/base/node.c b/drivers/base/node.c index 493d533f8375..1e63c692977b 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -569,11 +570,54 @@ static ssize_t node_read_distance(struct device *dev, } static DEVICE_ATTR(distance, 0444, node_read_distance, NULL); +static ssize_t adistance_offset_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int nid = dev->id; + int len = 0; + + /* + * buf is currently PAGE_SIZE in length and each node needs 4 chars + * at the most (distance + space or newline). + */ + BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE); + + len += sysfs_emit(buf, "%d\n", node_devices[nid]->adistance_offset); + return len; +} + +static ssize_t adistance_offset_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int nid = dev->id; + int value, ret; + + ret = kstrtoint(buf, 0, &value); + + if (ret) + return ret; + if (node_devices[nid]->adistance_offset == value) + return size; + /* + * Request from a node to migrate to a memtier with negative + * adistance is not valid. + */ + ret = get_target_memtier_adistance(nid, value); + if (ret < 0) + return -EINVAL; + + node_devices[nid]->adistance_offset = value; + return size; +} +static DEVICE_ATTR_RW(adistance_offset); + static struct attribute *node_dev_attrs[] = { &dev_attr_meminfo.attr, &dev_attr_numastat.attr, &dev_attr_distance.attr, &dev_attr_vmstat.attr, + &dev_attr_adistance_offset.attr, NULL }; @@ -883,6 +927,7 @@ int __register_one_node(int nid) INIT_LIST_HEAD(&node_devices[nid]->access_list); node_init_caches(nid); + node_devices[nid]->adistance_offset = 0; return error; } diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 1e39d27bee41..ff4e7136ab40 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -48,6 +48,7 @@ int mt_calc_adistance(int node, int *adist); int mt_set_default_dram_perf(int nid, struct node_hmem_attrs *perf, const char *source); int mt_perf_to_adistance(struct node_hmem_attrs *perf, int *adist); +int get_target_memtier_adistance(int node, int adistance_offset); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); @@ -136,5 +137,10 @@ static inline int mt_perf_to_adistance(struct node_hmem_attrs *perf, int *adist) { return -EIO; } + +static int get_target_memtier_adistance(int node, int adistance_offset) +{ + return 0; +} #endif /* CONFIG_NUMA */ #endif /* _LINUX_MEMORY_TIERS_H */ diff --git a/include/linux/node.h b/include/linux/node.h index 427a5975cf40..fd0f4f3177f8 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -83,6 +83,7 @@ static inline void node_set_perf_attrs(unsigned int nid, struct node { struct device dev; struct list_head access_list; + int adistance_offset; #ifdef CONFIG_HMEM_REPORTING struct list_head cache_attrs; struct device *cache_dev; diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index 8d5291add2bc..a40d4d4383d7 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -167,6 +167,20 @@ static const struct attribute_group *memtier_dev_groups[] = { NULL }; +int get_target_memtier_adistance(int node, int adistance_offset) +{ + struct memory_dev_type *memtype; + int node_adistance; + + memtype = node_memory_types[node].memtype; + /* + * Calculate the targeted memtier abstract distance from + * memtype adistance and node adistance offset. + */ + node_adistance = memtype->adistance + adistance_offset; + return node_adistance; +} + static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memtype) { int ret; From patchwork Thu Nov 30 22:04:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivasulu Opensrc X-Patchwork-Id: 172144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp714077vqy; Thu, 30 Nov 2023 14:06:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrizCXJeekjS6sjXnl7QuY3/c168zEDzM2GWefW0vqtS/nlKKQHa9NycPqgQjuErSboozW X-Received: by 2002:a05:6e02:12ed:b0:35a:eea4:1b4d with SMTP id l13-20020a056e0212ed00b0035aeea41b4dmr27707811iln.29.1701381967757; Thu, 30 Nov 2023 14:06:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701381967; cv=pass; d=google.com; s=arc-20160816; b=xc26FcWDJG4+2cCgutg+RNjh4fQ9Hf6OgnAh2NEF6XZO+sxiTUUgE5JYrUMFb7bgVm SNVicjbnxbdD367q9fRrrQd436ads0+eQBNVRgwohDudyZ8jOVA74m8nEXx6U6Au/icc SFkF4czojbp6wbuCBeKm0ecwAVIhB9IshXHJFC6MGBcRno3Of3Ep8QkD9Dw5EE3wq48Y 40gMSFWDnW7PYGEG4VGqaQDFq+OP/yMsl5/HUMMHgx0u+nyi7KssRa61D9cMAfofmR2W pJp0W0yshTPcew8kmPyqMwPvg0B+0yrxnsqxjL7opLdsW4uWg5IcA6+47ufgv2a1rGA5 KieA== ARC-Message-Signature: i=2; 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=iwCsJjNu6nQC1LUWcY1s4jJwPpNdTPIRqZ+x26Tt4/I=; fh=XjdDxkp+B4Wl5hE4S/qzEBL5/JlZM3+cRLljt73tBkE=; b=ENBjKExelMo24YEvoVimcBt3SmbmWq0YqbQX3xwZiFwOnLKIukkfnm0Mc1aYUrjvDv RCmwiDcfpr6ZcMmOWPdqwsL8cwx9ha73DOSfDvm7dmfD1VFXNKOueIFQQ43VZARQfOh4 ZdnMgyQxnQY2maMEc951MPebxJFoxnqbbuLb7E0s75KPGKmjGAg/3J7r/FuduCRhnGvl mK9Gb9Sr3Q8s+ccawd+91XZHan21G2NMgHn9f73NCEKMMT/01KEp+kI46LnID9tjk62I +qta0KlYHnMI0eC5BbKQ6y1lxFDeJr4k+Vn+QEn6+Z4uCPPegXuKAVlx5VB0oaLrdOLC M+nA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@micron.com header.s=selector2 header.b=P73mE6GM; arc=pass (i=1 spf=pass spfdomain=micron.com dmarc=pass fromdomain=micron.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=micron.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id cn3-20020a056a020a8300b005c624fdd8e7si1992431pgb.727.2023.11.30.14.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 14:06:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@micron.com header.s=selector2 header.b=P73mE6GM; arc=pass (i=1 spf=pass spfdomain=micron.com dmarc=pass fromdomain=micron.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=micron.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id AE175807FCC1; Thu, 30 Nov 2023 14:05:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377117AbjK3WFE (ORCPT + 99 others); Thu, 30 Nov 2023 17:05:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377132AbjK3WFB (ORCPT ); Thu, 30 Nov 2023 17:05:01 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2044.outbound.protection.outlook.com [40.107.101.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80C90170D; Thu, 30 Nov 2023 14:05:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DQffWLdkFqcIdCdNfx8Iv7YeMvAG7Qi8NryWn2LFj0MRIAuCjUCaadshegpITL1ZovvMeo80QcVtzXqg1VRoy0OZilG1/xnwMeZvrustsVjLT3QuNT/qaTLgAeNyPMHp2PZYwVKMDXyxKvexlfXF/yunuRWk0AVEVCPnATjQKcZ4wVYUF35Qg/wBc08JrPCT6IyjTUm0qTfS0+MzOktPE9t7g/XmkCPpYvupjmlUWmR6f7f6tvcWkkkpeqAqADLeVF0etiALZIUTl6sV5Fv2j3A7oaq6z/Y1x610AYLbvrAkGlm0TUTbnG2SVnwpEHhkNMrC/wlhV1UyCypVG3bRLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iwCsJjNu6nQC1LUWcY1s4jJwPpNdTPIRqZ+x26Tt4/I=; b=dLi+/dX/oiInLK2iaT9cmUkfgZs1Xwylxrq0lR325bKZc3o+R7cNB5aOyWMwM4Przl/qME5XTVY6fDTiCNSc6G/IBcJtce6O5CNVrnWWpSD9tgescGTv3LsDwuTPDIdX6ZJD6COLWkB6poNDHJsv9JHuBz+PamW68XLyE0mXMV8akxGzksLXo9nnMW8lXfeWdfbcu8OuXXUGPQypS2bhr88sknZpQyDdDnv+uNGSOWNGtJd+XFWwhUHGp02l5TsnGkOM9BUbnxDt02SCX9hRd6vnh56MHjigkwmRRguKd0ZO26uhubSZoLSKmdeZOK5y5/VhfpIH/Bu18feHAnHPcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 137.201.242.130) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=micron.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=micron.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=micron.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iwCsJjNu6nQC1LUWcY1s4jJwPpNdTPIRqZ+x26Tt4/I=; b=P73mE6GMXIbzg4FzeWQBUfpAKR2tkwmaRj2bKtl3ICSSFYXmXkboClQ6DgXiZwYt4cUHLjDrkk1cRUKdyn9WHdoA1pXBVD47KCklMn6uCb1uSO/R0Cr5lNCUcpS2A9d7XsTXRY1Bq+hydmV0fmGwl9NLG6i52qgek9uzpW/q8nvkRW8esDuCgfDN3ontdTNU08eACuoRr7josvmY+LiKd8ca39Cqkm+HQwSa00lddmcS08fy1hAdce+z4zet1JXfPFGxkAJPuIMAVfFxAfr5A3f1md29j0TSsQhpcvg/Fo99exzlBzmpYR8j0O71X4+U3/62uKV0DvFl6pLj/Gu7oQ== Received: from MW4P223CA0012.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::17) by SA2PR08MB6763.namprd08.prod.outlook.com (2603:10b6:806:11e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.24; Thu, 30 Nov 2023 22:05:01 +0000 Received: from CO1PEPF000044F3.namprd05.prod.outlook.com (2603:10b6:303:80:cafe::7) by MW4P223CA0012.outlook.office365.com (2603:10b6:303:80::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.29 via Frontend Transport; Thu, 30 Nov 2023 22:05:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 137.201.242.130) smtp.mailfrom=micron.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=micron.com; Received-SPF: Pass (protection.outlook.com: domain of micron.com designates 137.201.242.130 as permitted sender) receiver=protection.outlook.com; client-ip=137.201.242.130; helo=mail.micron.com; pr=C Received: from mail.micron.com (137.201.242.130) by CO1PEPF000044F3.mail.protection.outlook.com (10.167.241.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.17 via Frontend Transport; Thu, 30 Nov 2023 22:05:01 +0000 Received: from BOW36EX19B.micron.com (137.201.85.154) by BOW17EX19A.micron.com (137.201.21.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.27; Thu, 30 Nov 2023 15:05:00 -0700 Received: from micron.com (10.3.67.194) by RestrictedRelayBOW36EX19B.micron.com (137.201.85.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.27 via Frontend Transport; Thu, 30 Nov 2023 15:04:53 -0700 From: To: , , , CC: , , , , , , , , , , , , , , , , Subject: [RFC PATCH 2/2] memory tier: Support node migration between tiers Date: Fri, 1 Dec 2023 03:34:22 +0530 Message-ID: <20231130220422.2033-3-sthanneeru.opensrc@micron.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231130220422.2033-1-sthanneeru.opensrc@micron.com> References: <20231130220422.2033-1-sthanneeru.opensrc@micron.com> MIME-Version: 1.0 X-MT-Whitelisted: matched X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F3:EE_|SA2PR08MB6763:EE_ X-MS-Office365-Filtering-Correlation-Id: 25aecafa-2291-4cf9-e033-08dbf1f06640 X-LD-Processed: f38a5ecd-2813-4862-b11b-ac1d563c806f,ExtAddr X-EXT-ByPass: 1 X-MT-RULE-Whitelisted: Triggered X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vF4iKpy4IR8YBIhL6EyZvGR2PgHb/cJynJCYKGTnmD+UkqBP9Xeo1/wu5zB0/sOfb4T0pGX5+m/LBdOVXxfng/4nN81hMudEYxywOjeDPA07n2fU59+EPalrU2PdysgJWXyFbHZH4zj7flKfHGp3a4TRuYwzacoK+Yj6P20rVuCyDPe9FE8XV6P/tAwyMBeSUEREkiVA1g+XTMjlNWZl0SZGx6Qj5OKt27QDy80ERYqKY48E0RNusJje9UCBTcNHuDtEoXmNlzQ2I66Q5UqaNyv7UQFVRnmjM5OxMUIAUJ+G70rEvDQ9F8nerFHFwRtlXflgv8alqX6UtmVlHW7UyEJOXPBAx2yFYqlpYZtX+MXprpux+OV0hLcmPXrFtqPHe3okUxHZ61y9w+YSYmLlvFqqCX3JxOV7H3qwbqNLn6YYlaYMadIMj9kCsRKq1+W39fJkQsATIX825BF1IGcW4RP5/WFnlap006tnqnEe/nf9SiccFO88ku/2MBjBe9JGEaItsiB70cdRvb3QntM8CJQoUFTkuBKYqOzA7JDqVT+OEGWG7/4QhgYGrnDNUkiUj10iBEe05lQE1pIktkVfH4v9qWO/dH1Ro/yhcbCEEtlo67GcIwdryz04iOlAfN/EkTyK3rCVqTKgSsCQzDnS02l5N4YnOosv3bA2v00Wr8NoF/SzsxHA1C3ppa9xV2016E+XSQmG3XkgEQM22hlswwx9z/C1WMaQgw2uOSvPeha5Du1Km+O9u+wVZNOZIM/iw1tpvig3AP1z3cyr8tvpFg== X-Forefront-Antispam-Report: CIP:137.201.242.130;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.micron.com;PTR:masquerade.micron.com;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(136003)(346002)(376002)(396003)(230922051799003)(64100799003)(82310400011)(1800799012)(451199024)(186009)(36840700001)(40470700004)(46966006)(1076003)(55016003)(47076005)(40480700001)(7636003)(356005)(82740400003)(83380400001)(26005)(6286002)(41300700001)(36756003)(36860700001)(7049001)(426003)(336012)(7696005)(2616005)(6666004)(40460700003)(2876002)(2906002)(5660300002)(7416002)(54906003)(316002)(70586007)(110136005)(70206006)(478600001)(8676002)(8936002)(86362001)(4326008)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: micron.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 22:05:01.2092 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25aecafa-2291-4cf9-e033-08dbf1f06640 X-MS-Exchange-CrossTenant-Id: f38a5ecd-2813-4862-b11b-ac1d563c806f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f38a5ecd-2813-4862-b11b-ac1d563c806f;Ip=[137.201.242.130];Helo=[mail.micron.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000044F3.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR08MB6763 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 30 Nov 2023 14:05:24 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784028297975818121 X-GMAIL-MSGID: 1784028297975818121 From: Srinivasulu Thanneeru Node migration enables the grouping or migration of nodes between tiers based on nodes' latencies and bandwidth characteristics. Since nodes of the same memory-type can exist in different tiers and can migrate from one tier to another, it is necessary to maintain nodes per tier instead of maintaining a list of nodes grouped using memory type(siblings) within the tier. To migrate a node from one tier to another, remove the node from the current tier and insert it into the target tier. If the target tier does not exist, create a new one. Signed-off-by: Srinivasulu Thanneeru --- drivers/base/node.c | 6 ++++ include/linux/memory-tiers.h | 5 +++ include/linux/node.h | 5 +++ mm/memory-tiers.c | 65 +++++++++++++++++------------------- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index 1e63c692977b..8290ea96b439 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -608,10 +608,16 @@ static ssize_t adistance_offset_store(struct device *dev, return -EINVAL; node_devices[nid]->adistance_offset = value; + node_memtier_change(nid); return size; } static DEVICE_ATTR_RW(adistance_offset); +int get_node_adistance_offset(int nid) +{ + return node_devices[nid]->adistance_offset; +} + static struct attribute *node_dev_attrs[] = { &dev_attr_meminfo.attr, &dev_attr_numastat.attr, diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index ff4e7136ab40..e86c23873334 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -49,6 +49,7 @@ int mt_set_default_dram_perf(int nid, struct node_hmem_attrs *perf, const char *source); int mt_perf_to_adistance(struct node_hmem_attrs *perf, int *adist); int get_target_memtier_adistance(int node, int adistance_offset); +void node_memtier_change(int node); #ifdef CONFIG_MIGRATION int next_demotion_node(int node); void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); @@ -142,5 +143,9 @@ static int get_target_memtier_adistance(int node, int adistance_offset) { return 0; } + +static inline void node_memtier_change(int node) +{ +} #endif /* CONFIG_NUMA */ #endif /* _LINUX_MEMORY_TIERS_H */ diff --git a/include/linux/node.h b/include/linux/node.h index fd0f4f3177f8..5150215b4922 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -139,6 +139,7 @@ extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk); extern int register_memory_node_under_compute_node(unsigned int mem_nid, unsigned int cpu_nid, unsigned access); +extern int get_node_adistance_offset(int nid); #else static inline void node_dev_init(void) { @@ -166,6 +167,10 @@ static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk) { } +static inline int get_node_adistance_offset(int nid) +{ + return 0; +} #endif #define to_node(device) container_of(device, struct node, dev) diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index a40d4d4383d7..b6cd86977731 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -23,6 +23,8 @@ struct memory_tier { struct device dev; /* All the nodes that are part of all the lower memory tiers. */ nodemask_t lower_tier_mask; + /* Nodes linked to this tier*/ + nodemask_t nodes; }; struct demotion_nodes { @@ -120,13 +122,7 @@ static inline struct memory_tier *to_memory_tier(struct device *device) static __always_inline nodemask_t get_memtier_nodemask(struct memory_tier *memtier) { - nodemask_t nodes = NODE_MASK_NONE; - struct memory_dev_type *memtype; - - list_for_each_entry(memtype, &memtier->memory_types, tier_sibling) - nodes_or(nodes, nodes, memtype->nodes); - - return nodes; + return memtier->nodes; } static void memory_tier_device_release(struct device *dev) @@ -181,33 +177,22 @@ int get_target_memtier_adistance(int node, int adistance_offset) return node_adistance; } -static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memtype) +static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memtype, + int tier_adistance) { int ret; bool found_slot = false; struct memory_tier *memtier, *new_memtier; - int adistance = memtype->adistance; + int adistance; unsigned int memtier_adistance_chunk_size = MEMTIER_CHUNK_SIZE; lockdep_assert_held_once(&memory_tier_lock); - adistance = round_down(adistance, memtier_adistance_chunk_size); - /* - * If the memtype is already part of a memory tier, - * just return that. - */ - if (!list_empty(&memtype->tier_sibling)) { - list_for_each_entry(memtier, &memory_tiers, list) { - if (adistance == memtier->adistance_start) - return memtier; - } - WARN_ON(1); - return ERR_PTR(-EINVAL); - } + adistance = round_down(tier_adistance, memtier_adistance_chunk_size); list_for_each_entry(memtier, &memory_tiers, list) { if (adistance == memtier->adistance_start) { - goto link_memtype; + return memtier; } else if (adistance < memtier->adistance_start) { found_slot = true; break; @@ -238,9 +223,6 @@ static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memty return ERR_PTR(ret); } memtier = new_memtier; - -link_memtype: - list_add(&memtype->tier_sibling, &memtier->memory_types); return memtier; } @@ -499,7 +481,7 @@ 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); - + int tier_adistance; lockdep_assert_held_once(&memory_tier_lock); @@ -510,9 +492,13 @@ static struct memory_tier *set_node_memory_tier(int node) memtype = node_memory_types[node].memtype; node_set(node, memtype->nodes); - memtier = find_create_memory_tier(memtype); + tier_adistance = get_node_adistance_offset(node); + tier_adistance = memtype->adistance + tier_adistance; + + memtier = find_create_memory_tier(memtype, tier_adistance); if (!IS_ERR(memtier)) rcu_assign_pointer(pgdat->memtier, memtier); + node_set(node, memtier->nodes); return memtier; } @@ -548,11 +534,9 @@ static bool clear_node_memory_tier(int node) synchronize_rcu(); memtype = node_memory_types[node].memtype; node_clear(node, memtype->nodes); - if (nodes_empty(memtype->nodes)) { - list_del_init(&memtype->tier_sibling); - if (list_empty(&memtier->memory_types)) - destroy_memory_tier(memtier); - } + node_clear(node, memtier->nodes); + if (nodes_empty(memtier->nodes)) + destroy_memory_tier(memtier); cleared = true; } return cleared; @@ -575,7 +559,6 @@ struct memory_dev_type *alloc_memory_type(int adistance) return ERR_PTR(-ENOMEM); memtype->adistance = adistance; - INIT_LIST_HEAD(&memtype->tier_sibling); memtype->nodes = NODE_MASK_NONE; kref_init(&memtype->kref); return memtype; @@ -615,6 +598,20 @@ void clear_node_memory_type(int node, struct memory_dev_type *memtype) } EXPORT_SYMBOL_GPL(clear_node_memory_type); +void node_memtier_change(int node) +{ + struct memory_tier *memtier; + + mutex_lock(&memory_tier_lock); + if (clear_node_memory_tier(node)) + establish_demotion_targets(); + memtier = set_node_memory_tier(node); + if (!IS_ERR(memtier)) + establish_demotion_targets(); + mutex_unlock(&memory_tier_lock); +} + + static void dump_hmem_attrs(struct node_hmem_attrs *attrs, const char *prefix) { pr_info(