From patchwork Fri Apr 22 01:58:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 12822658 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 0E806C433EF for ; Fri, 22 Apr 2022 01:59:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 916F46B0075; Thu, 21 Apr 2022 21:59:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C81A6B0078; Thu, 21 Apr 2022 21:59:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78E526B007B; Thu, 21 Apr 2022 21:59:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 6A8AD6B0075 for ; Thu, 21 Apr 2022 21:59:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6B5DA230DE for ; Fri, 22 Apr 2022 01:59:07 +0000 (UTC) X-FDA: 79382857134.27.A7C064E Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf13.hostedemail.com (Postfix) with ESMTP id 3A52820013 for ; Fri, 22 Apr 2022 01:59:04 +0000 (UTC) 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=1650592745; 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=A+vAvPAvLUxpshxpsMFxiGzlhWXtwExNth63kuvG8pyzaeEFKFO49viIu4eG/STpNH3IZ3 uqZpYGbilxKBsT1DkapuFzgJd56xr3au73odv2GW7EVDrpAlQybjTWHVi6KHi9rmIPTPmC xURhXwuwskDQXdLi2rAaqlhVoYu1+/E= 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 v1 2/5] mm: memcontrol: introduce mem_cgroup_ino() and mem_cgroup_get_from_ino() Date: Thu, 21 Apr 2022 18:58:50 -0700 Message-Id: <20220422015853.748291-3-roman.gushchin@linux.dev> In-Reply-To: <20220422015853.748291-1-roman.gushchin@linux.dev> References: <20220422015853.748291-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Stat-Signature: r8shdxf1wdgzumhy6hqwwrq9xzkynr88 X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=A+vAvPAv; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of roman.gushchin@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3A52820013 X-HE-Tag: 1650592744-352087 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: 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;