From patchwork Wed May 25 20:25:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 12861708 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 9B4C8C433FE for ; Wed, 25 May 2022 20:26:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BD5B8D0005; Wed, 25 May 2022 16:26:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 21D6B8D0001; Wed, 25 May 2022 16:26:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06AB28D0005; Wed, 25 May 2022 16:26:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E73D28D0001 for ; Wed, 25 May 2022 16:26:16 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BB9FA34D19 for ; Wed, 25 May 2022 20:26:16 +0000 (UTC) X-FDA: 79505397552.02.D3C9BC8 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf20.hostedemail.com (Postfix) with ESMTP id DCA6D1C0027 for ; Wed, 25 May 2022 20:26:00 +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=1653510375; 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=xiAehEm5iJYhixjRO3mnnrUPj7Yc5RLJUL9sGmXH7Nk=; b=Yg7JQoRpOexH4agqfY1ad00qMtDT9TocwakUKuQZn+fpn81NrSIvV07W+LmS5GwLjw8G4v ggGCv0Do6+NDYeGrSqKbWvmSzYxYyWpu5TaLfRo7P5BatpEnMiTrCM78L/y0w/GkI5CZkE EfC3FCW8VDkXKCkQrJ0W/brEi+Ry6pE= From: Roman Gushchin To: Andrew Morton , linux-mm@kvack.org Cc: Dave Chinner , linux-kernel@vger.kernel.org, Kent Overstreet , Hillf Danton , Christophe JAILLET , Muchun Song , Roman Gushchin Subject: [PATCH v4 1/6] mm: memcontrol: introduce mem_cgroup_ino() and mem_cgroup_get_from_ino() Date: Wed, 25 May 2022 13:25:55 -0700 Message-Id: <20220525202600.2910982-2-roman.gushchin@linux.dev> In-Reply-To: <20220525202600.2910982-1-roman.gushchin@linux.dev> References: <20220525202600.2910982-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Yg7JQoRp; spf=pass (imf20.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Stat-Signature: 8cudwmi6bkwktx1gr8r8hsesbcntbrnu X-Rspamd-Queue-Id: DCA6D1C0027 X-Rspamd-Server: rspam01 X-HE-Tag: 1653510360-433870 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 bpf. This commit adds a couple of helper functions which will be used to handle memcg-aware shrinkers. Signed-off-by: Roman Gushchin Acked-by: Muchun Song --- include/linux/memcontrol.h | 21 +++++++++++++++++++++ mm/memcontrol.c | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 89b14729d59f..66a4f22e8154 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 memcg ? cgroup_ino(memcg->css.cgroup) : 0; +} + +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)); @@ -1328,6 +1337,18 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) return NULL; } +#ifdef CONFIG_SHRINKER_DEBUG +static inline unsigned long mem_cgroup_ino(struct mem_cgroup *memcg) +{ + return 0; +} + +static inline struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) +{ + return NULL; +} +#endif + static inline struct mem_cgroup *mem_cgroup_from_seq(struct seq_file *m) { return NULL; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 598fece89e2b..d0f892bde698 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5027,6 +5027,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;