From patchwork Wed Nov 1 10:28:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Rokosov X-Patchwork-Id: 160509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:abcd:0:b0:403:3b70:6f57 with SMTP id f13csp315420vqx; Wed, 1 Nov 2023 03:30:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8/IwpgqQRvZfLLZ/uUgncGjl2pBNzTd+R/VjxKfvQbiktl7UV8H/8L1RuiG98rhT9DsEC X-Received: by 2002:a05:6358:e497:b0:168:e887:2646 with SMTP id by23-20020a056358e49700b00168e8872646mr17846142rwb.29.1698834650348; Wed, 01 Nov 2023 03:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698834650; cv=none; d=google.com; s=arc-20160816; b=qM0lexoKpgPRhBO4tG7DRWWcOWw+x2tB8mN3wSYNSeK5p1mv1GO5Ie85I4cCBhFthU mMHvtMk/swf0NaD/EPTi58u+JlMpn8bjP15fuxsIyEHSJlObRYfavwazIPeJ0bLRGFrd ZGyZ83wiZCGyZB7OQeTzcgSd/XbR7bLow0xzBi4hCqc69cAt0+QqGdQrn2NovcxLH+3k 1pk8fk7yFQIyuaNIN6Nhjs4+cZ+RrZ2BDEdGZLEmjkWsl3hU0kNBRbK6UM7iWPIqpEGA 66dtSN3pGWk6y9KQjNbxN43n4qfVRQgyd+/qaMZ6K/D2svTWjzSu3mVEQNBG8XwZZuaa NrKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=zCPacf57FSqxrGG9gY+g6RYvl7Lu5qlKOE+d98c3Zi0=; fh=0+l72ck3kOAs3cMd/mEkI3DSRNpPfi1ydrq5QwtlmRc=; b=sOwKZT20bPrijTr7BGQpb8XuFJ0kfpwTYcCxjw3a0pzc6KYthlOgUaLsjOu88OQrUg eDx8eTPV01OPekguGOb13Yl6y4GSVMJygvWt9eSDQSqh0Decagv+x48hNP/q5D/cXn75 Tk4BElCc2goWsdZuVooOP61ojkcVd4QqsNaOKm/jATasvPGTrnkcjVfdMar5filjJa++ pvFgN8y7nHcOshlPNVXonJIsirmhTdpghY4ufFeTKAytbMwp06ch/zV440TsGzosbj99 3H7H8uF9NnIzFo/Fjv+BCDLBR/rg0O7SuB+6uRnTkqpZlpB1KVkOHzd1dl26zufTtR2l HaVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=ITydPT6H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id a25-20020a656419000000b005777bea0b6asi2741440pgv.859.2023.11.01.03.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 03:30:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=ITydPT6H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 903B28082DC2; Wed, 1 Nov 2023 03:30:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235128AbjKAK3I (ORCPT + 35 others); Wed, 1 Nov 2023 06:29:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235112AbjKAK3C (ORCPT ); Wed, 1 Nov 2023 06:29:02 -0400 Received: from mx1.sberdevices.ru (mx1.sberdevices.ru [37.18.73.165]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6246E92; Wed, 1 Nov 2023 03:28:52 -0700 (PDT) Received: from p-infra-ksmg-sc-msk01 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 4CE2E100002; Wed, 1 Nov 2023 13:28:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 4CE2E100002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1698834530; bh=zCPacf57FSqxrGG9gY+g6RYvl7Lu5qlKOE+d98c3Zi0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=ITydPT6H7oESdjce3b3rVNtP7ZXGiAvh+dWNOoFyzXQJicTPbAogyAoNAz7Sxqjep AldIYSpxJUJUphdHnjU6LdtQH3ywy+ljT9eg2o9EwnGArrvT5dAvnJ2+4OP5A3nkmA NJJxW8g0y9Qt+pzRuExNKn2Xj2ZEQ+7+C8y7MbFRU4btr7AAypM9j7dY3j2Rd37CzV G3SmTEmFjCh8SNS2mw9BcgU3n10ulMxSLUylPS0H+ii2buOQEPRilKPxFLLXWphyHv Jy4MiYmndJBkS0wgngoBkA7rmyk+IM3JmVpa6KvmwPSe5sm7hR5V7W2xTp3559i+N5 M3jEfjV7/rVmQ== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Wed, 1 Nov 2023 13:28:50 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Wed, 1 Nov 2023 13:28:49 +0300 From: Dmitry Rokosov To: , , , , , , , CC: , , , , , , Dmitry Rokosov Subject: [PATCH v1 1/2] mm: memcg: print out cgroup name in the memcg tracepoints Date: Wed, 1 Nov 2023 13:28:36 +0300 Message-ID: <20231101102837.25205-2-ddrokosov@salutedevices.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20231101102837.25205-1-ddrokosov@salutedevices.com> References: <20231101102837.25205-1-ddrokosov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 181040 [Nov 01 2023] X-KSMG-AntiSpam-Version: 6.0.0.2 X-KSMG-AntiSpam-Envelope-From: ddrokosov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 543 543 1e3516af5cdd92079dfeb0e292c8747a62cb1ee4, {Tracking_from_domain_doesnt_match_to}, salutedevices.com:7.1.1;p-i-exch-sc-m01.sberdevices.ru:5.0.1,7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;127.0.0.199:7.1.2;100.64.160.123:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/11/01 06:18:00 #22376334 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 01 Nov 2023 03:30:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781357242477147151 X-GMAIL-MSGID: 1781357242477147151 Sometimes it is necessary to understand in which memcg tracepoint event occurred. The function cgroup_name() is a useful tool for this purpose. To integrate cgroup_name() into the existing memcg tracepoints, this patch introduces a new tracepoint template for the begin() and end() events, utilizing static __array() to store the cgroup name. Signed-off-by: Dmitry Rokosov --- include/trace/events/vmscan.h | 77 +++++++++++++++++++++++++++++------ mm/vmscan.c | 8 ++-- 2 files changed, 69 insertions(+), 16 deletions(-) diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h index d2123dd960d5..124bc22866c8 100644 --- a/include/trace/events/vmscan.h +++ b/include/trace/events/vmscan.h @@ -141,19 +141,47 @@ DEFINE_EVENT(mm_vmscan_direct_reclaim_begin_template, mm_vmscan_direct_reclaim_b ); #ifdef CONFIG_MEMCG -DEFINE_EVENT(mm_vmscan_direct_reclaim_begin_template, mm_vmscan_memcg_reclaim_begin, - TP_PROTO(int order, gfp_t gfp_flags), +DECLARE_EVENT_CLASS(mm_vmscan_memcg_reclaim_begin_template, - TP_ARGS(order, gfp_flags) + TP_PROTO(const struct mem_cgroup *memcg, int order, gfp_t gfp_flags), + + TP_ARGS(memcg, order, gfp_flags), + + TP_STRUCT__entry( + __field(int, order) + __field(unsigned long, gfp_flags) + __array(char, name, NAME_MAX + 1) + ), + + TP_fast_assign( + __entry->order = order; + __entry->gfp_flags = (__force unsigned long)gfp_flags; + cgroup_name(memcg->css.cgroup, + __entry->name, + sizeof(__entry->name)); + ), + + TP_printk("memcg=%s order=%d gfp_flags=%s", + __entry->name, + __entry->order, + show_gfp_flags(__entry->gfp_flags)) ); -DEFINE_EVENT(mm_vmscan_direct_reclaim_begin_template, mm_vmscan_memcg_softlimit_reclaim_begin, +DEFINE_EVENT(mm_vmscan_memcg_reclaim_begin_template, mm_vmscan_memcg_reclaim_begin, - TP_PROTO(int order, gfp_t gfp_flags), + TP_PROTO(const struct mem_cgroup *memcg, int order, gfp_t gfp_flags), - TP_ARGS(order, gfp_flags) + TP_ARGS(memcg, order, gfp_flags) +); + +DEFINE_EVENT(mm_vmscan_memcg_reclaim_begin_template, mm_vmscan_memcg_softlimit_reclaim_begin, + + TP_PROTO(const struct mem_cgroup *memcg, int order, gfp_t gfp_flags), + + TP_ARGS(memcg, order, gfp_flags) ); + #endif /* CONFIG_MEMCG */ DECLARE_EVENT_CLASS(mm_vmscan_direct_reclaim_end_template, @@ -181,19 +209,44 @@ DEFINE_EVENT(mm_vmscan_direct_reclaim_end_template, mm_vmscan_direct_reclaim_end ); #ifdef CONFIG_MEMCG -DEFINE_EVENT(mm_vmscan_direct_reclaim_end_template, mm_vmscan_memcg_reclaim_end, - TP_PROTO(unsigned long nr_reclaimed), +DECLARE_EVENT_CLASS(mm_vmscan_memcg_reclaim_end_template, - TP_ARGS(nr_reclaimed) + TP_PROTO(const struct mem_cgroup *memcg, unsigned long nr_reclaimed), + + TP_ARGS(memcg, nr_reclaimed), + + TP_STRUCT__entry( + __field(unsigned long, nr_reclaimed) + __array(char, name, NAME_MAX + 1) + ), + + TP_fast_assign( + __entry->nr_reclaimed = nr_reclaimed; + cgroup_name(memcg->css.cgroup, + __entry->name, + sizeof(__entry->name)); + ), + + TP_printk("memcg=%s nr_reclaimed=%lu", + __entry->name, + __entry->nr_reclaimed) ); -DEFINE_EVENT(mm_vmscan_direct_reclaim_end_template, mm_vmscan_memcg_softlimit_reclaim_end, +DEFINE_EVENT(mm_vmscan_memcg_reclaim_end_template, mm_vmscan_memcg_reclaim_end, - TP_PROTO(unsigned long nr_reclaimed), + TP_PROTO(const struct mem_cgroup *memcg, unsigned long nr_reclaimed), - TP_ARGS(nr_reclaimed) + TP_ARGS(memcg, nr_reclaimed) ); + +DEFINE_EVENT(mm_vmscan_memcg_reclaim_end_template, mm_vmscan_memcg_softlimit_reclaim_end, + + TP_PROTO(const struct mem_cgroup *memcg, unsigned long nr_reclaimed), + + TP_ARGS(memcg, nr_reclaimed) +); + #endif /* CONFIG_MEMCG */ TRACE_EVENT(mm_shrink_slab_start, diff --git a/mm/vmscan.c b/mm/vmscan.c index 1080209a568b..4309eaf188b4 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -7088,7 +7088,7 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) | (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK); - trace_mm_vmscan_memcg_softlimit_reclaim_begin(sc.order, + trace_mm_vmscan_memcg_softlimit_reclaim_begin(memcg, sc.order, sc.gfp_mask); /* @@ -7100,7 +7100,7 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, */ shrink_lruvec(lruvec, &sc); - trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed); + trace_mm_vmscan_memcg_softlimit_reclaim_end(memcg, sc.nr_reclaimed); *nr_scanned = sc.nr_scanned; @@ -7134,13 +7134,13 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, struct zonelist *zonelist = node_zonelist(numa_node_id(), sc.gfp_mask); set_task_reclaim_state(current, &sc.reclaim_state); - trace_mm_vmscan_memcg_reclaim_begin(0, sc.gfp_mask); + trace_mm_vmscan_memcg_reclaim_begin(memcg, 0, sc.gfp_mask); noreclaim_flag = memalloc_noreclaim_save(); nr_reclaimed = do_try_to_free_pages(zonelist, &sc); memalloc_noreclaim_restore(noreclaim_flag); - trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed); + trace_mm_vmscan_memcg_reclaim_end(memcg, nr_reclaimed); set_task_reclaim_state(current, NULL); return nr_reclaimed; From patchwork Wed Nov 1 10:28:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Rokosov X-Patchwork-Id: 160508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:abcd:0:b0:403:3b70:6f57 with SMTP id f13csp314910vqx; Wed, 1 Nov 2023 03:30:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsIm2SK0ds4q3QGMgjX9TxV2dsKnmlgMPHNS14edho9VGI24xD3QvnrPjz/ya2TMRxqi1z X-Received: by 2002:a17:903:41c4:b0:1cc:4a84:27cd with SMTP id u4-20020a17090341c400b001cc4a8427cdmr8565440ple.31.1698834602521; Wed, 01 Nov 2023 03:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698834602; cv=none; d=google.com; s=arc-20160816; b=NnHFjCLm+9YikxlIxWoWOr/lZOpt2hDI4GRLdlF7MAM7Oy4JltD3ulIB+93Gw1QgNJ iWdopb3wDzuBuZ69lsueAfZGf4VfIoirSoIoOt6fbPe0XEY4H+sZxgqLDRUxMEiXcZie R27KY1jefUzk3vjDmy8cp2kFN6azfOUqMuJTkXbQkoO33VS95ERcT00AhvftEKCC6kuV cuurclKv0bl8Fh/3wBA5egF0wNk9LPIil8P920GRNtB93pSMR4v+doC9R1/R5g69NLxv ivOdSDaAvrNAP8O0vKqFCL0JxKDLdX7pYBM5KTESYU0tCO+r0jgL0/s39p6WBhDgxqzi Z4/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=pSKI4+L8HJRYn63UrrAYG4N/D56LntFTm89/ZK6IV24=; fh=0+l72ck3kOAs3cMd/mEkI3DSRNpPfi1ydrq5QwtlmRc=; b=m539ThUq5SxgaQxrZ0T6rbzWU39PCXVXeIxFmeQ9SI+sFx/4HgLsxOZTP8PHjG7fox VMTNDXifogtlSSlTNXnuXMFRzdfVASOYgHpgUXRpElIRyv8zcDLexI89Tcy2fdxX6EVN Pk/6SOqYWXeMRYceoaFM8awjy7f+u8jIEAb7wFIZ09SalxvtYFXrPEs+eXMAUwD8CKcY FEXFZc7LxgjmKVzBy/S1xxn21dqazk/dJP5o+ZTxZw9cqLk+ufjWUb8a4Dyy75TSDUF2 6UjFOf1Zuo7fDPkSIz+HHYJts/UcVdT8z9IhJW56Hlc7ckwbmZQljdsnsmubdKNVpyj6 NbNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=hQdEufFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id d1-20020a170903230100b001ca85fddf9esi2764263plh.483.2023.11.01.03.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 03:30:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=hQdEufFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A2FE7809B465; Wed, 1 Nov 2023 03:29:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235126AbjKAK3F (ORCPT + 35 others); Wed, 1 Nov 2023 06:29:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235110AbjKAK3C (ORCPT ); Wed, 1 Nov 2023 06:29:02 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88AA4DE; Wed, 1 Nov 2023 03:28:52 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 39397120033; Wed, 1 Nov 2023 13:28:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 39397120033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1698834531; bh=pSKI4+L8HJRYn63UrrAYG4N/D56LntFTm89/ZK6IV24=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=hQdEufFtltMp4tP59pfpQfMZAy5u5HUeSe7wslXZZYG0+RgoZAruI5nqoFqESnayv 8PDojzaOXskd/K7rXMwIx6qNKqm6R5vcNxDJK681HH83Rps5sg7ya2aMBELUJAJ6+k WMIv7jOTRVH3GHf7iukh+HewyvxYIkLSOb9Z4tjRH2k4Kp5IBR1TKZZ0fimlsP4pwF u4noMpFQRni0uYtGrP5RH1EpCivQAkmimxBRQzhD27R6S11XCbOzTNSmO9ePcwujmk QtHTqb1InR6V7SZErR2B8uCuSGeHYqP2v8FxvSROexv5DeZrnYOs7Ohb6iEczA7DlU slqJr1B6XRbag== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Wed, 1 Nov 2023 13:28:50 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Wed, 1 Nov 2023 13:28:50 +0300 From: Dmitry Rokosov To: , , , , , , , CC: , , , , , , Dmitry Rokosov Subject: [PATCH v1 2/2] mm: memcg: introduce new event to trace shrink_memcg Date: Wed, 1 Nov 2023 13:28:37 +0300 Message-ID: <20231101102837.25205-3-ddrokosov@salutedevices.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20231101102837.25205-1-ddrokosov@salutedevices.com> References: <20231101102837.25205-1-ddrokosov@salutedevices.com> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 181040 [Nov 01 2023] X-KSMG-AntiSpam-Version: 6.0.0.2 X-KSMG-AntiSpam-Envelope-From: ddrokosov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 543 543 1e3516af5cdd92079dfeb0e292c8747a62cb1ee4, {Tracking_from_domain_doesnt_match_to}, 100.64.160.123:7.1.2;p-i-exch-sc-m01.sberdevices.ru:7.1.1,5.0.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;127.0.0.199:7.1.2;salutedevices.com:7.1.1, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/11/01 06:18:00 #22376334 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 01 Nov 2023 03:29:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781357192437369517 X-GMAIL-MSGID: 1781357192437369517 The shrink_memcg flow plays a crucial role in memcg reclamation. Currently, it is not possible to trace this point from non-direct reclaim paths. However, direct reclaim has its own tracepoint, so there is no issue there. In certain cases, when debugging memcg pressure, developers may need to identify all potential requests for memcg reclamation including kswapd(). The patchset introduces the tracepoints mm_vmscan_memcg_shrink_{begin|end}() to address this problem. Example of output in the kswapd context (non-direct reclaim): kswapd0-39 [001] ..... 240.356378: mm_vmscan_memcg_shrink_begin: memcg=test order=0 gfp_flags=GFP_KERNEL kswapd0-39 [001] ..... 240.356396: mm_vmscan_memcg_shrink_end: memcg=test nr_reclaimed=0 kswapd0-39 [001] ..... 240.356420: mm_vmscan_memcg_shrink_begin: memcg=test oorder=0 gfp_flags=GFP_KERNEL kswapd0-39 [001] ..... 240.356454: mm_vmscan_memcg_shrink_end: memcg=test nr_reclaimed=1 kswapd0-39 [001] ..... 240.356479: mm_vmscan_memcg_shrink_begin: memcg=test oorder=0 gfp_flags=GFP_KERNEL kswapd0-39 [001] ..... 240.356506: mm_vmscan_memcg_shrink_end: memcg=test nr_reclaimed=4 kswapd0-39 [001] ..... 240.356525: mm_vmscan_memcg_shrink_begin: memcg=test oorder=0 gfp_flags=GFP_KERNEL kswapd0-39 [001] ..... 240.356593: mm_vmscan_memcg_shrink_end: memcg=test nr_reclaimed=11 kswapd0-39 [001] ..... 240.356614: mm_vmscan_memcg_shrink_begin: memcg=test oorder=0 gfp_flags=GFP_KERNEL kswapd0-39 [001] ..... 240.356738: mm_vmscan_memcg_shrink_end: memcg=test nr_reclaimed=25 kswapd0-39 [001] ..... 240.356790: mm_vmscan_memcg_shrink_begin: memcg=test oorder=0 gfp_flags=GFP_KERNEL kswapd0-39 [001] ..... 240.357125: mm_vmscan_memcg_shrink_end: memcg=test nr_reclaimed=53 Signed-off-by: Dmitry Rokosov --- include/trace/events/vmscan.h | 14 ++++++++++++++ mm/vmscan.c | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h index 124bc22866c8..518e7232c9eb 100644 --- a/include/trace/events/vmscan.h +++ b/include/trace/events/vmscan.h @@ -182,6 +182,13 @@ DEFINE_EVENT(mm_vmscan_memcg_reclaim_begin_template, mm_vmscan_memcg_softlimit_r TP_ARGS(memcg, order, gfp_flags) ); +DEFINE_EVENT(mm_vmscan_memcg_reclaim_begin_template, mm_vmscan_memcg_shrink_begin, + + TP_PROTO(const struct mem_cgroup *memcg, int order, gfp_t gfp_flags), + + TP_ARGS(memcg, order, gfp_flags) +); + #endif /* CONFIG_MEMCG */ DECLARE_EVENT_CLASS(mm_vmscan_direct_reclaim_end_template, @@ -247,6 +254,13 @@ DEFINE_EVENT(mm_vmscan_memcg_reclaim_end_template, mm_vmscan_memcg_softlimit_rec TP_ARGS(memcg, nr_reclaimed) ); +DEFINE_EVENT(mm_vmscan_memcg_reclaim_end_template, mm_vmscan_memcg_shrink_end, + + TP_PROTO(const struct mem_cgroup *memcg, unsigned long nr_reclaimed), + + TP_ARGS(memcg, nr_reclaimed) +); + #endif /* CONFIG_MEMCG */ TRACE_EVENT(mm_shrink_slab_start, diff --git a/mm/vmscan.c b/mm/vmscan.c index 4309eaf188b4..6b9619922dfb 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -6461,6 +6461,10 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) */ cond_resched(); + trace_mm_vmscan_memcg_shrink_begin(memcg, + sc->order, + sc->gfp_mask); + mem_cgroup_calculate_protection(target_memcg, memcg); if (mem_cgroup_below_min(target_memcg, memcg)) { @@ -6491,6 +6495,9 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) shrink_slab(sc->gfp_mask, pgdat->node_id, memcg, sc->priority); + trace_mm_vmscan_memcg_shrink_end(memcg, + sc->nr_reclaimed - reclaimed); + /* Record the group's reclaim efficiency */ if (!sc->proactive) vmpressure(sc->gfp_mask, memcg, false,