Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7616424rdb; Thu, 4 Jan 2024 02:06:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9PalVseJaGmqO/gDUvYSEvDQXAhm73e8oVvUf134WguDbvAwTP/j2JfNIyk4ROwH/xZ1Y X-Received: by 2002:a17:906:dfc6:b0:a28:ba8e:ac47 with SMTP id jt6-20020a170906dfc600b00a28ba8eac47mr188803ejc.113.1704362790452; Thu, 04 Jan 2024 02:06:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704362790; cv=pass; d=google.com; s=arc-20160816; b=E3iEWsYrAQezP3lf5GS1PyvAJzk3RfP3f4+mPip40lkds4MUdtLTIG+1yU+9jltI7l AbiR5VlweOJmVWsGYTXJEtyjlNzdO9IXTDVsz6a0aXGeMlfKmUy1ei4iD4I0aDyfZOch IIUG+ZYLowd2DUopG1cnwqhpachmuQQIhjT/mO35km4vBdlvHRHwN8bNEF7/MvKQUXhW HWPFWKHd2U83eszfCjmhucRrNm6V7AXslzoGSkbuY2P+/mV8UgXIoBOR4nFG2YCqttqP odFZhLRRzAE0DXgNVTMaasy5sge/gxW1SMTQfTo3VH7/nEavasJmCW/8kN78GS/zHdes PvvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9IyphLw1z3cXak/6N1bG1g+lJjhfGiAfu9pfQ+cF3bs=; fh=2HSsn4N1CERFiGILG69mO9UenZHX2CPN9NVZTN2/rP4=; b=k6qJi53VQf9pkiYFlETgiG8LSspFVxdqVJs6HcRQ3bwa7CYEKcwAR6F+ymZ48VHjTU 9XtzIiu0D9GGUw1ErMmptLF/hw6Jqm8WtQH79EFfP54gy2niBf2cm0vg54GYeJ/P9NMg 8RjnabZs8dQtr7K7ZQKLxTNH1jBHvc4qm3eSxK7d3i2Kiau4YTmGqrQxm/j9zOtT1qCQ vssitDAVErfXyC64Ll3CQHWbVFDFgR4q1xiGxNoCAl3kNKbgikKuDohUcjYQQXuhlbHX UnfWggGhwqiNSZp1v/16tMJeW4+RxZ3py3ndZYSa/OrSq2jwdZxu9IfEXJyYvAxg7SdM IyZQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=m3r9E6Jk; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel+bounces-16483-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16483-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r9-20020a170906a20900b00a26db4e6239si9928820ejy.510.2024.01.04.02.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 02:06:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16483-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=m3r9E6Jk; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel+bounces-16483-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16483-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 903F41F24D41 for ; Thu, 4 Jan 2024 10:06:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 239E820B29; Thu, 4 Jan 2024 10:06:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="m3r9E6Jk" X-Original-To: linux-kernel@vger.kernel.org Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2124.outbound.protection.outlook.com [40.107.215.124]) (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 AD64A20B05; Thu, 4 Jan 2024 10:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hPNjVylKPHZY2/gh2jdiJlq8LvOprJoGWtlrZwm/NVDAroTF9DCRhDGfQgMhHuWlGHXX+8eShBAaRKlssFEv/vO518ZAzHTn3NJeoN6TwKro9GpGk5wRrOOCwJigdGm/WtRH2pkfxZrgp6TczBHmLupHG9ejMLFPEfY2z7I19AEaijqnfHE0LqqetvnrXkCaZNSXKYdx/88vqpr6+7f536//xb8qAOJsFxwtHYKETurpnXzOiDMuT57BcJV7cic4NrVzNVrVXvWaD+j0zlJe/uEM6ZQJtOf9aAbgsk6zhNLDrmI5Q3sSfUwjqIpscbIdzHJiYN+Y0IGvAwpXuIfj7g== 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=9IyphLw1z3cXak/6N1bG1g+lJjhfGiAfu9pfQ+cF3bs=; b=IMMPEYIi3Zq/yG2GpUYJCjl1yK4Xb3MBhk3kEfdtaNe7WOzFM/ywRubTTpiUkN4nPf26qfG0DEHtGYf9MHx5KD8vAGxqYS03PHnJIHpAeMWH5aj22v4IPr3taM+nrqx+hi4jbsX9L6bmp9dtLvp8f5sHJkKXI5borjtTFZ+gg8FbHfh+KvMBezeu2LCtFK4Gtmd+06RWwv8glWhVFkPaH1rBz654rItWHx0g2YocEYbE2rIrVKcLngoE2yVQY3XcCVVAEUZjz4G5I1frW68/06oNEuLfJV2jaThHlBV1i81BRjkB2eznfAIHsQ9hz4YwJmENZaeCp6g6UT+DrwQIfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9IyphLw1z3cXak/6N1bG1g+lJjhfGiAfu9pfQ+cF3bs=; b=m3r9E6JkkFQGW7cVOoPKTwm7K3CprDFnPO3PJPnfAmw6m0ZN0t+VjrC1NQiZzSLbo6sVFlW6C5PAnUNzrCpxrYwa66A8cXQtf+IhfcbJ85AUetU96SHibcMIwJBqrqKxKyi9V4rYNCU6hIDkTglfybiUDA5a5iLAHLg28k+5o9JLjExSZOyFbYyzLQsb+tavU9B/O7egWDCM5ceJpHqUyPtQWoUX7UPUXgJ4oXecvDaPKKlfWIaFzuRpQ2mDVAJ08eXJCl1ZRGtTNXKcUuFpLGntE0fNbWLH8xIlFlV9tZKfpyH4WqrnYTIcytLGXDtLCW5j5ineYzq6gVU+0MkwkQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from TYZPR06MB4045.apcprd06.prod.outlook.com (2603:1096:400:21::8) by SEZPR06MB5879.apcprd06.prod.outlook.com (2603:1096:101:e4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.25; Thu, 4 Jan 2024 10:06:04 +0000 Received: from TYZPR06MB4045.apcprd06.prod.outlook.com ([fe80::9925:32d7:c818:3c5]) by TYZPR06MB4045.apcprd06.prod.outlook.com ([fe80::9925:32d7:c818:3c5%7]) with mapi id 15.20.7159.013; Thu, 4 Jan 2024 10:06:04 +0000 From: Bixuan Cui To: akpm@linux-foundation.org, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org, opensource.kernel@vivo.com, cuibixuan@vivo.com Subject: [PATCH -next v5 1/2] mm: shrinker: add new event to trace shrink count Date: Thu, 4 Jan 2024 02:05:26 -0800 Message-Id: <20240104100527.3908-2-cuibixuan@vivo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240104100527.3908-1-cuibixuan@vivo.com> References: <20240104100527.3908-1-cuibixuan@vivo.com> Content-Type: text/plain X-ClientProxiedBy: TYCP286CA0316.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3b7::9) To TYZPR06MB4045.apcprd06.prod.outlook.com (2603:1096:400:21::8) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR06MB4045:EE_|SEZPR06MB5879:EE_ X-MS-Office365-Filtering-Correlation-Id: a8ebebcc-4f1c-4658-0059-08dc0d0cc311 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UMeqyndD6UgRtw30GhUVIxWHAL/0f/7rMFvICYW4/XVmU2M6H6TwVm62GIiqdzfPr5BN8GdB16JM9UhM5P0OAxOgzjeapnA/zbzIzSw9qepyaAgS2hWevFmg2HhmmDjL7XLF68exDy54SPpaQlRoi8KCXqE0Gs1C3s0xp/C/i8zT0CSVP0fvR/ZJQVGVOcldQ0LOYwrK1JqO/srf2pTRk21fGu0itgBLggTYUT9V+ZM/kUO59p/6KB1Rl1PoiSGmm8e/4U0OJq9kSXF+XfL8GH3gvFZgyvH67PiD2jfqjDGcqoj5vONODWkmwcKGnpsiDN/HrReQ1K9Q3VICcURcezkAY+SYj7/ic2vUFZRmDrXV0tyhoVzxMgjHHlOgeOpCE4o0ZWiiB897oTOdsO2Wn4HKFCr6B9elrlqdf+L7JWjdL1RtYRvfPlq1iGyePzIOHiPr+iQR91jgtIyjMAkCt14psQu8+rSiwvU0fvTq/VQLG4YmQY+1YrttCI+zFQ6KQMf3yy+KMYdj7665Yf8OgH4xLw4tA+SbxK9X2xEZR7aSekfD/PaJtFWIQy81iIuUCNZHPhu4L+xXNn6qukZIT6whYDgNYXmrdV+cfY0wkRjvOzFEfrg8py11mB08i8US X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYZPR06MB4045.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(136003)(346002)(396003)(39860400002)(376002)(230922051799003)(1800799012)(451199024)(186009)(64100799003)(26005)(1076003)(5660300002)(107886003)(83380400001)(2616005)(2906002)(8676002)(8936002)(41300700001)(316002)(38100700002)(4326008)(6666004)(478600001)(52116002)(6486002)(6512007)(6506007)(66556008)(66946007)(86362001)(66476007)(38350700005)(36756003)(40140700001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?5VI6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OpUL9U4sw?= =?us-ascii?Q?B7IihiJu2ub3vMtDfyX6fDnj804O6+2hd9ut/B/WO8ZE+S6sAVkW1pR0kn+T?= =?us-ascii?Q?q61CeLyM2PhD4pKH5Qcb9nNdkF0Sk93aOaXVYlx6a+92UZX7+A4PiSbbbyx/?= =?us-ascii?Q?ryG9AxqA0n+OzLetIUMKrvfOj1ntAQ+16rK9OteZ/IVhbTiUcUC9gLtQLTVV?= =?us-ascii?Q?96mtQLYKeOtmjvn694chuw3+2/WnJR2EiZiWNxIoAmy8cEmVjeyKLZicty52?= =?us-ascii?Q?Ot8Wax+zGQDq2KEgRPfhR6+iGATnuc+tXEnugKuiNnMX6Ls7N15HaZ6OcijM?= =?us-ascii?Q?27Ir9r71z0cH9KP/ONiAGvFD+KAWmUd14EiHywa1KxpfTNmfhPGaJXLZ+Pbc?= =?us-ascii?Q?w5pMvey8REjr2nma4//4RoUmFs7K0RQj23d/wEdIfYFFxLlvcVmJ72B0s3U5?= =?us-ascii?Q?+PtPj5kK3a+UoIil+7Vk+ZgucoujKA8Xh4rGcakUmwryDujGSbwhqLSKVAiX?= =?us-ascii?Q?To/yNszjwgldiax4JNACZJzKVzYxmPYabtD1/VkL7uLoNlmFKG2xxAQhyLI4?= =?us-ascii?Q?jan0k3adSRASyO88EY1qB+addEv8khzAvScbL0qbfjlOFcco1Y/2mHL8wJZA?= =?us-ascii?Q?juU5DupJ1XqzPKoAd0mpWC1/Z+dTpnMtJH3EJAeu72wsjxqhyxUsehm2/+8B?= =?us-ascii?Q?1/xf/Y/AH1nZW1OAESXYJaAZ1FOAUNQ6JHDDiR9k?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a8ebebcc-4f1c-4658-0059-08dc0d0cc311 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB4045.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2024 10:06:04.5212 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SP5dnoo/goEQGCrYq95D+aU+UaQa3w1v9+KFaxHhDm8qEJZaHuKbEKdwLyxwx2S2pVmmQw2W7tvSPwrdLLp/Fw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB5879 From: cuibixuan do_shrink_slab() calculates the freeable memory through shrinker->count_objects(), and then reclaims the memory through shrinker->scan_objects(). When reclaiming memory, shrinker->count_objects() takes a certain amount of time: Fun spend(us) ext4_es_count 4302 ext4_es_scan 12 super_cache_count 4195 super_cache_scan 2103 Therefore, adding the trace event to count_objects() can more accurately obtain the time taken for slab memory recycling. Example of output: kswapd0-103 [003] ..... 1098.317942: mm_shrink_count_start: kfree_rcu_shrink_count.cfi_jt+0x0/0x8 00000000c540ff51: nid: 0 kswapd0-103 [003] ..... 1098.317951: mm_shrink_count_end: kfree_rcu_shrink_count.cfi_jt+0x0/0x8 00000000c540ff51: nid: 0 freeable:36 Signed-off-by: Bixuan Cui Reviewed-by: Steven Rostedt --- Changes: v5: * Use 'DECLARE_EVENT_CLASS(mm_vmscan_lru_shrink_start_template' to replace 'RACE_EVENT(mm_vmscan_lru_shrink_inactive/active_start' * Add the explanation for adding new shrink lru events into 'mm: vmscan: add new event to trace shrink lru' v4: * Add Reviewed-by and Changlog to every patch. v3: * Swap the positions of 'nid' and 'freeable' to prevent the hole in the trace event. v2: * Modify trace_mm_vmscan_lru_shrink_inactive() in evict_folios() at the same time to fix build error (Andrew pointed out). include/trace/events/vmscan.h | 49 +++++++++++++++++++++++++++++++++++ mm/shrinker.c | 4 +++ 2 files changed, 53 insertions(+) diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h index 1a488c30afa5..b99cd28c9815 100644 --- a/include/trace/events/vmscan.h +++ b/include/trace/events/vmscan.h @@ -196,6 +196,55 @@ DEFINE_EVENT(mm_vmscan_direct_reclaim_end_template, mm_vmscan_memcg_softlimit_re ); #endif /* CONFIG_MEMCG */ +TRACE_EVENT(mm_shrink_count_start, + TP_PROTO(struct shrinker *shr, struct shrink_control *sc), + + TP_ARGS(shr, sc), + + TP_STRUCT__entry( + __field(struct shrinker *, shr) + __field(void *, shrink) + __field(int, nid) + ), + + TP_fast_assign( + __entry->shr = shr; + __entry->shrink = shr->count_objects; + __entry->nid = sc->nid; + ), + + TP_printk("%pS %p: nid: %d", + __entry->shrink, + __entry->shr, + __entry->nid) +); + +TRACE_EVENT(mm_shrink_count_end, + TP_PROTO(struct shrinker *shr, struct shrink_control *sc, long freeable), + + TP_ARGS(shr, sc, freeable), + + TP_STRUCT__entry( + __field(struct shrinker *, shr) + __field(void *, shrink) + __field(long, freeable) + __field(int, nid) + ), + + TP_fast_assign( + __entry->shr = shr; + __entry->shrink = shr->count_objects; + __entry->freeable = freeable; + __entry->nid = sc->nid; + ), + + TP_printk("%pS %p: nid: %d freeable:%ld", + __entry->shrink, + __entry->shr, + __entry->nid, + __entry->freeable) +); + TRACE_EVENT(mm_shrink_slab_start, TP_PROTO(struct shrinker *shr, struct shrink_control *sc, long nr_objects_to_shrink, unsigned long cache_items, diff --git a/mm/shrinker.c b/mm/shrinker.c index dd91eab43ed3..d0c7bf61db61 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -379,7 +379,11 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, : SHRINK_BATCH; long scanned = 0, next_deferred; + trace_mm_shrink_count_start(shrinker, shrinkctl); + freeable = shrinker->count_objects(shrinker, shrinkctl); + + trace_mm_shrink_count_end(shrinker, shrinkctl, freeable); if (freeable == 0 || freeable == SHRINK_EMPTY) return freeable; -- 2.17.1