From patchwork Thu Jan 4 10:05:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bixuan Cui X-Patchwork-Id: 13510967 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="m3r9E6Jk" 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> 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-trace-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: 5VI6kuvt1XyPTNDeprY25thcqBAhTSSUuqWfBPIeH5sIMvI5aSplfyfIwd9eVNhEIKgml0JkFtD3Spu3FJQgpuScfw7CN26MEdEY4b/yy7NDnX7UfH6HW61thWDnh9WySJFKg8GtlXr/v4kXBNFRLibGBF43nIqzVNk/skcFaQ+b1blCeM9zAbyktEJXgxUgM5rF5pZ0eR0H3EKL90wvXg8Wmv6yjX6SbrWHZU7xKBZPaRaPy0b/tOES7n5ntrTh3+6b4A+2tcO7puRDuSAF6kb3m0JXbSZ4ZJ307fs20fiT9cKnUaosuA3hz+5JdGY31b1eG+GzLPEMIN3Q8Gh9rjtxBt1DkBNFS2jJEkzsTEq8ItIYc7Irz66z3jVvoYN+1nQar4c8dRLV74GiGszHsBe0nStAp97L110eUb7XTQvxXRhGivB04KPIPTRXJ0txTPUDxzSvXGVDoI67ORW+ZlSXLDItEn5VgjZpsMutfmjcTbgZFhaBZilCtl0poYqBIP9z4LuRfmC3rptVejeMnaJIaXDs8YXK3AmMwgIgcdN+DblMzgiqV2Aw3lgV7ZitqP2xJYv71/EaST5W0FQACgNebe/GEce/3Ek3qH0OagTt0cxqcUZJQ6UIiCT0mvDJ47ImCJhysmYC6FcQI92N06uVl362kkJZp+807gA+Io7JdyBaNjzOMtIZv+R7CjXDmGclaopa7ZxlE/YrON4SOo74Wv9Y9SsQB6pvPkH5egucmly9RceF9YY+gRPyWBOQxNJkTSpgV08qpxYCuU4SnTOYTyZw5P/b5iwGy4VkaG33K4NXLzkluL0XoJ+WlUsGRDh62tLPTqL/lJbjl1nlTDSJS0Gnp37Tbfe6WkSNmFVVQ51hvdvn8p5pxw3OpUL9U4swB7IihiJu2ub3vMtDfyX6fDnj804O6+2hd9ut/B/WO8ZE+S6sAVkW1pR0kn+Tq61CeLyM2PhD4pKH5Qcb9nNdkF0Sk93aOaXVYlx6a+92UZX7+A4PiSbbbyx/ryG9AxqA0n+OzLetIUMKrvfOj1ntAQ+16rK9OteZ/IVhbTiUcUC9gLtQLTVV96mtQLYKeOtmjvn694chuw3+2/WnJR2EiZiWNxIoAmy8cEmVjeyKLZicty52Ot8Wax+zGQDq2KEgRPfhR6+iGATnuc+tXEnugKuiNnMX6Ls7N15HaZ6OcijM27Ir9r71z0cH9KP/ONiAGvFD+KAWmUd14EiHywa1KxpfTNmfhPGaJXLZ+Pbcw5pMvey8REjr2nma4//4RoUmFs7K0RQj23d/wEdIfYFFxLlvcVmJ72B0s3U5+PtPj5kK3a+UoIil+7Vk+ZgucoujKA8Xh4rGcakUmwryDujGSbwhqLSKVAiXTo/yNszjwgldiax4JNACZJzKVzYxmPYabtD1/VkL7uLoNlmFKG2xxAQhyLI4jan0k3adSRASyO88EY1qB+addEv8khzAvScbL0qbfjlOFcco1Y/2mHL8wJZAjuU5DupJ1XqzPKoAd0mpWC1/Z+dTpnMtJH3EJAeu72wsjxqhyxUsehm2/+8B1/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; From patchwork Thu Jan 4 10:05:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bixuan Cui X-Patchwork-Id: 13510968 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2115.outbound.protection.outlook.com [40.107.215.115]) (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 8827220B3E; Thu, 4 Jan 2024 10:06:11 +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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="ASDfma+S" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dk6MMRFrCHse6wxW3blUSD0e2Big2fixmJ1UAHmj2NauAYEZ5m5+Em8aR0uiCXC3N5Q0mdGRtD4SNkWnPcCcpVwSc/hGtdKpPPHgi9q1BPtHRJQ4oQWuUZbnz9w7dMxmhb3v7U8+FpcwECesgPIfF2p+rXtZhSSvtFvn9cc+eGDrRKAMYPj7rIPe0XJl6hX6Uva0x67mMtZ69/s/3AZ3oodgslDWjG/q3SmDYYGWKGs5jzIFFh7ziYJs6RkX+gLd5lNEbVUtrWUVm/HMt0QA7ySF/kMw3lKKBwR2EGlR0ftHbKdde4gxlYbnxA6vvuS2JEVYB8Y1x5ObWjBhRVvjEA== 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=2aQDjlWhWdpqHlsXM3gl/Zf183I9Y9KyBUkLUpxSWPA=; b=X3MEjiHQaH/6N3Y9Nw1f3axsUlQ+aJuHuKAsOKa/KIWTwHJbhUVG7HoI0WRTKP3Fv2e0QCGEYvJ1OdwH7LUvx88G8yuLFvrNRlkRZ6DKLhXGZsb3OyG/61vo9ML6f0ihKgOu+SVXEAX0X6VJc6wh/sonOZ2U4Xj/pxY7Osh237WFNZDxUeQ8uvFoYf532bP6gi5ddQeEJfeVhMqk2G6rG+P/gonXGeVphs/l0QMN1pnm2UAFpNYaFFA6g042dunMqNiGH417HaboJZp4hbmPDBwh8qrkJrAeJYP9xbRdw4R/K/H6iIrniNbXsRVVpxNz0qXXyh3PNZLV4jzqF2lPzg== 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=2aQDjlWhWdpqHlsXM3gl/Zf183I9Y9KyBUkLUpxSWPA=; b=ASDfma+Ss/rcgeLgjpqVs+4FNNzuJPRHHtH0VTffpdvxCepDvslwu7LF56JXRHlnsbgfkboPTUStKGV5DEC31bm0t0BLuHmwpTXmJy0qleOae7/lWk/m8m0iVEg5PrlV+NcQ0DnR8XhBw/liuftLrQk2xuu0q4oh8PMTv0ulC8Lwtc0945Rb1l+d7yGiE0A8rikFQQFt0ri0ryTXc/1KCFrKAnENs3qdzFA/CqkZbZU8cvsli7prWvpXBxH9kv6MvilExcL09ZADTea+RnEXJMg0HFUjy7hwtKvY8LxSiadhqEC87i1htzmIodY1E3/GPLID2PM/5vvE7ZJhm6QbYw== 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:07 +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:07 +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 2/2] mm: vmscan: add new event to trace shrink lru Date: Thu, 4 Jan 2024 02:05:27 -0800 Message-Id: <20240104100527.3908-3-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> 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-trace-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: 0b435189-8bbd-4a45-2d71-08dc0d0cc49f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0T+KS8kIrF6xFgrZgKqQHW2fUF4g5o7u4DXhJRuWq6tWr9+vBwYvAXnTZyV2YOZAlhWvTnW552vuoMBuJO8D5JHWXtV8oNNc/7SLhL+rqloGjzgAbTFi4psFDQM0bs1KKIDyCoXHezU8nTYoEUCmzjnhXCk/VvYg8ZZ9Ggwa2p04TH/SDFrz86mJuNjI8K++rvag42En3Xrme8DGzQzGmA847cZTvz8XBoSHIywiLC+ZZQL06gi/BWz6pGA4eoF7pPSjd00RGEQCQA9FCB1JgQdW6wr6wPBNuSWZf1/OGDCgp2Rihxi/wbO2bVloROCxWDWBT9bkWTQ/y7cErnnmSPLPuaMr7GDLKsJx7sDsaVg+JygIsN9Lbl3E0VPRNBS5GpMZyB0ZsuYlJkLaeaI9ITk7Dnan33SldV4HZxmzvujWuO4sBV9fxjkJZIRFE5n5RiL8iHZJwI1dMPm8m0lKuLzllXGYkO1xR2TmALfcw+aiW8HgSBTCw7uG6u03BmVDETq8IHzWPm6vIlALEH5ccfuoljPN/wj7dioaOg7eOaBPwrBmPAG65BcSLvGxfL0UpyLhNhJPjEnmfTaSOVACenVwJyUTs4DgL7gZ81CtRCJ0OORZ58GoCDXYHmd6yt6q 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: bb3O8yIKJNXPc6Pt0qG5CCJKOBQ/Cefldv416yvxFtCjnNMXFAzjgffesv7Wo3tTQxcK9BNfEzcknUXNaTpK0pB0B5Qm0h8dJeQUPjOlNDA47ZfNTzE09cC/cZMfZnYmTibacydGhK9nH/Ty+kUp+XFQIP8IpqjyfAewwq4Xnf0lasidkj+JyaLBvIG6mQ42HhNa9MQB6Olw25bPZvxh9/D6iuP49rohXTG+xypfWS87yxnCFBShuwfMX4Eg+c7LQe7wa7g5u3eGPHkQWltLfSCh2CSw6FIiD8Gd27sALyNn9Dk3xWGeYdE7j4lbtbtiXo+AJ6DBgyaCZWNUadgOXPYrxMvzvjT3t1eyRUt685A+72Ck518FgiQJDDNO7SwnLDMINwQTVDW8bWJb2V9kUq7wea6kLRlq9KIYTHlH54F8CRRaCvieyjnKEBBRZq/gk/WnzyFCx2Cheto7oLSIvvYcw+5Mv8EDGPFE4Cn1g2ErYXeIr6SVZm7uw5lZEIEeBKTUjilFik1srZzBc+0jUzu2HGWY7ub45m8qk+dnKzpPrmlwAMpNLMfUEUu6DNuPq4EBHaOGKSBqG9IoSAvt4vLlZ5rOHiuDgftHcjHF6b+XAIzEu4LbTyuivlOLI+Zoa6wsg+II9f+uxlTd+IZlqBNxzmLCRMpQ5PLNpipCNjHHxXXv9w9Es7ubl2sa9ZjfHCabQ4YajHjYnkgBaFjOdl1aboPWkZeIGNRwQqfL09JWbZynPK5uL9y9T3rbW0vSSAWUTQKsSKIDHorZ4s095VywvLhwgbC6FyizXlaeCabbZYS+B4q8+CEteL7RhXLnn0K3c7af9RkSvaDkosLeetznruVaSuvV1+kO/FCGD+IGS6XXVvG7IbqvNFVH9QuneyH3lq+EkZiCL6TfTx7YfItL9X4DYlhQrX/eZSsHn52J5OtapLBExcgahLVhKntDIp7odKycx2vXOFCwxQpOThxkLzfbPH2vT+JV+1pb/CtUnEwqJS75jtP6MTtlg7uMBXBeBPLeoB2sjiCIt8nhP6LgzleUfUmN9x/c1BJQhwZuAT5VRbp0vPz7CHEOm4ZmL3+dMZBrjyhU3Fs3MY6Rug03MJqdO/AqXjTGPT+gMYeIkW860AbqMGA4HTz//a5di0w1WMTmO7OaxqwEzfr5Znv3n4jxvZrUDSgmYkM1vURLH34uFbPEBIrlWCnYRuZNBxPq2GZr//cm+h8AwvE6nJagrfEZ4VgJUWGUM+vePXEggWJGvbGGN8QYn7MWzyFdjHqHfbljh6WsQzf3/B0naEzDND7i9Fio1PezD3b+f4Cn/B0111134r/XkshPvcZN6nxgd9bDoaPO32TUIInXdrCXuI+fShQklw6wJ2jgM06o97QJfvSqcbP8D1lIwXgQQBGoXeumWme7SByRwxNR7YF7/0I7ncfmyFyxY/pJMf0Flu/ZmE4Msqd4jOk559+3r5+qk5dAWDUTuH3mXO3FQRg8S3i940i7xvUP6JB6LV3RuyT3jImSne7iOhlqh2flqY7FRUonmpDxf+UBu2Sz1t0YBD7nRIpjQ7JDSiXkgBwQOD+YdKf3E2ACMQ1GYr4e X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b435189-8bbd-4a45-2d71-08dc0d0cc49f 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:07.1055 (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: Xk4o1tESSayQWLS4Jv7X76j6W3EndV9KT61OXWQJs9inW8fN5so/P4y9dh8KVVjGvNjw8PS3YO0tAaJc+oexjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB5879 From: cuibixuan Page reclaim is an important part of memory reclaim, including: * shrink_active_list(), moves folios from the active LRU to the inactive LRU * shrink_inactive_list(), shrink lru from inactive LRU list Add the new events to calculate the execution time to better evaluate the entire memory recycling ratio. Example of output: kswapd0-103 [007] ..... 1098.353020: mm_vmscan_lru_shrink_active_start: nid=0 kswapd0-103 [007] ..... 1098.353040: mm_vmscan_lru_shrink_active_end: nid=0 nr_taken=32 nr_active=0 nr_deactivated=32 nr_referenced=0 priority=6 flags=RECLAIM_WB_FILE|RECLAIM_WB_ASYNC kswapd0-103 [007] ..... 1098.353040: mm_vmscan_lru_shrink_inactive_start: nid=0 kswapd0-103 [007] ..... 1098.353094: mm_vmscan_lru_shrink_inactive_end: nid=0 nr_scanned=32 nr_reclaimed=0 nr_dirty=0 nr_writeback=0 nr_congested=0 nr_immediate=0 nr_activate_anon=0 nr_activate_file=0 nr_ref_keep=32 nr_unmap_fail=0 priority=6 flags=RECLAIM_WB_ANON|RECLAIM_WB_ASYNC kswapd0-103 [007] ..... 1098.353094: mm_vmscan_lru_shrink_inactive_start: nid=0 kswapd0-103 [007] ..... 1098.353162: mm_vmscan_lru_shrink_inactive_end: nid=0 nr_scanned=32 nr_reclaimed=21 nr_dirty=0 nr_writeback=0 nr_congested=0 nr_immediate=0 nr_activate_anon=0 nr_activate_file=0 nr_ref_keep=11 nr_unmap_fail=0 priority=6 flags=RECLAIM_WB_FILE|RECLAIM_WB_ASYNC Signed-off-by: Bixuan Cui Reviewed-by: Andrew Morton --- 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 | 31 +++++++++++++++++++++++++++++-- mm/vmscan.c | 11 ++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h index b99cd28c9815..4793d952c248 100644 --- a/include/trace/events/vmscan.h +++ b/include/trace/events/vmscan.h @@ -395,7 +395,34 @@ TRACE_EVENT(mm_vmscan_write_folio, show_reclaim_flags(__entry->reclaim_flags)) ); -TRACE_EVENT(mm_vmscan_lru_shrink_inactive, +DECLARE_EVENT_CLASS(mm_vmscan_lru_shrink_start_template, + + TP_PROTO(int nid), + + TP_ARGS(nid), + + TP_STRUCT__entry( + __field(int, nid) + ), + + TP_fast_assign( + __entry->nid = nid; + ), + + TP_printk("nid=%d", __entry->nid) +); + +DEFINE_EVENT(mm_vmscan_lru_shrink_start_template, mm_vmscan_lru_shrink_inactive_start, + TP_PROTO(int nid), + TP_ARGS(nid) +); + +DEFINE_EVENT(mm_vmscan_lru_shrink_start_template, mm_vmscan_lru_shrink_active_start, + TP_PROTO(int nid), + TP_ARGS(nid) +); + +TRACE_EVENT(mm_vmscan_lru_shrink_inactive_end, TP_PROTO(int nid, unsigned long nr_scanned, unsigned long nr_reclaimed, @@ -446,7 +473,7 @@ TRACE_EVENT(mm_vmscan_lru_shrink_inactive, show_reclaim_flags(__entry->reclaim_flags)) ); -TRACE_EVENT(mm_vmscan_lru_shrink_active, +TRACE_EVENT(mm_vmscan_lru_shrink_active_end, TP_PROTO(int nid, unsigned long nr_taken, unsigned long nr_active, unsigned long nr_deactivated, diff --git a/mm/vmscan.c b/mm/vmscan.c index 4e3b835c6b4a..a44d9624d60f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1906,6 +1906,8 @@ static unsigned long shrink_inactive_list(unsigned long nr_to_scan, struct pglist_data *pgdat = lruvec_pgdat(lruvec); bool stalled = false; + trace_mm_vmscan_lru_shrink_inactive_start(pgdat->node_id); + while (unlikely(too_many_isolated(pgdat, file, sc))) { if (stalled) return 0; @@ -1990,7 +1992,7 @@ static unsigned long shrink_inactive_list(unsigned long nr_to_scan, if (file) sc->nr.file_taken += nr_taken; - trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id, + trace_mm_vmscan_lru_shrink_inactive_end(pgdat->node_id, nr_scanned, nr_reclaimed, &stat, sc->priority, file); return nr_reclaimed; } @@ -2028,6 +2030,8 @@ static void shrink_active_list(unsigned long nr_to_scan, int file = is_file_lru(lru); struct pglist_data *pgdat = lruvec_pgdat(lruvec); + trace_mm_vmscan_lru_shrink_active_start(pgdat->node_id); + lru_add_drain(); spin_lock_irq(&lruvec->lru_lock); @@ -2107,7 +2111,7 @@ static void shrink_active_list(unsigned long nr_to_scan, lru_note_cost(lruvec, file, 0, nr_rotated); mem_cgroup_uncharge_list(&l_active); free_unref_page_list(&l_active); - trace_mm_vmscan_lru_shrink_active(pgdat->node_id, nr_taken, nr_activate, + trace_mm_vmscan_lru_shrink_active_end(pgdat->node_id, nr_taken, nr_activate, nr_deactivate, nr_rotated, sc->priority, file); } @@ -4524,9 +4528,10 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap if (list_empty(&list)) return scanned; retry: + trace_mm_vmscan_lru_shrink_inactive_start(pgdat->node_id); reclaimed = shrink_folio_list(&list, pgdat, sc, &stat, false); sc->nr_reclaimed += reclaimed; - trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id, + trace_mm_vmscan_lru_shrink_inactive_end(pgdat->node_id, scanned, reclaimed, &stat, sc->priority, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);