From patchwork Sat Apr 16 00:27:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Gushchin X-Patchwork-Id: 12815534 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 095D8C433F5 for ; Sat, 16 Apr 2022 00:28:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9280A6B0074; Fri, 15 Apr 2022 20:28:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 863DF6B0075; Fri, 15 Apr 2022 20:28:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B6506B0078; Fri, 15 Apr 2022 20:28:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 583276B0074 for ; Fri, 15 Apr 2022 20:28:21 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1BC1B1837DCD9 for ; Sat, 16 Apr 2022 00:28:21 +0000 (UTC) X-FDA: 79360855602.29.BEA97D4 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf08.hostedemail.com (Postfix) with ESMTP id 984DB160002 for ; Sat, 16 Apr 2022 00:28:20 +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=1650068899; 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=+XZZWweDhLkUOzoGjk2nZa3eMTmJYoI0OHNWOPTHZmo=; b=DMhX8nIvQXvjHFV70qMe2HbYl7ufGj5tarrp/VQxtL94dab8ieQfSoa2M7kMQFrkbcplx2 af0PG8XF9znncRJuWufEjWY+jz31+q0YrvSK5EkC++ad5tiL8s6Wgj6llY+spQuR/9TgAU rR/TC4qf8RiWHA5dDerrz2aqtXvDAlI= From: Roman Gushchin To: linux-mm@kvack.org Cc: Andrew Morton , Dave Chinner , linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Yang Shi , Roman Gushchin Subject: [PATCH rfc 2/5] mm: memcontrol: introduce mem_cgroup_ino() and mem_cgroup_get_from_ino() Date: Fri, 15 Apr 2022 17:27:53 -0700 Message-Id: <20220416002756.4087977-3-roman.gushchin@linux.dev> In-Reply-To: <20220416002756.4087977-1-roman.gushchin@linux.dev> References: <20220416002756.4087977-1-roman.gushchin@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Stat-Signature: k1mokjh4ed5aj7ys3ybtryg3i8d961gh X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=DMhX8nIv; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of roman.gushchin@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 984DB160002 X-HE-Tag: 1650068900-113239 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 sysfs requires a way to represent memory cgroups without using full paths, both for displaying information and getting input from a user. Cgroup inode numbers is a perfect way, 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 using shrinkers sysfs. 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 cc16ba262464..299472046000 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -838,6 +838,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 4a3e1300c5a1..030dd637ec7a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5023,6 +5023,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;