From patchwork Thu Nov 30 21:48:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivasulu Opensrc X-Patchwork-Id: 172141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp706085vqy; Thu, 30 Nov 2023 13:49:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcU/mQ/xE5lqjCU9mX3jolbw7EzqCx4D7hnCTdXAYWTPiD3es+CLnumKevr41atWH9D5cA X-Received: by 2002:a05:6a21:9999:b0:18c:25de:b981 with SMTP id ve25-20020a056a21999900b0018c25deb981mr22779410pzb.22.1701380997742; Thu, 30 Nov 2023 13:49:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701380997; cv=pass; d=google.com; s=arc-20160816; b=haNwvKdHuzlUJlGlOK/uDVI7vP2o47CDv5yuWVlLjTvkZt8aBG6trDKdAz0N0As4Kc k2EdRoL0SXB1/7RE0P8a5oLtskz1zaNzKTkUhzgxIKzXDtVGG6dVTZXT43DtAp/ns6wH DgWRVwydr6Thbkp9q6G/yd8i/e6TNmyKWK9StH6ADCJkJbiCg5ObnxFciHoF5UFpJzLL kshmgnUk5KsS4Riu3X5RqsRceSO+i3D+xfCVF0JDvmWak0VCASL8BHRIE+lZVQjcfbXO hzuZhaOystOTL+ijruPHhtm91rrfA8ktQ9xUabca+/OOnCeSkNuis2oZHcfYzycLmyZ2 eb+w== 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=6ZAc/+Gd8EwkRqso9x9WKtt3+HjDNYO+S4sQkJ6iSPM=; b=KfOqdc01FGOmGbPOJszk3XpOiEDA0blyqAgBbflB2fdQOmu4Bw5lEWFBEjNjvBo8cL UgfkhGP6D6Y8LrvPz+gxJLXu3mTV/nWaTMb5gepTfkDjksROF46LusI8YfTlQJ67MZ5R IqPu2B5uEoKoOk+17friFzTOVwv9Zd5/xioGENi58ynxF60vktXPTaV2sE8bpVNmpLWF T9Khje29HkVyeJKR2vN/Ipk6GAmRO/7RDyPCywO7eRMJP0uBVv1FBTjKxcaVEdfo+6Dt uv7JVZQcAgBnxsGjFfb+vH+lYs+Ob1alDMSFMJjeMQacFpdcC3ZzVHc2p0ED2Gni7Buv Ueaw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@micron.com header.s=selector2 header.b=gXRXCtx9; 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 ck25-20020a056a02091900b005c1b316d768si2292768pgb.664.2023.11.30.13.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 13:49:57 -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=gXRXCtx9; 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 9FC288026485; Thu, 30 Nov 2023 13:49:54 -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 S1376987AbjK3Vt2 (ORCPT + 99 others); Thu, 30 Nov 2023 16:49:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbjK3VtZ (ORCPT ); Thu, 30 Nov 2023 16:49:25 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2053.outbound.protection.outlook.com [40.107.243.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D8E510FC; Thu, 30 Nov 2023 13:49:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=atkN91w4WzTi870IxiaTvm02DxXwv25JMh/szwASkYYN7AlNmkjx0f9S95nboMeuvcCf86H606UA/80Xt8vxNZBu7I1Qv8UjgKO/Nnjr22jRIac7xjSFCoOtWbMWSwKMsxmhZres7UnmIOiPLCDVhr5cSvoyntfi50BhhxYT4b0EtewqRBVe9LMK34TV2x4GpJ0NxwS6pC4n5mJPsNVqMex4qXKg0i6/YfM1Zmj89CmE/xLJnODUnwJzulabrbpDQOUyTQ7HmD3nHNdBMvD3JzhJEXpoLN+tunj7qgumlBv5G8yhZgxOZXQZ0WlpvlpjfOJVTBR+mcyeNrjXWLqZHA== 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=DLDpU60JqNiF8MY4mMGxGyyjCsC10I1/d+9kui1coP3bfKTKc8TyXo75rgDUB8x2htPMtmyHSwj7HUehUY2e2hDgE5UCI5DLN4lW5mLUM7564S6Ox3T6nDUwV+JPhl4HQfjMGLebFbSV1kuNsdfaPhOmTUeKK6dUKLbYkOFZwreSFM2Q1fGw0slFzjZ5jKzk98RFThIbH1GmOR8HCcheTkcOgmOQl/B6fPeBjfgHOfgVO/Uubywsx0iSUk6Lrd47kq9vgqEzjpx+PiC/j1bAzKXrzxfVh/X/noODPJRTl1rMrdo5vvInmgR3W8XNGVH/jZ3RFAqOtj8Jh/brMYyRag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 137.201.242.130) smtp.rcpttodomain=cmpxchg.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=gXRXCtx9ozewQwq/Xz2VRwALMP8xolVrxWEyCfxGYCyNMsDr+RKVU5C7ty62kNT1hXNrY7qIcD14XM3RbuIrrPv87Jxh1JbXRpDAi1PGDvuxEhFm/4tsSRwSC63Tcq5BOFXris0g3KyGLMPkzPjtLfKl2LHb4PuwFb++KtV0JahStO5hBwPp+sjo7xuDKzkgGaL1C5X1yCEFAqhPUV5GJxwH5DO7gs+Qh/XCDs8kHuD0daEGpvBnDE5C8j9EiSle2vLKlPK7PTnJqKJjAOMYTFAHxAOU3hS4YdacFtg9X3LegIKLyBwYrZKXSOyGTG+g3FywF/C0ln5t9uPxeqmC8Q== Received: from BL1PR13CA0277.namprd13.prod.outlook.com (2603:10b6:208:2bc::12) by SA2PR08MB6523.namprd08.prod.outlook.com (2603:10b6:806:110::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.21; Thu, 30 Nov 2023 21:49:20 +0000 Received: from BL6PEPF0001AB51.namprd04.prod.outlook.com (2603:10b6:208:2bc:cafe::8e) by BL1PR13CA0277.outlook.office365.com (2603:10b6:208:2bc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22 via Frontend Transport; Thu, 30 Nov 2023 21:49:19 +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 BL6PEPF0001AB51.mail.protection.outlook.com (10.167.242.75) 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 21:49:19 +0000 Received: from BOW17EX19A.micron.com (137.201.21.218) by BOW36EX19B.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; Thu, 30 Nov 2023 14:49:17 -0700 Received: from micron.com (10.3.67.194) by RestrictedRelay17EX19A.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 via Frontend Transport; Thu, 30 Nov 2023 14:49:11 -0700 From: To: , , , , , , , , , , , , , , , , , CC: Srinivasulu Thanneeru , Ravi Jonnalagadda Subject: [RFC PATCH 1/2] base/node: Add sysfs for adistance_offset Date: Fri, 1 Dec 2023 03:18:57 +0530 Message-ID: <20231130214858.1887-2-sthanneeru.opensrc@micron.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231130214858.1887-1-sthanneeru.opensrc@micron.com> References: <20231130214858.1887-1-sthanneeru.opensrc@micron.com> MIME-Version: 1.0 X-MT-Whitelisted: matched X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB51:EE_|SA2PR08MB6523:EE_ X-MS-Office365-Filtering-Correlation-Id: 92c3c0dd-af63-4856-bc6c-08dbf1ee34e8 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: VWu3tn/s3fXeKw6pyjFKRw4HQLGCZFXGzuSjnJsNWmMknpS11ionnvV6DlDXVWQvRsfYG5v+VMsyqSbX+1NgWw0VoWSHjGji+10v3OocjjC84/HIbzgMhFsGfmuGsDCW/IyO5Y2Pc6lCQ2X0n3BGl9pTBiubWtcVs09BHJYQcSSUPfbegWu6FV2BetN7mMte0yjkSuoPDdfy45iR/W//+eoe1xYiWgW0sNHZjO+5p+Xt8pBVNEToHWymGMdig2oh7XPB53Bx0NhpDvohpJ7lh/ECTsuo4i++je4D3Q5ZOSDG6sRUVRVZ0fxAGLOUJ63rFeocy139upQ6RhgSoM3iRZq73YoKC1MW3MEGmwLttFTp6Pk8c/pxIxbrnU/PyiC4V52y0/RtCKZyXyMafVXQzh4NQLJ0hpzHv9t3tJBVkEvfK8+GTSyalSzS1w3C6P/5G3P+eGD11mmMzs+1qgRtmcN7DfNijFpZrXAqmACABK4ZjbFk7sdoiAd4eREpyLOOeS1dZDwBFGnMY5l8T8MDAR2gjhXJvrCOtcWuUfpFKRTt39WhkNOhXuH49AKuZLPxkLe2b5a8OfjXbLGgt0AtkADh5x4KT7Ii7RueWOF++1OUojSoZCKWWrhVoMkfJwxMuANtHa65kpw1hXzG6qK3m5uhcW3olJSsmSC1wnUb1jihhPtXeikfgAHE7Z41m19Y6tofDFd7Wl4E2mdLHlTzRuB6DxCHZ+zXDKKG/o8XFmlsvHIv1R6LxWPMOSuWLPEa2Ec9vR0GG7v4LO+1VcXF7F/SRy8zGWtD0SOwM8nqVP/tn7jPpqoRI9EtiohVkNkv 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)(376002)(346002)(136003)(396003)(230922051799003)(64100799003)(82310400011)(1800799012)(451199024)(186009)(36840700001)(40470700004)(46966006)(40480700001)(7416002)(6286002)(478600001)(6666004)(55016003)(70206006)(36860700001)(86362001)(2616005)(316002)(107886003)(2906002)(336012)(426003)(1076003)(110136005)(26005)(5660300002)(4326008)(70586007)(8936002)(8676002)(83380400001)(41300700001)(54906003)(2876002)(82740400003)(40460700003)(47076005)(7636003)(7696005)(36756003)(356005)(921008)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: micron.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 21:49:19.3672 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92c3c0dd-af63-4856-bc6c-08dbf1ee34e8 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: BL6PEPF0001AB51.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR08MB6523 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 13:49:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784027281055537164 X-GMAIL-MSGID: 1784027281055537164 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 21:48:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivasulu Opensrc X-Patchwork-Id: 172140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp706044vqy; Thu, 30 Nov 2023 13:49:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHUSCL37e0JQ2wB7c9NN032yXMf7382Ver1V102N2mqzeli4DfSOZa8axFZbilBGeMXDgE X-Received: by 2002:a05:6a00:8ca:b0:6c4:d12c:adf0 with SMTP id s10-20020a056a0008ca00b006c4d12cadf0mr23867719pfu.33.1701380989125; Thu, 30 Nov 2023 13:49:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701380989; cv=pass; d=google.com; s=arc-20160816; b=E6lRYmsB0dKJ+L12vuZ13L6/5nL38a8yhbPf6K2X6IEj/lDzCo6N7Q9FBVEIUcLxxd XIo7EWQoUqhwbrOIrouFWilcyFuEMcE0R/aeWSiOY3WZpn3ZhneYHYoggQEumE5WMoPo 7Xtko7LTzSFSz6ptjnV1LdgK7J8lJcXiT7rsAfdttpqu4hCJoKp1NEPgfcFxQ4gC3fc1 wqPo4A/t8/KLRWZZLIba8+abiZWCRIFw/aoFGxn94AefI1RSDiBx5IUA8gPoePEeC9R9 5jvPIsgxXn1hOHGDHrbhOr1ed608+Yf0Y/vvpGilZv6DX+pjpLsMqJJ9OclWTBRIY7q0 KjVg== 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=XYiBWrAvH/S4TzZ7AV/U5qUelIwYZW29daKWmZ6zehY=; b=Ie/aGxwUGXIrjtkK47S2D/YUysqUU2bhhW0OIX8YOiSU4VSm/RdZYDpmA+rCkIHOJN zCyF+POHxi8EWSVgamL0aJHSl72mXvJS31jl7gulcy36uW1oulu3I89h0a9udFNm5rXu 1PM2kcPnsqheLTQG4ChuKxTaffQRj/ZdZ+d1R1Y8lt79qOqAoRTDXpPdkA3Pk70D6/u4 I+kcSAHg6l/ZSSD6ee4eSgxO+2QrZ2irw/1hJTKBo6sYM8pwq25vsTVP8oglTKAFpssI C/JGNhGLUqfkaDFY6RlRkoBzgRDulMzMzcrlLvA+rOnxKppwENeuVMNptMS+XRICRLXm Oang== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@micron.com header.s=selector2 header.b=MK5u3ZeT; 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.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o7-20020a056a0015c700b006cbf1b8bf38si2048388pfu.303.2023.11.30.13.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 13:49:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@micron.com header.s=selector2 header.b=MK5u3ZeT; 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.33 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 lipwig.vger.email (Postfix) with ESMTP id 31F3D80E9E04; Thu, 30 Nov 2023 13:49:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377035AbjK3Vtd (ORCPT + 99 others); Thu, 30 Nov 2023 16:49:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376975AbjK3Vt2 (ORCPT ); Thu, 30 Nov 2023 16:49:28 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAE011719; Thu, 30 Nov 2023 13:49:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WrgYqr7hudrQbE0+scgzHNPN1bkSiUhAPUnhRA2uH5Kc5UmuoU5vb2/h4uG/AyzDZmsBx6PJbC6ElWavYwqPALNlfbuKh2hIkjMrWihlVEtjgC1wc5tuT+ClYNN/QnonvJF6+wSjm8rTQfcEd0uEki12wlUmma0/DBdWhOde+G8nrJuEeJLdpPlmCJJRbp4sdYud3UWFR9OOtw1PkeKPaFISUdqDXNc8ikI2c2DsmNBFTRjKER06JfzBHTYaFP3cvRTtuiKSHR2RqPQAdkqdDDVgdvF1LvQ3+nrNVHOGcScWlRkpBmYiIGKTchKqrhlMLIvkmFIIfGrAqCVEMKpK6g== 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=nP0ed0+N2P4LScTzD/Ptabcur4+6CPxD/ZW5bzYUxcj3I5WHmw6mkIQnAr48puamCdBIY2OjXCiaDzyecROZ5n52xJCDdcyKykyLUF1y7OTOwrLL9goY55dCqSB2gFU8nJiPW3B5RtjBf1KBQzaIa+ZYoZ74GcUmGQ5F3kya/IOwNaiNIQLPX5EaSUFtVUmaiPV+dv4qgj3xD5qviXSOLqikyGbT5lLu/j/z7EEC7ozg+BhZuJXJaXu6XX9DnGWN8gl85e0yqwmasKTxcIMRaLQ1x8KIp16g9wmBDu56mk1182zVXrwzm0UUBjrCob3pms04lpAT7E4cbDDrZUOf8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 137.201.242.130) smtp.rcpttodomain=cmpxchg.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=MK5u3ZeTs0HHiIwroRL5QTAtjaysPZ8c3mMQzCo+yAbDJQFynlnwUhF4K4fjqTn2PpSGbWYtcQYSWuWAM9vintXJiWh51Asn3ZSnxw4edjB2Bmni7gjeQm00DIMXYiTg077Yg90lU79ZXAQ7W7WtsP7tKY10d7y+Kyu5QITrKI0K8TzWsJZkvbZV/QkzcmDbdPIbpqaT5bTRUiwD0CY59txbXnh7PbanRFZB6y9ScFr2mk3BozKPvJ/zBLT++y39tOUojnQ+8+3q4LGjVzab0KnoRyz+F6qN6yzOz45i9g00/Qc2PEAeq24uh5eQCcd2mHkKQOXqBL05AQ7FKkWF/Q== Received: from PR3P251CA0009.EURP251.PROD.OUTLOOK.COM (2603:10a6:102:b5::31) by SJ2PR08MB8884.namprd08.prod.outlook.com (2603:10b6:a03:557::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Thu, 30 Nov 2023 21:49:28 +0000 Received: from SN1PEPF0002BA4F.namprd03.prod.outlook.com (2603:10a6:102:b5:cafe::91) by PR3P251CA0009.outlook.office365.com (2603:10a6:102:b5::31) 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 21:49:26 +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 SN1PEPF0002BA4F.mail.protection.outlook.com (10.167.242.72) 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 21:49:26 +0000 Received: from BOW17EX19A.micron.com (137.201.21.218) 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 14:49:24 -0700 Received: from micron.com (10.3.67.194) by RestrictedRelay17EX19A.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 via Frontend Transport; Thu, 30 Nov 2023 14:49:18 -0700 From: To: , , , , , , , , , , , , , , , , , CC: Srinivasulu Thanneeru Subject: [RFC PATCH 2/2] memory tier: Support node migration between tiers Date: Fri, 1 Dec 2023 03:18:58 +0530 Message-ID: <20231130214858.1887-3-sthanneeru.opensrc@micron.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231130214858.1887-1-sthanneeru.opensrc@micron.com> References: <20231130214858.1887-1-sthanneeru.opensrc@micron.com> MIME-Version: 1.0 X-MT-Whitelisted: matched X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4F:EE_|SJ2PR08MB8884:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c7e2f10-9969-41c6-b3f1-08dbf1ee38f6 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: jXB+3WBOX20sUL4OJSmaxHUFidQeHjNX+3N1+54dSjzzI6jnanF6TJEIoApfnn+M1z9aVKhT0TdZCwBvnROKq+1Vikm9plPFBqrMbghyqGGw1rmz13g4yOESJxugaw9kVRIQylirrcuoxrvl3L7JCJ6kT7qd0GF//DJXEM+G0V8DTgzYdnIqxOJXSd+xZ5YeVOQMnGt0GI+2kq20WzVhgjIgrSVXTr6aDFowjfl1sKumECt/1buoWm1OMj6ds8vaDekVXZl8XWB/SAZhZklPWzGLZ484gfIKPSB6p6hrPqbkahy23v6lUfsbHctMRgxZHYesYMXVBp6NnKWCaqU38xrKMChGhMlerJgzx/zDdB8KqZ8By5vUCXrwfggATF0jgh3fGe7w5EY+903zTFjAJoD9TEyKP+BkL/zP3WmeqWaLjQtPVdQIGnUQjuod5W2EM4aItsMbY65w57DuWNdLTaPXk7bVwoNQd6yTCYutiS7YnBTwEap7ZrB2AjMZ937Ze/dJpucp7myb0XZFG8F+AmXQWajR15+lBKlSYqIgsLgzwIDfl70yg8rCS7Hru6obcfDsrt/nZ7kNWC7TzVlKUKx5q+cRjxYxMWfsugiVk0d/FQkqVBFQ8cnzCfsyKKAMex782IyXJqFvYZHuaCb9tnLSU0B+1+au+4Y1763v677AC4SDLKSsN8RqWcww0YGA1qpeHZTUdU4SXQTD8foKojShex4gboBJeS0FtG5aIJDuOERvx8E1865rkIVk53NguMLz+Kg2q1y0lLeWCkLO75bWoabIia6Ff8mTkqfkB0fG4kBvkdI/AY/Tg+f93J5V 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)(376002)(136003)(346002)(396003)(230922051799003)(82310400011)(186009)(451199024)(1800799012)(64100799003)(46966006)(40470700004)(36840700001)(7636003)(47076005)(356005)(40460700003)(83380400001)(107886003)(6286002)(1076003)(2616005)(26005)(921008)(70586007)(70206006)(7416002)(2876002)(2906002)(110136005)(8676002)(5660300002)(4326008)(7696005)(86362001)(8936002)(41300700001)(36756003)(316002)(6666004)(478600001)(426003)(336012)(82740400003)(40480700001)(55016003)(36860700001)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: micron.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 21:49:26.2322 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c7e2f10-9969-41c6-b3f1-08dbf1ee38f6 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: SN1PEPF0002BA4F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR08MB8884 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 30 Nov 2023 13:49:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784027271960514697 X-GMAIL-MSGID: 1784027271960514697 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(