Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp987648pxb; Fri, 22 Apr 2022 16:04:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYp9CBX0lm9XQ/maeazHJ9csy7K6RTLefGN8z7iRjx3WJmD3UZ0T35hGU1j7NNmpiaYsDM X-Received: by 2002:a63:7d4a:0:b0:398:dad:6963 with SMTP id m10-20020a637d4a000000b003980dad6963mr5738147pgn.329.1650668641454; Fri, 22 Apr 2022 16:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650668641; cv=none; d=google.com; s=arc-20160816; b=CaXv8DGSSg5q9kfkFcsfgZjZk+g75hTPW+JDweZlMhwASVQDZxJx64pD/Z2+LQnDaE OuamCCeyzUcv9FRL5V5WfoaPCntZnCu1E3QeDrI1vOzOcKK8sR/oh9WNH+eF6faA5eNV 5scJyva8DI87iJVGQ8Gmcbdhr4Qxvm2IB68qC32Or4CVyViNKqhQjsFF7n7W54gAndlg GQu5XDnWnRp6A947gat4UwKoNpPBJF/wp6kBE4Bg90fVqm6jSFEkBv6cVRxV+S0l9RNM aZrm6RL4Nk9AFWAhAY29c521Kyrs/D8YxcEqrEB7zKZWK6+fPfcIIE689M+EDRfq2roo XVgQ== 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=YJ7iyWPMUBRHOLQYsDGfDGb0YRmFrOq96IBzMGKKov4=; b=Myoiq4LbtvTMUzpLAqa3drEY7KB1kLv32FoiHwA7gaV+SNyy1FcpEoZN6sOWpx/7G9 QCRaOUgJs5FNqFgfbf2/dRLfwruo2tfDv6Y+nJmUK9z2jNqajVrxz202jqPZD7BoQ78+ ky4wFfnTRQBUitDEZQasApw82FLDe7GN+9pJQGaY+5ow/wt2DNQ5hXOWMothWpluqdnp 9ggkUq5tOHtC8IfjlGGxDfGKk+Tjv51fZpfw/RqXM6fHMt6HHlWrtq96HyVTFk0LGzTD +wlVcV1DUaEgLOS6lOoNFjWn2m1cpiXT9LvPW6inM5G23XHCy324BqXN7o/MA0EeMfPr dU2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QViKBcw+; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id q11-20020a65494b000000b0039d976426d9si10205640pgs.575.2022.04.22.16.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 16:04:01 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QViKBcw+; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 53BE12A5649; Fri, 22 Apr 2022 14:53:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbiDVV4k (ORCPT + 99 others); Fri, 22 Apr 2022 17:56:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230341AbiDVV4U (ORCPT ); Fri, 22 Apr 2022 17:56:20 -0400 Received: from out2.migadu.com (out2.migadu.com [IPv6:2001:41d0:2:aacc::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 910DD2A6FFA for ; Fri, 22 Apr 2022 13:38:53 -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=1650659223; 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=YJ7iyWPMUBRHOLQYsDGfDGb0YRmFrOq96IBzMGKKov4=; b=QViKBcw+Y9me8wTo9O4z/6ARWC0RmTqkrJWEJ2LMRfQ3Qrx5ozVcnOKyrHA5zyzle+u9xQ 00G2tNIT5roV/LpwrAldQRK1ODQiptW0RKq1uETU7v8wjtHp1XmlgoNT+7wjiylNM3KnBt 9FI2VIjhzM7nngbtUg5otkmzsXGjiEU= From: Roman Gushchin To: Andrew Morton , linux-mm@kvack.org Cc: Dave Chinner , linux-kernel@vger.kernel.org, Yang Shi , Kent Overstreet , Hillf Danton , Roman Gushchin Subject: [PATCH v2 2/7] mm: memcontrol: introduce mem_cgroup_ino() and mem_cgroup_get_from_ino() Date: Fri, 22 Apr 2022 13:26:39 -0700 Message-Id: <20220422202644.799732-3-roman.gushchin@linux.dev> In-Reply-To: <20220422202644.799732-1-roman.gushchin@linux.dev> References: <20220422202644.799732-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 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 Shrinker debugfs requires a way to represent memory cgroups without using full paths, both for displaying information and getting input from a user. Cgroup inode number is a perfect way, already used by e.g. bpf. This commit adds a couple of helper functions which will be used to represent and interact with memcg-aware shrinkers. Signed-off-by: Roman Gushchin --- include/linux/memcontrol.h | 9 +++++++++ mm/memcontrol.c | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 89b14729d59f..27a91dd210c9 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -831,6 +831,15 @@ static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) } struct mem_cgroup *mem_cgroup_from_id(unsigned short id); +#ifdef CONFIG_SHRINKER_DEBUG +static inline unsigned long mem_cgroup_ino(struct mem_cgroup *memcg) +{ + return cgroup_ino(memcg->css.cgroup); +} + +struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino); +#endif + static inline struct mem_cgroup *mem_cgroup_from_seq(struct seq_file *m) { return mem_cgroup_from_css(seq_css(m)); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 08cbe23a8b94..a508979177a2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5022,6 +5022,29 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id) return idr_find(&mem_cgroup_idr, id); } +#ifdef CONFIG_SHRINKER_DEBUG +struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) +{ + struct cgroup *cgrp; + struct cgroup_subsys_state *css; + struct mem_cgroup *memcg; + + cgrp = cgroup_get_from_id(ino); + if (!cgrp) + return ERR_PTR(-ENOENT); + + css = cgroup_get_e_css(cgrp, &memory_cgrp_subsys); + if (css) + memcg = container_of(css, struct mem_cgroup, css); + else + memcg = ERR_PTR(-ENOENT); + + cgroup_put(cgrp); + + return memcg; +} +#endif + static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) { struct mem_cgroup_per_node *pn; -- 2.35.1