From patchwork Wed Nov 22 10:01:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Rokosov X-Patchwork-Id: 168269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1213499vqb; Wed, 22 Nov 2023 02:02:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7sN/1koqmkuzIYqgNRhFZd872+Mrh+rPiMU8ejtMRwM8zSOQH7y1MogjXEBgY3gorLR5L X-Received: by 2002:a05:6808:1804:b0:3b2:e61f:f0a8 with SMTP id bh4-20020a056808180400b003b2e61ff0a8mr2207471oib.45.1700647360428; Wed, 22 Nov 2023 02:02:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700647360; cv=none; d=google.com; s=arc-20160816; b=CxWz8Rj/JOXDXSoN8k4qUDgcxHMPvP34nQtcwbamZPirwTLc2vawaEWPefpCLZJ6wy Hty9H9F8o/ftGReTnIGtl5wO1yxsERmQFHLNjfIcCUOh4umhXB5cRo09I97yCikKwHt1 VDWygyqTEN+xeJLaAEGEyYHmc/DS7PVIiKH1lFdSy8nudmVVZASek7pnSGaTGcr2OjS8 0xo7vPIA+FTbcgPZRtJWuAGRXTWPJHdToC5xNRSUOxpUn42PgEP2AvDOu7dYMBs9NpUA Sdo9Jjl6CRQrqHkHVls5TNbMDw+mEA5RWpM3fqPaa9Ma3ZhGRuG+bKCrO62W6HGSzflf D95A== 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=ihuwRMROZNg9AMfolsXNCx/0gG4LGfVCgQWgEVIDo1o=; fh=0+l72ck3kOAs3cMd/mEkI3DSRNpPfi1ydrq5QwtlmRc=; b=mo4ThULhzXp7xbjnlU/4IA6jk7tlPBDckvuDJiVs/d05iNeP98MlbUWSt4RI7wRADK K76r9Uhf6XO9kKREfJaL1Ub2J8/m/CiYe1mcenp3NWb6xk9Is/yelHGik2zm2OQtbqZQ xPIrkpnJDFzIsLUy9nOpbe6OogyXbZuW4q3cnMgicNWh91T2U0lh9jYm8D9LnZHX7xO6 oqzpaYdxxF32udx6K3X7ixU7GRnUHl+dLUIV5ovEDXhs8s9cPYze1lligNy2NYeLrdi+ Cz69a4xU1uNST9n7Z18nShQrbBGKgekeB5QUD+VOe1Ayhm/ZjvDnL9Rpdi58i1sPflcg yb4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=eyXlTCLL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id by11-20020a056a02058b00b005b64e8336dfsi13175262pgb.604.2023.11.22.02.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 02:02:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=eyXlTCLL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id C2AE18114EDA; Wed, 22 Nov 2023 02:02:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235117AbjKVKCP (ORCPT + 99 others); Wed, 22 Nov 2023 05:02:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbjKVKCN (ORCPT ); Wed, 22 Nov 2023 05:02:13 -0500 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85C1BD65; Wed, 22 Nov 2023 02:02:07 -0800 (PST) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 48C2C120079; Wed, 22 Nov 2023 13:02:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 48C2C120079 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1700647325; bh=ihuwRMROZNg9AMfolsXNCx/0gG4LGfVCgQWgEVIDo1o=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=eyXlTCLL30waDgk1VVuibAcFiArPDA/QsTD9s6PVmHQgZDaoOl0J7HEhacQSCGzdW KpC4kNieIjEFxfS7rrl1N/XnW2xeSyvlnB3irz28yZu5koLfNmBdv3XgUW1/8bDNC2 UhUCooBWv1c8a7wGw4dtmVhFcjNzEEQ/8olZIuSXqZCPfxpqDW/7qoyGEUt+yKxmS6 OEek66LqWv/XAvLl+yqIg3FJ4LbryZ/luWoFIc5d8EH0xClBLML70hedhn3PrHyfjv DUMuF6145cZGNl7EV41++Y5LhnIxWkV/utXAwWS1AZ+8VYlsDl+KNWaRRcab96J6Wy GqtyrCw9DvGyw== 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, 22 Nov 2023 13:02:05 +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.40; Wed, 22 Nov 2023 13:02:04 +0300 From: Dmitry Rokosov To: , , , , , , , CC: , , , , , , Dmitry Rokosov Subject: [PATCH v2 1/2] mm: memcg: print out cgroup name in the memcg tracepoints Date: Wed, 22 Nov 2023 13:01:55 +0300 Message-ID: <20231122100156.6568-2-ddrokosov@salutedevices.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20231122100156.6568-1-ddrokosov@salutedevices.com> References: <20231122100156.6568-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: 181525 [Nov 22 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: 3 0.3.3 e5c6a18a9a9bff0226d530c5b790210c0bd117c8, {Tracking_from_domain_doesnt_match_to}, salutedevices.com:7.1.1;127.0.0.199:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;p-i-exch-sc-m01.sberdevices.ru:5.0.1,7.1.1;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/22 05:48:00 #22499758 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 02:02:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783258006643729894 X-GMAIL-MSGID: 1783258006643729894 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 | 10 ++--- 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/include/trace/events/vmscan.h b/include/trace/events/vmscan.h index d2123dd960d5..9b49cd120ae9 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(int order, gfp_t gfp_flags, const struct mem_cgroup *memcg), + + TP_ARGS(order, gfp_flags, memcg), + + 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("order=%d gfp_flags=%s memcg=%s", + __entry->order, + show_gfp_flags(__entry->gfp_flags), + __entry->name) ); -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(int order, gfp_t gfp_flags, const struct mem_cgroup *memcg), - TP_ARGS(order, gfp_flags) + TP_ARGS(order, gfp_flags, memcg) +); + +DEFINE_EVENT(mm_vmscan_memcg_reclaim_begin_template, mm_vmscan_memcg_softlimit_reclaim_begin, + + TP_PROTO(int order, gfp_t gfp_flags, const struct mem_cgroup *memcg), + + TP_ARGS(order, gfp_flags, memcg) ); + #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(unsigned long nr_reclaimed, const struct mem_cgroup *memcg), + + TP_ARGS(nr_reclaimed, memcg), + + 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("nr_reclaimed=%lu memcg=%s", + __entry->nr_reclaimed, + __entry->name) ); -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(unsigned long nr_reclaimed, const struct mem_cgroup *memcg), - TP_ARGS(nr_reclaimed) + TP_ARGS(nr_reclaimed, memcg) ); + +DEFINE_EVENT(mm_vmscan_memcg_reclaim_end_template, mm_vmscan_memcg_softlimit_reclaim_end, + + TP_PROTO(unsigned long nr_reclaimed, const struct mem_cgroup *memcg), + + TP_ARGS(nr_reclaimed, memcg) +); + #endif /* CONFIG_MEMCG */ TRACE_EVENT(mm_shrink_slab_start, diff --git a/mm/vmscan.c b/mm/vmscan.c index 1080209a568b..45780952f4b5 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -7088,8 +7088,8 @@ 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, - sc.gfp_mask); + trace_mm_vmscan_memcg_softlimit_reclaim_begin(sc.order, sc.gfp_mask, + memcg); /* * NOTE: Although we can get the priority field, using it @@ -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(sc.nr_reclaimed, memcg); *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(0, sc.gfp_mask, memcg); 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(nr_reclaimed, memcg); set_task_reclaim_state(current, NULL); return nr_reclaimed;