From patchwork Fri Jan 5 01:36:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bixuan Cui X-Patchwork-Id: 13511652 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 AFBEFC47074 for ; Fri, 5 Jan 2024 01:36:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 672396B02EF; Thu, 4 Jan 2024 20:36:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 622B06B02F0; Thu, 4 Jan 2024 20:36:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C5356B02F1; Thu, 4 Jan 2024 20:36:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 348C16B02EF for ; Thu, 4 Jan 2024 20:36:52 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 00DDA803A9 for ; Fri, 5 Jan 2024 01:36:51 +0000 (UTC) X-FDA: 81643543464.25.3584894 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2118.outbound.protection.outlook.com [40.107.117.118]) by imf19.hostedemail.com (Postfix) with ESMTP id A1BFA1A0005 for ; Fri, 5 Jan 2024 01:36:47 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=n4td7H2Q; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf19.hostedemail.com: domain of cuibixuan@vivo.com designates 40.107.117.118 as permitted sender) smtp.mailfrom=cuibixuan@vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704418609; 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:in-reply-to: references:dkim-signature; bh=bv17LkrivSbMKVXvFYW7632InhHiYYKYFcGfDylGxBg=; b=0NOIc+OPEN9aQg0GvWXZy/AG1L/OwWjAJPmO9otISTLD2G2B4tReSKHjVoogcAySYTmgQ7 LlS2cP5vjcq/AZyw13kSGIzAbXbBgOZYRAEnUxeDPz+Vv7GNkCiK20mc5DPuGtiKGlYcN9 E4GJic1xwujme8iHdFA3IoO2BFDe3Sg= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=n4td7H2Q; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf19.hostedemail.com: domain of cuibixuan@vivo.com designates 40.107.117.118 as permitted sender) smtp.mailfrom=cuibixuan@vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1704418609; a=rsa-sha256; cv=pass; b=5NCwICCN9gJZvfnLKvwTUIdKbLZLhHDCal1VcJQRsaA9xrATlgds/P27sHutobOX7Bc6Hh JjCjQBYP2nLGikZdJfvEk6yJZCZ4QFmPa1bs4aU6rYArPpExzJ0k5m0Bx2sRSCX+Zuu/Ys qcWBq1xII+wHUyG42aRKXBnHl5WIghU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UKGSKaTzJQ7UaK+C4+SQ/dvyubegaZ1eZlQzLwbTZOsNHp5aXnChenMIFR0Hnjy1wZbC00GLVU5kdWKrY0GqqC167VzJGZImI/DSsPdeX0Q5QnIEubAJOG+lfXVKk0SlwmIm1eswe5kxvQWT2J+ryFsKxPwMNG+3VKb35RB/zJWvwySaKwL/hv3gKk9zaZYG6zBZ2QdFcSI/AnJnti9gjRmxZgO1WMdwlVB+x7jX3N212WwdQMm8e7LWD/MwIqvAszURDyvUXXKemK8afuk47jVfI/BpdDn3CQlgHjGgILpSoplDNXVmOgqd4HZwZn2uPf08T01CvcqLPnQ48dvSYQ== 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=bv17LkrivSbMKVXvFYW7632InhHiYYKYFcGfDylGxBg=; b=hh+UABoMpkdxUtH5SR+MqOm+p/IUV1X65s6r2c52Ht9w8BQNLYZLumTgXP+i+O3juRkUubiLuBoU62RMX5tGthaqIT1pX2Tg1X2ZZomW/ygVNnxP2ttvlNKv6YsE8sN7qljy63SWhjcexSsELyLFBckkZDv8Na/phWXOcVyqbsdukBtCxQe4k6hopYL1Sd1End9VYksRuZ3WCg2VnBo0r3Nv7ZbQ+dD/vXCvk8W1NZ/Lg3agaGsGKXfwWYY8Ok1Y6mtAsahwQnm6J/DA5hE8CSwG+6sE7V9XjsAlqYg8dIMUgduQ71HX5AX/BSFCueFig1qQ2qJWQmxjLRyHpMQILA== 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=bv17LkrivSbMKVXvFYW7632InhHiYYKYFcGfDylGxBg=; b=n4td7H2QtBtMLjRvFfPbVdO9b/3V9FilDiyrOYoLA4CMo9P0SGedqJ/5bpmiljnM9Cc85M9kaveHYXiz+Qn+Tilx6MaH/glnMvdI57ZS49fi3UdtxX0Gw4mPp9OyqCmv1ILki4f+npj3axMMVP1O3wZkH3ea9d6IurHm5poSygineLM2+dHJIJkYraVZI/3gcxbH6b6WCoAbyLP6G6Ryv8kKxsMl0hc4i6b6ByMOryqP1hQuhv7V+JwI5NqB/YHjAAoBbKHQ4gz7Az0cOz7cJUx8p8gHJ5qRkhMqq8MSfbjP5/Om2PWqDkTTIF0UiysuJ3ZhvYzVP6OzS09iSars8g== Received: from TYZPR06MB4045.apcprd06.prod.outlook.com (2603:1096:400:21::8) by PSAPR06MB4488.apcprd06.prod.outlook.com (2603:1096:301:81::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.16; Fri, 5 Jan 2024 01:36:38 +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.015; Fri, 5 Jan 2024 01:36:38 +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 v6 0/2] Make memory reclamation measurable Date: Thu, 4 Jan 2024 17:36:05 -0800 Message-Id: <20240105013607.2868-1-cuibixuan@vivo.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: SG2PR04CA0169.apcprd04.prod.outlook.com (2603:1096:4::31) To TYZPR06MB4045.apcprd06.prod.outlook.com (2603:1096:400:21::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR06MB4045:EE_|PSAPR06MB4488:EE_ X-MS-Office365-Filtering-Correlation-Id: e1dd43a1-8446-4bf8-12b9-08dc0d8ec296 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S2G7T5/hzmF6Its9uwFFmtN4eF99mgqFqFOknE+FKev1SUQNhrY6BZi+YLKTDtfuWCvPy2v8RQbhRo+z1E8kccc6NTC/6GIYZbTG/NgVvc1I4sQTzT2/HW1uj+LDuqxNt3/pBOOtPmXdaLzZbsUFRdoJyeVHmGap2aNWR4YwZIfKLKPzYo/NEFYhF0lhu6Ckmaty3xgILglbjn2GvyiCKj41eB3TWNtYl4aJ6AxqAw0eUwbPvOgkjwGmEmIqtpbHyvn9djXyRMYb7DXDFFCA6emsvifaSm8I6emCkOEpZpYwgUXbVF+B4qjXi6Pv+YNUKBg2FpjXgvl1Q6WOlewQnXtcs8ELAy47V0AGxMuZNIHycDvqv7eC5e8I7aghP3xk9IG6Zx3km77OIhPl84T46N1iQ4OBo91AoP4aibWeRHwLbE8LyvjszpRqcsZC+iC/KngUc7pJHDs4u79QtKlaWexpk3A/pA/CanpxxpY6OKu1VqTcgBDEMiyyv6TswMaqghcqh+V8jvrtxgsSOwGkDh1+dOm6cEPsNrfg149eMk3SCuDTD5oOZai+pyDw/uc75c4a4FzVxrwmjxn3UshInOLZDJ7CfEQ9bup9I8COTwZqy0eHwpAzEglJW8zbYqrr 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)(396003)(376002)(39850400004)(346002)(230922051799003)(1800799012)(186009)(64100799003)(451199024)(52116002)(26005)(1076003)(6666004)(6486002)(478600001)(6512007)(6506007)(2616005)(83380400001)(107886003)(5660300002)(2906002)(41300700001)(66556008)(316002)(8676002)(8936002)(66476007)(4326008)(38350700005)(66946007)(38100700002)(36756003)(86362001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData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BRNHAmiKwNl2SCPYsRYpUqUuxjTbA0B7M9fJogLGio+YicGR/qtkTC//AFfnXzFmjUFqosq3ZTcGMchf4tvQcKfVAT9sSweyqk0BYmTOycMx192qyZ7XZd0+5xojjIAumHiENRcYD87pfDtJxQgVj+fn3gOeb09IySFHBARtIfGq72liKsmEtvtsStY+NHDZ90yF1/iWvha+zlckr5rGH3C2E6ozjcyO1+lklhn1eRBDVB3CkoYAxyj6vT15BJGG2Z3pALgvsixzhGsw6sq4QFRtg77QDft5QNrzIFQ81hVoaOiJWZH/frAf0He8RFEnravDTjOWPZRzoagCUJFTSsHtCEFbeqTtzgXFqbr4wysxzgQrXpgJnz5p/4VW8zhwrYvtLU6Bi/BXQBYZSSGFJkUhShKB81BnU6yhRC9vhrS2xWK5m4fKB4xCkrIwMoUDLRJzG9KyKi/zUPGh66DlxVZlxozrx/IMY5fsZ7LRx/rqDktTQ2c02F7npGsFIyBnedr3m2wN6w5HW X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1dd43a1-8446-4bf8-12b9-08dc0d8ec296 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB4045.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2024 01:36:38.2530 (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: bR38NH3sxgiXuFqPCwNLnW2QP6xQ2QiKFZOd56lBDimiCEzNGox5nj+CPZt4tuoC9geS7A8ers0PM6NMYgabtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR06MB4488 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A1BFA1A0005 X-Stat-Signature: eijtnfeo783b193m93msu8gtz844j9xk X-Rspam-User: X-H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4KMoUoG0XJr6InsJGiAKee/rEMXyQ3XLmm6dt0HodjViZug55hsPaFxV2ziAlnG42pEyb7xjQ7AgGeznCsbeeLUPe5qE5H7k/wKsw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: v6: * Add Reviewed-by from Steven Rostedt. 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(-)