From patchwork Thu Mar 6 05:45:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 14003844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBF73C282D1 for ; Thu, 6 Mar 2025 05:47:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 099C36B0082; Thu, 6 Mar 2025 00:47:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 049BD6B0083; Thu, 6 Mar 2025 00:47:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E07AE6B0085; Thu, 6 Mar 2025 00:47:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C31DD6B0082 for ; Thu, 6 Mar 2025 00:47:00 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4BB6E80B11 for ; Thu, 6 Mar 2025 05:47:01 +0000 (UTC) X-FDA: 83190042642.27.4A50458 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2044.outbound.protection.outlook.com [40.107.243.44]) by imf18.hostedemail.com (Postfix) with ESMTP id 6D2661C0009 for ; Thu, 6 Mar 2025 05:46:58 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=hr6FClkx; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf18.hostedemail.com: domain of bharata@amd.com designates 40.107.243.44 as permitted sender) smtp.mailfrom=bharata@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1741240018; a=rsa-sha256; cv=pass; b=702ZTO2m1OIinmk59FRuCx6OfCORvF23VbqIMNoC4gbgw/54jMr9DZbSeigZOeQnyLt/hy uDmiUz2HTJmOGy3hciLPUV71ls4++EYs41OOvUU9OV9+97GosaXF7PJEyc33sUcPom6QWK 3GUZ1NSoOIfQkkho7BWg/6vvZKilMfU= ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=hr6FClkx; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf18.hostedemail.com: domain of bharata@amd.com designates 40.107.243.44 as permitted sender) smtp.mailfrom=bharata@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741240018; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=1QFKCbUCNC9TWnvnxFhbG/VkxsA1ZUaVDH8DZejw4kY=; b=4wCrZxay/7/SX3mzKhnfA2QLb0NTmtU58pfT6fJ2vCK9+uy1vyZiq0gaVk5BorqNDMkLoN oy7KeLfaSMQEMmw9a4Xj/cux0nwh4ep9USzR0ASIL1jo7ED5yJeMmd8q7ZnAfAqvyLn2lh HbIowgFwOtvmcn5SA0thEMML8FL7tR8= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BDDYDIAXfIIy6/gLFX/bLsDnhpP5yX/7LAQCbO875GGlnkmSfMIDfKgtH0DOtShLHOtCu2V+p6w4zLOftiu2Ucs5UTS7Ad+ixml1rrG8TLasjPOo/gmxsKmdyo8D7j7bhUqR2q9No9qMbJtKufu7uoNzyXKouQnzyGVF9aNOx7BzBalna16agxk0OftdyrpqhI/L7Y1scO+SkZCL9Brbi/vRwgZd+E6SrgjGU2qWNzDAs7IkAuV+tS+q1yBh3VXc94Eyk+mL6iPawRs3Hgdg1INb8TvTz/KGpUMWMR0u+ZUfY+N23b0CUNUQTnS6jjLM7jZKCblLrFmnRvPOqKTcZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=1QFKCbUCNC9TWnvnxFhbG/VkxsA1ZUaVDH8DZejw4kY=; b=ujrCipfjZlN1dMWRUFqv/z8gViCNx8qSKNuE7PaBkkR4yJaNGV6WJFuHAE8e9PH1dw1b0xAssi4y9q4/ZxvtgY0PxTOHK4DEYzDxfCsCZi9jICrEJ0zX8drTML73+XxOdkjLqHaT1Z18w8y2vdy0EwSyyfifLgQGFCHoVRXg+Pi8wG2hTkOEXTVCAbdoKbXKbJfyewjkasKurG+i/x/RE1GoFLOaYJe8+invYckqltEc1RDsQ+SOx6EZNyJI6uIjtvuqq0JH2TwHwvN7L0FZfMDLKS61cLYLtnHDrXtCl/YUMyIq6lu75GtDkwawsU2r24vwazQ2q9PwfC6Zow0Qfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1QFKCbUCNC9TWnvnxFhbG/VkxsA1ZUaVDH8DZejw4kY=; b=hr6FClkxNIJ9TMv3ThAXnIfW7P4iV3jLa7IsOxjqPZFEmnzvdk5pRh/Ni5fsX1gs4gN/WwIHlU5uGMfRWXK6vN9VEfsuKQEwflYOtSa1r+EuVK0dcKJ2sGK3az4fEVPU7Rbl5oIeDMU8X9mwqDQAoLKIGgozn8i9w04RuqDsvGM= Received: from BLAPR05CA0023.namprd05.prod.outlook.com (2603:10b6:208:36e::25) by CH2PR12MB4229.namprd12.prod.outlook.com (2603:10b6:610:a5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.19; Thu, 6 Mar 2025 05:46:53 +0000 Received: from BL02EPF0001A0F9.namprd03.prod.outlook.com (2603:10b6:208:36e:cafe::b3) by BLAPR05CA0023.outlook.office365.com (2603:10b6:208:36e::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8511.20 via Frontend Transport; Thu, 6 Mar 2025 05:46:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF0001A0F9.mail.protection.outlook.com (10.167.242.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Thu, 6 Mar 2025 05:46:53 +0000 Received: from BLR-L-BHARARAO.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 5 Mar 2025 23:46:41 -0600 From: Bharata B Rao To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Bharata B Rao Subject: [RFC PATCH 0/4] Kernel daemon for detecting and promoting hot pages Date: Thu, 6 Mar 2025 11:15:28 +0530 Message-ID: <20250306054532.221138-1-bharata@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0F9:EE_|CH2PR12MB4229:EE_ X-MS-Office365-Filtering-Correlation-Id: a66aac34-be70-4e12-1afc-08dd5c724c72 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|82310400026|7416014|376014|13003099007; X-Microsoft-Antispam-Message-Info: rv4zw5NrgjByDUjFdLMWpFl8OIKTrIcxewWeSOlUfwGdsdCaLOcokpBuZyvz+ZULR2DgCcdEPkPxdXml7CXjrGtX+5PKM0Ueo3RIeHXPwElyssHpE6D6j7n/b3xB7jS9mygWmhYHnCifTdteN1IpMmlVQ8rOES0dewHYJJ1meNBQVIBB+xrvJX03PidR/W/c+VNoYhB2CdNIpVhTB+8d6BL6q1TYhDVGqZMiFfUXaAzSk42rN3ipEZvoKsWJmCymRnJWoYMIhAiDRN+6yo9EoetGXq6tPqjeipZXVdOHXpT0q3M5tu5zA1JB1Ve490O4RJr1LGhVFeN6+p44aS2DxJBVnlcXIiKbPgctyhXgJPlg9FduNdCX0A9jZfrHZtg+2UpT3PMftAJ0hwYoJEq8vRQ5wJmbBfjd5YXL4/7d18NyNCjCb4Ne11s/pV9jP1Yq4P2gF54XEnRpVW6T18SQjxEd3/UKZ7ml+ypr6m1LuYM+eFlOQVSWu1HLiP9CJp4J0hZnKnTrH5smEkEZJ7jAZ2luwbHaoZOwNfUmP82eizTwqc+Iu8EORN57A4rISDjbxk7s2NlkJkY75o4xgQFhdXoMuOGd4u4SnI2jMgwX6JHnkQdQrlWWGtFdHfVxFdJJQ+i6LwrHaXxpxqfeW9/vzV5jegT6z/sWQQ/2qjXxZ25XViM+FAL/rxlrA3GzSKXMMGOcDbwMP/lTnUDd666CLMm9T+E9dqwpp4lSx9Gz5bUC/V7V69I/BC6TYY0g7GP93Dt30qC9EHRWkDqykxWss2rOgE5XDYAWkDVVmlekjPoyguiyzZJ3hFf+t7GcVnut3sdEWUMRm6Z7S5TEx7b822kmHAMauplOeLpkNV42rD3BVpvbJjz1bPqlUqETKTVKlGJiQBwrq22mnm5tiKHTKzEjzdezMNqGk1l5VkJ85fcZYcR3porBtQzC4iIlx8e25+mbP9TFJDpJia/9Kteqy6evFMSSARJ8IaUkxxGwVRypG2gD0Zaf8Er61v3S6CCKBIjmt7EMsroQEEUENpGCVQqDmtdBYfy4/FgmwRvL5FG3p95C6p88qBZO6WzJs/iMtsUriAYyOaCCSXtZQjPVxrnc8we89nJcirJJXH8rQqdkuDXB4bWzCaaSZpEjJOsTS8o1ugqMN5/jb4zdKHyazR9Z7UPddFLViZyoTCK0NB+UdjFllwLGOLSGFPPIURiYqaOKfK46oH852CsAnszCQ2T6c3HQAcVo3wrRoEidUE6JLnlWwbKS3916KOMKNuaqq5t7zEwC3F/vdAqnmfMR03CUKe0ZvdC31AjBeMJ7SI75V+9Kssybz9f+8BywDW4tNe4du/KgEaOtI2R5hATPF4VvYKUXOCyjeCVQE7OJvSDzz68bd8qbatXzyYA5B4vj4wnyBJAvVEdCdmH5ONwbscZ5NtiR3df8z+6y8mSREXwk9K4OsiStFwSkt23X4Cr7nPJ72dPEikwMhbcqlJJfBEaQIuBtsSpASgJbutKdw2w= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(82310400026)(7416014)(376014)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2025 05:46:53.4583 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a66aac34-be70-4e12-1afc-08dd5c724c72 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A0F9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4229 X-Rspamd-Queue-Id: 6D2661C0009 X-Stat-Signature: rkxhgujxgt5ji8tfye65nytr5mnrxkoy X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1741240018-249016 X-HE-Meta: U2FsdGVkX1+v0933cHnUSDEEKs0RzrlFunksrpAFaxMj4AzPiWO/cI0LquMAKaVodwcgZIuhRw0/lyNRJssexX5eBccF1eieM+Wi4+w+vuCiDrJve5Lfs4YWlxJ8Ehc3B1bQrRj96CQO15tZgwr5fnHF1/wTOKOpEO36MIgLURsu9d3hemQD+T+T9WF0B0MdiR4yDR4XGxxEiWPmLd1+4sTTB1lFhfRIl7Fo0s5ijh8McKR5u/9zacCmIFSZRoPbsvUM8smGAXtQ6o6IRCOYxPAL1mpBaQ3uXbSPGZlbDzNlevTU11KtAH3qExkNcBl26ETEUlxLRVzLebDN+XU93Rhj7aeaHM2XE1P26l4iXdLGwN39grGp/c+TAfV6joq1WUzH//91Pxbqs6uHm8NnVDDIBxATxjDqIQ4y+E3liVu+BorWGYv2bnpIWSXjCguISYdxpksPCk7Ro0pZUEFyGWYnNEi2KLwNlZAgCK2OMax0D/sfoaumLasAkny0QcGzpKoQp+ncTVUav9AsDSrshA2L6kzx2OQ+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version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi, This is an attempt towards having a single subsystem that accumulates hot page information from lower memory tiers and does hot page promotion. At the heart of this subsystem is a kernel daemon named kpromoted that does the following: 1. Exposes an API that other subsystems which detect/generate memory access information can use to inform the daemon about memory accesses from lower memory tiers. 2. Maintains the list of hot pages and attempts to promote them to toptiers. Currently I have added AMD IBS driver as one source that provides page access information as an example. This driver feeds info to kpromoted in this RFC patchset. More sources were discussed in a similar context here at [1]. This is just an early attempt to check what it takes to maintain a single source of page hotness info and also separate hot page detection mechanisms from the promotion mechanism. There are too many open ends right now and I have listed a few of them below. - The API that is provided to register memory access expects the PFN, NID and time of access at the minimum. This is described more in patch 2/4. This API currently can be called only from contexts that allow sleeping and hence this rules out using it from PTE scanning paths. The API needs to be more flexible with respect to this. - Some sources like PTE A bit scanning can't provide the precise time of access or the NID that is accessing the page. The latter has been an open problem to which I haven't come across a good and acceptable solution. - The way the hot page information is maintained is pretty primitive right now. Ideally we would like to store hotness info in such a way that it should be easily possible to lookup say N most hot pages. - If PTE A bit scanners are considered as hotness sources, we will be bombarded with accesses. Do we want to accomodate all those accesses or just go with hotness info for fixed number of pages (possibly as a ratio of lower tier memory capacity)? - Undoubtedly the mechanism to classify a page as hot and subsequent promotion needs to be more sophisticated than what I have right now. This is just an early RFC posted now to ignite some discussion in the context of LSFMM [2]. I am also working with Raghu to integrate his kmmdscan [3] as the hotness source and use kpromoted for migration. Also, I had posted the IBS driver ealier as an alternative to hint faults based NUMA Balancing [4]. However here I am using it as generic page hotness source. [1] https://lore.kernel.org/linux-mm/de31971e-98fc-4baf-8f4f-09d153902e2e@amd.com/ [2] https://lore.kernel.org/linux-mm/20250123105721.424117-1-raghavendra.kt@amd.com/ [3] https://lore.kernel.org/all/20241201153818.2633616-1-raghavendra.kt@amd.com/ [3] https://lore.kernel.org/lkml/20230208073533.715-2-bharata@amd.com/ Regards, Bharata. Bharata B Rao (4): mm: migrate: Allow misplaced migration without VMA too mm: kpromoted: Hot page info collection and promotion daemon x86: ibs: In-kernel IBS driver for memory access profiling x86: ibs: Enable IBS profiling for memory accesses arch/x86/events/amd/ibs.c | 11 + arch/x86/include/asm/entry-common.h | 3 + arch/x86/include/asm/hardirq.h | 2 + arch/x86/include/asm/ibs.h | 9 + arch/x86/include/asm/msr-index.h | 16 ++ arch/x86/mm/Makefile | 3 +- arch/x86/mm/ibs.c | 344 ++++++++++++++++++++++++++++ include/linux/kpromoted.h | 54 +++++ include/linux/mmzone.h | 4 + include/linux/vm_event_item.h | 30 +++ mm/Kconfig | 7 + mm/Makefile | 1 + mm/kpromoted.c | 305 ++++++++++++++++++++++++ mm/migrate.c | 5 +- mm/mm_init.c | 10 + mm/vmstat.c | 30 +++ 16 files changed, 831 insertions(+), 3 deletions(-) create mode 100644 arch/x86/include/asm/ibs.h create mode 100644 arch/x86/mm/ibs.c create mode 100644 include/linux/kpromoted.h create mode 100644 mm/kpromoted.c