Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5241702iob; Mon, 9 May 2022 11:44:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxESVmvZLTzvey0e89JQO2vsnLDoM78ipYKoppkGtiMvbsf1G5TSL6OgYpCih4e8PVs4YyD X-Received: by 2002:aca:1c11:0:b0:325:db6c:f1d3 with SMTP id c17-20020aca1c11000000b00325db6cf1d3mr7764927oic.187.1652121879589; Mon, 09 May 2022 11:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652121879; cv=none; d=google.com; s=arc-20160816; b=KqOPmbNU6SZ2pFc18mHzcr+6+hLx8jySXIYVxmIjK/+WFKwaLPEnlw474FPA79azoV FoWfLVKdTJGK2u7qqicr31a/8LEyWCjLOx9hy+WAL5AOo834KF1udzlSyEzwcmg9Va7T DSa8LvVc4fsIj+J+wiwqodYcMrNYeNH+KTft5VajoKrkd71VqKOZvwUDuZ5ojD3SpLJ6 RxTBBu1+25cXcPE94J4Sy2WMf6H9lutGW38T/1JT04G9MRIyGzemDVPpbp2ylAx7qfWK TIU+qmzlxiGgkYL2wkjO35WUy4RKjcUg9I11YfXqmzrAxD+V2jIK22GYb6mqWYq4sA6k NNtw== 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; bh=2z4am8efPkBHe5K6q2zk3FpEuHSEHOPmz0WCK0OizBQ=; b=y6IBbF7rAtIRrhuromnyV+W/9K0dlNiuZiKqg/TrRy4lCfUVgiiPfBaS3FPZvIuSQp tJjCe7vNpNKZPVepK33lo8hxh4kulgZmo0R6DeUcAuEUTYsBSwtcofE9nvY4tY8Uwit+ ghUI7MFaxHfG4Q6YPrhED+DtafmZOCoaWFgo+4GbQzOQB8yipMl2lQOPoQu7gG4stRnf goklaBeacKdl/LgL0n1ZeDnji4InLbwoPkGiRjc0+/lbBKuVhpZ/b0b+EpVf40ooPBZJ /l4REMzBanHU0iCCNoLPgV8jYUN3lgBxHt0pR39zQ/5oaQs6qyBZyrFSycNmhiNALMJa PvSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=W7wTrLUT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w1-20020a056830060100b005cb2fc13865si10415160oti.225.2022.05.09.11.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 11:44:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=W7wTrLUT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B9DF72609C4; Mon, 9 May 2022 11:39:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240280AbiEISmp (ORCPT + 99 others); Mon, 9 May 2022 14:42:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240272AbiEISmj (ORCPT ); Mon, 9 May 2022 14:42:39 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50818260867 for ; Mon, 9 May 2022 11:38:44 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1652121522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2z4am8efPkBHe5K6q2zk3FpEuHSEHOPmz0WCK0OizBQ=; b=W7wTrLUT6pcfa+GNzHQSJr6RwTrBgKY7pSyQYtBPdqz4ksSV8Yr5fAs3rpz4B97+6bbg8W brZ0u/I84OUgoI1tSOEmCIe4x2IKx43Kjlhv9+79j36wGsJ37VymFjCiOnOH3Pf3eMJl2a dY72NIvHL5sz3BH0qpSs/suYcaU2khM= From: Roman Gushchin To: Andrew Morton , linux-mm@kvack.org Cc: Dave Chinner , linux-kernel@vger.kernel.org, Kent Overstreet , Hillf Danton , Christophe JAILLET , Roman Gushchin Subject: [PATCH v3 5/6] tools: add memcg_shrinker.py Date: Mon, 9 May 2022 11:38:19 -0700 Message-Id: <20220509183820.573666-6-roman.gushchin@linux.dev> In-Reply-To: <20220509183820.573666-1-roman.gushchin@linux.dev> References: <20220509183820.573666-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a simple tool which prints a sorted list of shrinker lists in the following format: (number of objects, shrinker name, cgroup). Example: $ ./memcg_shrinker.py -n 10 2090 sb-sysfs-26 /sys/fs/cgroup/system.slice 1809 sb-sysfs-26 /sys/fs/cgroup/system.slice/systemd-udevd.service 1044 sb-btrfs:vda2-24 /sys/fs/cgroup/system.slice/system-dbus\x2d:1.3\... 861 sb-btrfs:vda2-24 /sys/fs/cgroup/system.slice/system-dbus\x2d:1.3\... 804 sb-btrfs:vda2-24 /sys/fs/cgroup/system.slice 643 sb-btrfs:vda2-24 /sys/fs/cgroup/system.slice/firewalld.service 616 sb-cgroup2-30 /sys/fs/cgroup/init.scope 275 sb-sysfs-26 / 238 sb-proc-25 /sys/fs/cgroup/system.slice/systemd-journald.service 225 sb-proc-25 /sys/fs/cgroup/system.slice/abrtd.service Signed-off-by: Roman Gushchin --- tools/cgroup/memcg_shrinker.py | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 tools/cgroup/memcg_shrinker.py diff --git a/tools/cgroup/memcg_shrinker.py b/tools/cgroup/memcg_shrinker.py new file mode 100755 index 000000000000..706ab27666a4 --- /dev/null +++ b/tools/cgroup/memcg_shrinker.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2022 Roman Gushchin +# Copyright (C) 2022 Meta + +import os +import argparse +import sys + + +def scan_cgroups(cgroup_root): + cgroups = {} + + for root, subdirs, _ in os.walk(cgroup_root): + for cgroup in subdirs: + path = os.path.join(root, cgroup) + ino = os.stat(path).st_ino + cgroups[ino] = path + + # (memcg ino, path) + return cgroups + + +def scan_shrinkers(shrinker_debugfs): + shrinkers = [] + + for root, subdirs, _ in os.walk(shrinker_debugfs): + for shrinker in subdirs: + count_path = os.path.join(root, shrinker, "count") + with open(count_path) as f: + for line in f.readlines(): + items = line.split(' ') + ino = int(items[0]) + # (count, shrinker, memcg ino) + shrinkers.append((int(items[1]), shrinker, ino)) + return shrinkers + + +def main(): + parser = argparse.ArgumentParser(description='Display biggest shrinkers') + parser.add_argument('-n', '--lines', type=int, help='Number of lines to print') + + args = parser.parse_args() + + cgroups = scan_cgroups("/sys/fs/cgroup/") + shrinkers = scan_shrinkers("/sys/kernel/debug/shrinker/") + shrinkers = sorted(shrinkers, reverse = True, key = lambda x: x[0]) + + n = 0 + for s in shrinkers: + count, name, ino = (s[0], s[1], s[2]) + if count == 0: + break + + if ino == 0 or ino == 1: + cg = "/" + else: + try: + cg = cgroups[ino] + except KeyError: + cg = "unknown (%d)" % ino + + print("%-8s %-20s %s" % (count, name, cg)) + + n += 1 + if args.lines and n >= args.lines: + break + + +if __name__ == '__main__': + main() -- 2.35.3