Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7616312rdb; Thu, 4 Jan 2024 02:06:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IECyR8SoUNWDIfDibD0ltK/JEinKVz4gjsFa6LpZLOm9uNA9ZMPSd9Drg+A+Qhre8BicrDi X-Received: by 2002:a9d:7dd5:0:b0:6dc:50a:cd28 with SMTP id k21-20020a9d7dd5000000b006dc050acd28mr428038otn.62.1704362779284; Thu, 04 Jan 2024 02:06:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704362779; cv=pass; d=google.com; s=arc-20160816; b=WWlMmxqW9pZgIgxVVp02Rw0A3k+ZDZBpfECi15+OpnZc2V3H7kD2it/uTq4U9H85YD 11unh1dc866DeYXpaVWn+f3Hx7MPl6OOj464WX+p1mitGHFd1jbKso4u92FsGT8kr/AJ KRainCtJktp/oX9lmrbSCO4jlP2AD94MJe9sPxZLwzJ2WOoBTKYSSDpwXWnb6uq+v2Xj GmiYEYDN9Gi/TxpP/VNz/qLnypao/hQJayCtRHusj2YAuwDXm5MLWMUbRdPI0HTgiybU jk7v+kBE8sVvn+RDEw7cQLAYcuwyjerFc1DTeNW2LdlEBosNReDRQOvvKt++sMVu9X1B 3mPA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=zsVe3UP4UgK9uHn33EMZpTNhMYGychcd080bxCe9C00=; fh=2HSsn4N1CERFiGILG69mO9UenZHX2CPN9NVZTN2/rP4=; b=mLqkjWVEKtd/K86F2I6usNM1sZskTLJxDVPRgLy1+xISB+I/UIIXQMADgVPxcIQUjf bZ9GuJviCKQH2fC81VRc0DjdWW5BEJwGlJoCQlpM60Ps8dlCVVv1TGK1R1CVxsDUw5Kx TInudAoc4fMCAw8GaSVfURf1G8e8YcF7Jn9uDomjB1hm0MyDLkRjCwxGpwVuXOhRaxxb Tfjcif2wZIfmf3IXOfJ7bG/+BHVFHyeeGvBS0npBKvO4Gx0CVwty7Vtkyh83e1Z7wl9N 2BLIEwTdolx9tUDmG7R9GYw4067US4tJNk6ML+jolmmBHvHRLB2/oRAv0BMpDB1JYNCQ Gx4A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=L8n3rvM3; 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-16482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16482-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p21-20020a056a000a1500b006d96d89c938si23420973pfh.212.2024.01.04.02.06.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 02:06:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=L8n3rvM3; 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-16482-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16482-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4E2BBB21440 for ; Thu, 4 Jan 2024 10:06:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A33C20B0B; Thu, 4 Jan 2024 10:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="L8n3rvM3" 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 8E7EF20B02; Thu, 4 Jan 2024 10:06:05 +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=hpQeRnPGgkSksogS+fBzHmsIHQb+iwZTr1bfbnVIPZ0kB2jpnEZAPkqZ01zCnVkJJoU/inH76Et95fO8k+TP6P94FZSEs0/i2KH+QAfJtK67lDMRSFNycdAX6P83kZcSBnF65UZXfKNlXiNf5GqRbjFQx5Bk9Ey/NuEMqgLFEIChRkaCT/LPdFxJ3IFJTQeg81sQU+BHRgvFHVRf1uKpcRPQfKB94UM84i8OpGeV+JEmzCY4mHf/n9mu3y5lrdGNZ/lhU2ssWHgsb6aB5UiKOrlufiocxsVam8kYShJPrHI7rgH5NSy+nZX9vytul3OXEFpMk/eUHEr6sxmBIi3XkQ== 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=zsVe3UP4UgK9uHn33EMZpTNhMYGychcd080bxCe9C00=; b=U6ZFkiFc9q8rE3N67ndU8QrTE5Twkc6rnKhQuab71bvMPB/hj3eowKmDYnwckoIlQ8dpJRWI6jBCzhWthaG7ImE6nUlCJkCZznDnP9kerq1NpstLB9JwKNekeD9htnISuqNcQ3gZaBymqGXNM65ZgSxLY/nwngYjE6jyzJcIai1KSJLmVZDNV46ZlrdpqFUmlF4Y5OD9VrBjhkqPYxDnw5BOrxIfiJcbWnxpTXi8mXQ1OBwThZMr5tLSFcu2xXJvlSHN43eMlNGURFEbMQ9spQy0J47zXgGT83c+mRWjIybUm3D7h8jicn/qEZQ7YzdQ3Azo7IEtblhNbGst+5PW0g== 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=zsVe3UP4UgK9uHn33EMZpTNhMYGychcd080bxCe9C00=; b=L8n3rvM3t6qm6lkWgIUZXgpdIN8q0y80uQpD2rpe25Z9jKd0P1CCxMSs5F+5R+adGFIEW5EDqQHLs/s6xX9JLRICDpeA0AnOwOsKVk1lK3Wlv6OEqTfwVHWPK0ov9d/nS7pM8TKuS1dcsYoExkvyDS/5zdkZtux2LUQQdKd2BfEqz7SnTmHjZCggvy6MqHgP1nOSCYoeQz9YOoEiycD3C4oSdeOyIkr2t1wwtx4r7R2gqePOwfiOqPzcbUXf/gmO9xeEo/BiAL7KdRxA6GWb4/YaFoBY4gvVbqHCgO/liMcO+V18ZbCfAPgNqEJzI0L0ww42uBkjWJlEhj5x04p/wg== 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:01 +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:01 +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 0/2] Make memory reclamation measurable Date: Thu, 4 Jan 2024 02:05:25 -0800 Message-Id: <20240104100527.3908-1-cuibixuan@vivo.com> X-Mailer: git-send-email 2.17.1 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: 0c6b9e98-a59d-4866-3914-08dc0d0cc128 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YiJMKyfSRwe0Ot1NWzMdddYXSjeuWJVdTOeSIl0IjjDTfaWF+jAQ7c8DTrLVNPyzvAw22B+78PQomaYiGvEiyQoG0aEriEZyaQRtnexMV66KnYL3T9L/wItKoTiEOKVIzpDny+LRJ8VDJkc3IMW6a5iz8DJhZ2hDYauTKQee3mNiFpj5wvc8vpHZt/TlKaoUj2jl9Dz9moGbRwyvzsdZeWmXSKR4JZl/DH2lP5fOKADTMcmeb6aGkjHhlHbeHeGeIyN+gzspGEkshRJFfNaV86siuVU9kFapgxiMfjaa2aKXAC8XTjUcl7854QQDhufvzwYmKv5v9sxdboVWhExqkhxmMrYgAPQLuWSgL6x8Q+sVhEGa7P1F8PbCGYASb1VoGC42Vzzrw88p1QkF4hPhVGjGxz3NBypk4inYGVYIfyZSlLh4J1tKEeuooAaD4tY5gM3Y5uD60KAwfUiIVkeEDR7wjkhcqm5wcMqu8RrXfEN/yKdXf/OKCquHkRNW1EoOrsg0SQf7QV821lm2PocT4YP6aZUD8iJFM0O3NXyVHwzjKtxvAejAnso/TdivxvFUzh7STekQYdgz66GYEMHCpgzO1m7xCQteYpweuQQhR+xSZJzEFVIvERmH20+8vfbk 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);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0luzV+Icj6u23Q4lyciz4F2DeayqpJhpV7U3KByrbVAenOSbj0L3d6+hLHlk?= =?us-ascii?Q?Hu0u6/8B3LBU9tUSip6z4R8H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q?Hw2Petljw7aZbTF0Q9dj4r70x1/USwQYEwW4AlwcHzO/vWO/m+92wYPOL1ai?= =?us-ascii?Q?2AX0aMw0EG7gQeuRgVu3As6qsI+Rejmhn8M3zUISuyTOrrRkracOxV2Uu8EK?= =?us-ascii?Q?JgCFsHk19fP7oya1fnfqZogEd8w6Ccscrcz7CcPcOXHjKeCm6lga+0MXCI2O?= =?us-ascii?Q?jQcY92g3mrIOPwFk0rg61DT7aW2PLDwCoEeSoQ36ISMtzHuyY/daOMTbby0z?= =?us-ascii?Q?LcUKuR/WpXgB1rKkv71kvDH1oJSYOVLSwkW2nuxfZga0oBb+Irp/RxGKE9SG?= =?us-ascii?Q?n43BE/hIM+p5EWOM7paZiUGfuM72T1cxxaJtD2ttzKcGeJ/jq3h/JZgvhmQD?= =?us-ascii?Q?gcJx0p/3B/YX/IOq1Mt02N0+WAboY98uBzCxRxrjaN8jglhLP9q/7hGBGU6F?= =?us-ascii?Q?5ztnsVqqVq3yq4iKF5Xii66Q5A/hKy77ZSmTobbOn3Oapy084dNvJJJGsoEz?= =?us-ascii?Q?sTtLt2xFNdhgUZmZrdxd8A/pBFcBkC4qOXa3ztdHV1gofaos8ISpdel2Nws5?= =?us-ascii?Q?8u+h5Q/KMKMJkHl8IJHZvGHP3Tm3yGVuaaKsqbyZy8CrxrU34u27ress6Der?= =?us-ascii?Q?rYPCGA834psS+xuLYcvl0t2w9XreuWe5kYf1IcU+?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c6b9e98-a59d-4866-3914-08dc0d0cc128 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:01.7166 (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: xSX6LT5gd/9LChbG7diqDdWH3/vnVgBEyH2XV07fTw6UBMS+nneppFTtvtnM8gWko9digxkIGRUsuCw/rGcusA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB5879 When the system memory is low, kswapd reclaims the memory. The key steps of memory reclamation include 1.shrink_lruvec * shrink_active_list, moves folios from the active LRU to the inactive LRU * shrink_inactive_list, shrink lru from inactive LRU list 2.shrink_slab * shrinker->count_objects(), calculates the freeable memory * shrinker->scan_objects(), reclaims the slab memory The existing tracers in the vmscan are as follows: --do_try_to_free_pages --shrink_zones --trace_mm_vmscan_node_reclaim_begin (tracer) --shrink_node --shrink_node_memcgs --trace_mm_vmscan_memcg_shrink_begin (tracer) --shrink_lruvec --shrink_list --shrink_active_list --trace_mm_vmscan_lru_shrink_active (tracer) --shrink_inactive_list --trace_mm_vmscan_lru_shrink_inactive (tracer) --shrink_active_list --shrink_slab --do_shrink_slab --shrinker->count_objects() --trace_mm_shrink_slab_start (tracer) --shrinker->scan_objects() --trace_mm_shrink_slab_end (tracer) --trace_mm_vmscan_memcg_shrink_end (tracer) --trace_mm_vmscan_node_reclaim_end (tracer) If we get the duration and quantity of shrink lru and slab, then we can measure the memory recycling, as follows Measuring memory reclamation with bpf: LRU FILE: CPU COMM ShrinkActive(us) ShrinkInactive(us) Reclaim(page) 7 kswapd0 26 51 32 7 kswapd0 52 47 13 SLAB: CPU COMM OBJ_NAME Count_Dur(us) Freeable(page) Scan_Dur(us) Reclaim(page) 1 kswapd0 super_cache_scan.cfi_jt 2 341 3225 128 7 kswapd0 super_cache_scan.cfi_jt 0 2247 8524 1024 7 kswapd0 super_cache_scan.cfi_jt 2367 0 0 0 For this, add the new tracer to shrink_active_list/shrink_inactive_list and shrinker->count_objects(). 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. cuibixuan (2): mm: shrinker: add new event to trace shrink count mm: vmscan: add new event to trace shrink lru include/trace/events/vmscan.h | 80 ++++++++++++++++++++++++++++++++++- mm/shrinker.c | 4 ++ mm/vmscan.c | 11 +++-- 3 files changed, 90 insertions(+), 5 deletions(-) -- 2.17.1