From patchwork Sun Dec 1 15:38:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra K T X-Patchwork-Id: 13889571 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2076.outbound.protection.outlook.com [40.107.243.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF75B1D14F8; Sun, 1 Dec 2024 15:39:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733067598; cv=fail; b=fPOowkckeCwyODisCB1Mk2njGFNZq4EHUCJlUSGPaJRPNJWTUwVVYfTVmucrsjtyQc+DTsdUdspaU0rHLCrba58yn2A5o8Jz4h7I5S5ZxaoSi7/lBBWAWVSlqbXt37LKQCWnFMhY+XjN6/MO1VwtemGmjAqnpSnXDlZJcHwKOt8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733067598; c=relaxed/simple; bh=YwcOx3T4/8+NAeC2q7ZMYcYRWS5D9+R0Dl4TsSBTe6Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WBA2Vrg2JvJViw9s7lh5LKZ3rSNxoQ2zFqenll4xPpO7ApU9TvGnSEdaPv/RYnWiYdOBnUah8fWKnUMjQpoQ470V/jffZMnSEEila6y7njLb8w67Qwb/79vY6XGL7iTj3kgib9aQsP6OWhUf9V2cIJmBGpgrrzSQjGZRM80kt+k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=oqfYKGdo; arc=fail smtp.client-ip=40.107.243.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="oqfYKGdo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gs3A/GjIq+t/gBe+rLFC452vxst1bSaalYMr+nLu76FAWcZcYkzPuPxNzUldfO81J7tBXm+I9G2PHd8F4EthS8TgiHDS3qyy6AhxlKD2oLap+ZWsh9JM2H5mCsCXrhIJ3/JSSwckfwb/up8PriShdmGDh4hCeCFaWA8wojPTWHIcerjhfoYlgREIDz5N0lGRYzRj3qWpQgEGb2kSpYnhG7RlnRle3BN/liHKKPaWFdAuGrjD5JTEIvMt40aSHx7DHpa7Gv5rzEyUtOWRzF7Ss1XkghJ8b/N7GR+FMDdgYN2F11Fap6Txjecf33jJ1yRzxAlyBq5kP0sXTFB6tb0gSw== 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=+rBTqNeMywA3YqEk7Nh/vZKAp1YDQTBwl5ueiIClenY=; b=FJgBb0B0HKeaxKwrumhX8e+x8nMIEC3/zlb+cffXj25sr7/IbOcD15eskBZYoCWGz8ze8e+y0mnPjCNbRg4/3qJEBaMR2+JZd6SIsLKOX4+yxzRsaeTDcEJ2WnOhsXudcR0xqnhjtHawMJCBBK1gbVcH8ojjfFC/C3fgy19jJGwcIUZ1txI/HeXMuKlW8kGX6oTEzt/+YJQs7veCblYX8KE9D/Xb3JP7HIgJiWCL7EogYPansw9eLhxXDZLEXUy8vQO1R+oki2qdI3/hj5oJkoNY8ruFgxtzrVnA+RuYXeu2qiQF3ark+y8zDsAHJJUuFd9Dd9iKfX5RNdqV7tE7YA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kvack.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=+rBTqNeMywA3YqEk7Nh/vZKAp1YDQTBwl5ueiIClenY=; b=oqfYKGdoZGnakZH5ik3/RuuVhWyIo8vAj6DnrGbzR3XFevAFv1TXtylOc4NuP3T6wUHidQBk6ZTmp7Qv4PSf+/XCzTVyqKkBs+s2Otc7HrHyElxFinBYt0szqE13TikYjmWM186VAdFuEV2gSIooxEiZl6eFyAqYmMBNbdvzrwk= Received: from CH2PR11CA0017.namprd11.prod.outlook.com (2603:10b6:610:54::27) by PH0PR12MB8821.namprd12.prod.outlook.com (2603:10b6:510:28d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.16; Sun, 1 Dec 2024 15:39:49 +0000 Received: from CH2PEPF00000145.namprd02.prod.outlook.com (2603:10b6:610:54:cafe::19) by CH2PR11CA0017.outlook.office365.com (2603:10b6:610:54::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.17 via Frontend Transport; Sun, 1 Dec 2024 15:39:49 +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 CH2PEPF00000145.mail.protection.outlook.com (10.167.244.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Sun, 1 Dec 2024 15:39:49 +0000 Received: from tunga.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; Sun, 1 Dec 2024 09:39:41 -0600 From: Raghavendra K T To: , , , , , , , , , , , , , , CC: , , , , , , , , , , Raghavendra K T , Steven Rostedt , "Masami Hiramatsu" , Subject: [RFC PATCH V0 09/10] trace/kmmscand: Add tracing of scanning and migration Date: Sun, 1 Dec 2024 15:38:17 +0000 Message-ID: <20241201153818.2633616-10-raghavendra.kt@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241201153818.2633616-1-raghavendra.kt@amd.com> References: <20241201153818.2633616-1-raghavendra.kt@amd.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000145:EE_|PH0PR12MB8821:EE_ X-MS-Office365-Filtering-Correlation-Id: c18a81a7-b413-4120-3fb7-08dd121e63f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|82310400026|1800799024|36860700013|921020; X-Microsoft-Antispam-Message-Info: +S4vgTk4HYFyPkj3jl3MLxi3ijH2yDRrLPPvtmCALRco9zr0x7ISsDI7V6uVMcfz1+BLMZtNE+J+xRg/P/oTU2Wmks0q995FiWOBLy/KQJcXEAEXX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hUE16r0Vj+WcCNUigX7p4Mf56MMs4SX9/wmw8ffqV8GqOQgtOFTGiCOi/8V0vd3BAENIdDDovN4uSiuzekeMDyr+x5p5Hk/K/mb2YU5qBH9JPF19QFt+qF+18GCqdT/ReDXg6Cev3Te36ujI3bD8uVVWX4kHXHWvvEJBbfkgFHPRjdtywBwrUTK4g4dpsQQVhWB4OXBMLafgfr1gAEbo7IPy1EijSEEo0TB06Mc1Y96sch+0haEFBXiBrPiCqqbMk49ROYOJbfXskLzdx9gD4r8R6Ju7Xd0u64murEVMkuVHzmeiWg== 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)(7416014)(376014)(82310400026)(1800799024)(36860700013)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2024 15:39:49.1542 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c18a81a7-b413-4120-3fb7-08dd121e63f8 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: CH2PEPF00000145.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8821 Add tracing support to track - start and end of scanning. - migration. CC: Steven Rostedt CC: Masami Hiramatsu CC: linux-trace-kernel@vger.kernel.org Signed-off-by: Raghavendra K T --- include/trace/events/kmem.h | 99 +++++++++++++++++++++++++++++++++++++ mm/kmmscand.c | 12 ++++- 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h index b37eb0a7060f..80978d85300d 100644 --- a/include/trace/events/kmem.h +++ b/include/trace/events/kmem.h @@ -9,6 +9,105 @@ #include #include +TRACE_EVENT(kmem_mm_enter, + + TP_PROTO(struct task_struct *t, + struct mm_struct *mm), + + TP_ARGS(t, mm), + + TP_STRUCT__entry( + __array( char, comm, TASK_COMM_LEN ) + __field( struct mm_struct *, mm ) + ), + + TP_fast_assign( + memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + __entry->mm = mm; + ), + + TP_printk("kmmscand: mm_enter comm =%s mm=%p", __entry->comm, __entry->mm) +); + +TRACE_EVENT(kmem_scan_mm_start, + + TP_PROTO(struct task_struct *t, + struct mm_struct *mm), + + TP_ARGS(t, mm), + + TP_STRUCT__entry( + __array( char, comm, TASK_COMM_LEN ) + __field( struct mm_struct *, mm ) + ), + + TP_fast_assign( + memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + __entry->mm = mm; + ), + + TP_printk("kmmscand: scan_mm_start comm =%s mm=%p", __entry->comm, __entry->mm) +); + +TRACE_EVENT(kmem_scan_mm_end, + + TP_PROTO(struct task_struct *t, + struct mm_struct *mm, + unsigned long start, + unsigned long total, + unsigned long scan_size, + unsigned long scan_period), + + TP_ARGS(t, mm, start, total, scan_period, scan_size), + + TP_STRUCT__entry( + __array( char, comm, TASK_COMM_LEN ) + __field( struct mm_struct *, mm ) + __field( unsigned long, start ) + __field( unsigned long, total ) + __field( unsigned long, scan_period ) + __field( unsigned long, scan_size ) + ), + + TP_fast_assign( + memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + __entry->mm = mm; + __entry->start = start; + __entry->total = total; + __entry->scan_period = scan_period; + __entry->scan_size = scan_size; + ), + + TP_printk("kmmscand: scan_mm_end comm =%s mm=%p, start = %ld, total = %ld, scan_period = %ld, scan_size = %ld", + __entry->comm, __entry->mm, __entry->start, + __entry->total, __entry->scan_period, __entry->scan_size) +); + +TRACE_EVENT(kmem_scan_mm_migrate, + + TP_PROTO(struct task_struct *t, + struct mm_struct *mm, + int rc), + + TP_ARGS(t, mm, rc), + + TP_STRUCT__entry( + __array( char, comm, TASK_COMM_LEN ) + __field( struct mm_struct *, mm ) + __field( int, rc ) + ), + + TP_fast_assign( + memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + __entry->mm = mm; + __entry->rc = rc; + ), + + TP_printk("kmmscand: scan_mm_migrate comm =%s mm=%p rc=%d", __entry->comm, + __entry->mm, __entry->rc) +); + + TRACE_EVENT(kmem_cache_alloc, TP_PROTO(unsigned long call_site, diff --git a/mm/kmmscand.c b/mm/kmmscand.c index 682c0523c0b4..70f588a210dd 100644 --- a/mm/kmmscand.c +++ b/mm/kmmscand.c @@ -668,8 +668,10 @@ static void kmmscand_migrate_folio(void) WRITE_ONCE(kmmscand_cur_migrate_mm, info->mm); spin_unlock(&kmmscand_migrate_lock); - if (info->mm) + if (info->mm) { ret = kmmscand_promote_folio(info); + trace_kmem_scan_mm_migrate(info->mm->owner, info->mm, ret); + } /* TBD: encode migrated count here, currently assume folio_nr_pages */ if (!ret) @@ -828,6 +830,9 @@ static unsigned long kmmscand_scan_mm_slot(void) goto outerloop; } + if (mm->owner) + trace_kmem_scan_mm_start(mm->owner, mm); + now = jiffies; /* * Dont scan if : @@ -868,6 +873,10 @@ static unsigned long kmmscand_scan_mm_slot(void) update_mmslot_info = true; + if (mm->owner) + trace_kmem_scan_mm_end(mm->owner, mm, address, total, + mm_slot_scan_period, mm_slot_scan_size); + count_kmmscand_mm_scans(); outerloop: @@ -1020,6 +1029,7 @@ void __kmmscand_enter(struct mm_struct *mm) spin_unlock(&kmmscand_mm_lock); mmgrab(mm); + trace_kmem_mm_enter(mm->owner, mm); if (wakeup) wake_up_interruptible(&kmmscand_wait); }