From patchwork Tue Jul 2 08:44:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13719108 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 73ADEC30658 for ; Tue, 2 Jul 2024 08:46:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09FA36B0089; Tue, 2 Jul 2024 04:46:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 027DF6B008A; Tue, 2 Jul 2024 04:46:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6EE06B008C; Tue, 2 Jul 2024 04:46:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B55B06B0089 for ; Tue, 2 Jul 2024 04:46:25 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 247DD1A1E37 for ; Tue, 2 Jul 2024 08:46:25 +0000 (UTC) X-FDA: 82294181130.30.A2B369F Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2061.outbound.protection.outlook.com [40.107.117.61]) by imf30.hostedemail.com (Postfix) with ESMTP id 4016E80004 for ; Tue, 2 Jul 2024 08:46:21 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=qTZi65VU; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf30.hostedemail.com: domain of link@vivo.com designates 40.107.117.61 as permitted sender) smtp.mailfrom=link@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719909960; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2MV7Q2+/9roovDyuynNKu6Tlm1HAL+DluQZMl+IyKQU=; b=n4/ztMddBMNqdnlt8o/XwaHNkGSxt0X9lAlnAqaan+EQCV4QStYgVE1eDuWpCUefitvbfp 1+3ccqCnH0wFMCJQWGrWgPccZAhUr9eRrVpNiflo6Q4aWMZOdCTFJe7vUvS7SGZXan6AHU qF54PJdvz2Gtxm0lTzSaBpMuLHpwj1k= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1719909960; a=rsa-sha256; cv=pass; b=H3IrD5ZRsbAH7YEOavQ/Y60EYFqCuPBaswleD/KKepKpEG9DEwyy4Ph/U12bRFE8RfqSrq oPoe0jr/6dUGCMLNP/4syJRFQTJ2zKcgNQ9FqpSy74oEQkQWEtMyEh3OTwGMw0ZSJ9s9x4 2RUExY2hja6S/UO5B7v0Z+HuAy6vi+8= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=qTZi65VU; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf30.hostedemail.com: domain of link@vivo.com designates 40.107.117.61 as permitted sender) smtp.mailfrom=link@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iRFhxV3/yKnBSTgIU5u9jy0ZCM28mdMIAlHoeieG/eFg6NLSUQXT3pZzpQAlHY7U2ccj0Z2X7boPS3Jf42v9+vA6e2Uw/ybaLAdI04QwJFRJBNmru4aKZij6wQ2u9EqjI0Jj49DokNl/G0jd6np/g299T/QrMBwDpPSXBHMtYAaw4WRmrK4ATSkvyanvjhFhwEFb14bEaabKdh+mJW1cU8IGmdl3YhV/MDYgC8ML9ZIb0bULSoFmW32RAhvPrWs1l1xBmVRUIKIDgG4iyI1SuHECnal+L1AoIQWn7G7H45acgSF8qOa6TnJHuK+WQGuTwrMtHCXUQuh+vtuV3TgM+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2MV7Q2+/9roovDyuynNKu6Tlm1HAL+DluQZMl+IyKQU=; b=i0h9VaPXUyBTcOb9X4EXP6HaKFAtkPo2UXDaVSZEZBdd8nuTwAsntkM8zXVXL2t+4KJ227PUHFKfBnBaGPcihgJZZ28LzmHS2Qoyrw+mN07MOUL+NTn/mfQ7oQhfyfP2sZdqEKc7NUd6traLZmvaF3fvC2ngZlWoiiCOnk4vFg26fL1yx3vXKkyxeMQ+liECpID0iXARg77u/vZesCkJKjNc/h9NH25zp+2Bzajdy3faK/J2PpqrmxRRZ2OX7BCrEny8ejl6JNbgbzKIdZzNXbHtoF2OWjz5AeOSzEzZ8NyMvq84xfJxffm+K2JGQCXd5kwJKQ7wtIiYELYJV/7TOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2MV7Q2+/9roovDyuynNKu6Tlm1HAL+DluQZMl+IyKQU=; b=qTZi65VUKb02QN2AQ5YlH4npS6tSgw//8x+xsr3mqdz6FHeEqqgSyqKMhDT6BeAvSnvQFAqM6lgOy7ZY9NX8G7LwgOnoyxl2IhDIKFbonz2pkX0dFC3s56cSnlRsBxpTcNpkNDAttqyGrnkNt0lzJkdt/aSUQVeGWBepvH4SZ//Dla+jqJ9TeNxLJb70Yfxt4sGTqKTt0ED1mat+e3ylzwO1XDiakBCpRPXEd8AonMBV3u7ETUqkqzyY3n0lG1cFRfssAngV82QF/3cRbHwjJfxaG6cDpn2UXw2O+wsc4CDFy1RhG6xkp2+gVklN+OSk1CoQI3/ZBfqmehZGBoYV/Q== Received: from PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) by SEYPR06MB5790.apcprd06.prod.outlook.com (2603:1096:101:b9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.23; Tue, 2 Jul 2024 08:46:10 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::a00b:f422:ac44:636f%6]) with mapi id 15.20.7719.028; Tue, 2 Jul 2024 08:46:10 +0000 From: Huan Yang To: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , Ryan Roberts , Chris Li , Dan Schatzberg , Huan Yang , Kairui Song , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christian Brauner Cc: opensource.kernel@vivo.com Subject: [RFC PATCH 2/4] mm: memcg: pmc support change attribute Date: Tue, 2 Jul 2024 16:44:05 +0800 Message-ID: <20240702084423.1717904-3-link@vivo.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240702084423.1717904-1-link@vivo.com> References: <20240702084423.1717904-1-link@vivo.com> X-ClientProxiedBy: SG2PR01CA0148.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::28) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|SEYPR06MB5790:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a2b0f9d-f637-4db7-7d21-08dc9a736c00 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: 49AJizRIli6T8+XohSyCV4OOS/8am/tL8wB9DywapHJf/AkidjaKey7NaYYcczjOUUBTzfcH1oTB7PlJkowYz/9Ff4UAjmdztuz9BUMcfOCrrjF+CaV0YFuMmMjLp0qIsEb3/sCBqpETEfNpJOVqgR0/Grry21JRoEqaFrPG0EDZwnL4UGQMVpaVwXF3np9oBBP8DwXeqLzeGLC+87+CRxXiuZbq1RmKXhZDM0fyz7mcdZHCzGheHC1jsu8+0F0su5Lx+SP4SocdaqyVLm/ePC5B7YS15CAli1ND07eALBeayVWdhsKzvZWbyzdY5hs+fDh1OyXrszlQYbpyRfJFkAYLheQ9SA2SNOVQ1tZs+ISq/4882UBqJdZL0mWRTxdrVE6AnYbrkEasDU4qCCJa2vNdE8Ky9eOAzQhm0KZ5sufcMS/d8Pwc/E3MWdG0nyQNNVoWcbb87B6C1qfSZ4YrKsXq0e8CVlLCSHGin/3oQ1AirPNzc7z4Jq+M/qTh6EzzMo0/+EsBUWjJXHJF7uvKLHqGAbXMwBFlC7VS4BwWHjp2Ya3FHZTFzQzQxizuIiuftj/2T1mZGfEhSzdJpfFQRAlEaGDXk5kcq+IC7btwXdPqP51yILqkGmz/L+yXui35Flp0EEllvg+veXMrQRBgYf5lBYLdQyUSjXV96pgLq5JMCm1ZWsMZ0JApCByrjEuBOxYgDreUjNzeSdJPnMo4/zUDvnGNzBfp2MRk2dbEG1tFKoXlNXhjD9w73ddtY0QYFiyewp2MnvWO82QeJr3nHK5ww6uOgMYBMdPm64vK8WfTcl8DkQNePT0k5mikiHBwje3SCfB+xvajcDFSC3z4vhGRwPLt3doUoXVvebUG5H2A60Xtvfj2pX9T0CCdG+dH4j/NAkoltub8BAH9R/vpdjhMTqLjpCFTfHR2LeoTHhfsAAYvFfP7+kOozNcTJwQGOzRUKaTUMXz8hNzpUCeuCvG/iT/dErlo+ML+xkKdAPLgtKWqhbdHB6UwA30aQq73yT7edJKu0SB3SedH2qkKJFoyQ9+1lijS/5d7tym6JKRUiKuyf4yLBWL2SKOVOIOVgYa8jnVM5tmdOi9Lq9eQ6wPMjEjCXHJLtZfooOfzubvedj8Ld6mv8XIet1zDuW5+fNjQ31um0cMbQXNRTl+S0kKmxPfsgwtq+n0fB2vEh5ZEZx682XBlBoLb/pxpBr3BYb1QZtWaVe0GoqdFQQLh/gRfqXGQrzqZWLM1oZ00RrNBg1GuXKwPIX+4weoCD2qY4pOBo2ZcjH6veJFOKggC1xwH0RtGXFf1IXoSZMGyIZQE/jeUeOUySMQDmHm87k6x6hynoeOycc0qs0i62fcz7uKEbjVCYNXQivj5/Ouxcg0vQCcaGAMvuMdpHZpRveXPxEhy811/C9RTDrApHcqSb11IkzJR95RftcJ7iPQeSzU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB5676.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(7416014)(376014)(366016)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: x6kusNf0ShESwMV1tB9QubYUsfGsHTzqJOKZFnzJmUmaqMNTMklNeVr0WJ8BOB4oyJGmfCgs0c59lPtrYHQqPmjnEgLd/a/EhJiK+8e0NQC9mOEXlmN9lAhihpYw+NyTMlNjhvbSrqfTEwfSC3mNka4v83ZGumy4qL6kVnXJYhBnWmuSNiik4RKuXODYMQUxZB8W4oMu9rOb4J7mi4Rp8Pqj3krfDBT/tepTCdHEKNV58U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RHK6TmVcX0uADEihtdxqYPpmH46sAf9ZmkJakYUQT28Uv7zXB8Uyoy1/nX+qlbkfOTsHgy4tsWIZiGbh1fi9pq1Z4WjkSYjk7/5U8JfFxt6g5Erc6Rz6M1WTomY+v5Xch1v6/kvmyDDIukptMO6CVwDWghjrYdvHG+I2GI3M5utcQWbPy9kajfO7FmJfWXa6UQgFBLGHyERYdekKgIHWsy2xbs9cmCRAomShpfiwZrGHHexPcumIPi4sZHKIC5CgkiO4RFWtzfQWfJ/1mDrQ59VPjfG3TU25Q0jyWxHE2uBLyEep X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a2b0f9d-f637-4db7-7d21-08dc9a736c00 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2024 08:46:10.5289 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6KY6lu++Iu/ILojwIxMOEIrWhiVYpDb2UC6OKonul2hy/y4jSDyVr4WZSMr3g10NKUvkiaYmE33qbMpwZAkQJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5790 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4016E80004 X-Stat-Signature: bkywyk33kbmqd5agd7ipp8py18i3mqgn X-HE-Tag: 1719909981-197138 X-HE-Meta: U2FsdGVkX18gSzcwjHhu5NbOQNsJJlo25YiDZQjA852PfmI9eIaaZJaRKectFZVt9T/HhaP1v7Lh1uDLd4oyp4zdBMi8OByICCZSJgGWOBEHQgSjHbTxEZazbKq9HO8S7dBDmO+ADGnGhjXClHSJmogYJsWpNPkWXMJ+fZHuTkg9kO3ocjJ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53Q7/WU7goQDNY87LQQEagS5TNAFZDFchEHB8226LR7VE3A3h+q2Yr4Qr0CxffItt6T2Navx5aPEhNfetnORODc4pn3exD4BF9Q== 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: List-Subscribe: List-Unsubscribe: pmc have below attribute: watermark: only when zone free pages above high+watermark can cache pages limit: max memory it can cached. This patch let user can change each attribute by `memory.cache`. To change attribute, can type `keys=attribute=vaule` into memcg's `memory.cache` if it enabled cache. For example: echo keys=watermark=157286400,limit=209715200 > memory.cache This changed memcg's only when free pages above high+150MB can cache pages, and can cache up to a maximum of 200MB . Signed-off-by: Huan Yang --- mm/memcontrol.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 404fcb96bf68..9db5bbe63b34 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7253,29 +7253,168 @@ static int mem_cgroup_cache_show(struct seq_file *m, void *v) return 0; } +#define STATUS_UNSET_DEFAULT_VALUE -1 +enum { + OPT_KEY_NID, + OPT_KEY_WATERMARK, + OPT_KEY_HOLD_LIMIT, + OPT_KEY_ERR, + NR_PMC_KEY_OPTS = OPT_KEY_ERR +}; + +static const match_table_t fc_tokens = { + { OPT_KEY_NID, "nid=%d" }, + { OPT_KEY_WATERMARK, "watermark=%u" }, + { OPT_KEY_HOLD_LIMIT, "limit=%u" }, + { OPT_KEY_ERR, NULL} +}; + +static void +__apply_status_for_mem_cgroup_cache(struct mem_cgroup_per_node_cache *p, + unsigned int opts[]) +{ + int i; + + for (i = OPT_KEY_WATERMARK; i < NR_PMC_KEY_OPTS; ++i) { + switch (i) { + case OPT_KEY_WATERMARK: + if (opts[OPT_KEY_WATERMARK] != + STATUS_UNSET_DEFAULT_VALUE) + p->allow_watermark = opts[OPT_KEY_WATERMARK]; + break; + case OPT_KEY_HOLD_LIMIT: + if (opts[OPT_KEY_HOLD_LIMIT] != + STATUS_UNSET_DEFAULT_VALUE) + p->hold_limit = opts[OPT_KEY_HOLD_LIMIT]; + break; + default: + break; + } + } +} + +static __always_inline int +mem_cgroup_apply_cache_status(struct mem_cgroup *memcg, + unsigned int opts[]) +{ + struct mem_cgroup_per_node_cache *p; + unsigned int nid = opts[OPT_KEY_NID]; + + if (nid != STATUS_UNSET_DEFAULT_VALUE) { + p = memcg->nodeinfo[nid]->cachep; + if (unlikely(!p)) + return -EINVAL; + __apply_status_for_mem_cgroup_cache(p, opts); + return 0; + } + + for_each_node(nid) { + p = memcg->nodeinfo[nid]->cachep; + if (!p) + continue; + __apply_status_for_mem_cgroup_cache(p, opts); + } + + return 0; +} + +/** + * Support nid=x,watermark=bytes,limit=bytes args + */ +static int __mem_cgroup_cache_control_key(char *buf, + struct mem_cgroup *memcg) +{ + char *p; + unsigned int opts[NR_PMC_KEY_OPTS]; + + memset(opts, STATUS_UNSET_DEFAULT_VALUE, sizeof(opts)); + + if (!READ_ONCE(memcg->cache_enabled)) + return -EINVAL; + + if (!buf) + return -EINVAL; + + while ((p = strsep(&buf, ",")) != NULL) { + int token; + u32 v; + substring_t args[MAX_OPT_ARGS]; + + p = strstrip(p); + + if (!*p) + continue; + + token = match_token(p, fc_tokens, args); + switch (token) { + case OPT_KEY_NID: + if (match_uint(&args[0], &v) || v >= MAX_NUMNODES) + return -EINVAL; + opts[OPT_KEY_NID] = v; + break; + case OPT_KEY_WATERMARK: +#define MIN_WATERMARK_LIMIT ((10 << 20) >> PAGE_SHIFT) + if (match_uint(&args[0], &v)) + return -EINVAL; + v >>= PAGE_SHIFT; + if (v < MIN_WATERMARK_LIMIT) + return -EINVAL; + opts[OPT_KEY_WATERMARK] = v; + break; + case OPT_KEY_HOLD_LIMIT: + if (match_uint(&args[0], &v)) + return -EINVAL; + v >>= PAGE_SHIFT; +#define MAX_CACHE_LIMIT_NR ((500 << 20) >> PAGE_SHIFT) + if (v > MAX_CACHE_LIMIT_NR) + return -EINVAL; + opts[OPT_KEY_HOLD_LIMIT] = v; + break; + case OPT_KEY_ERR: + default: + break; + } + } + + if (mem_cgroup_apply_cache_status(memcg, opts)) + return -EINVAL; + + return 0; +} + enum { OPT_CTRL_ENABLE, + OPT_CTRL_KEYS, OPT_CTRL_ERR, OPR_CTRL_NR = OPT_CTRL_ERR, }; static const match_table_t ctrl_tokens = { { OPT_CTRL_ENABLE, "enable=%s" }, + { OPT_CTRL_KEYS, "keys=%s" }, { OPT_CTRL_ERR, NULL } }; /** * This function can control target memcg's cache. include enable\keys set. * To enable\disable this cache, by `echo enable=[y|n] > memory.cace` * in target memcg. + * To set keys, by `echo keys=[key=args;..] > memory.cache`, current support keys: + * 1. nid=x, if input, will only change target NODE's cache status. Else, all. + * 2. watermark=bytes, change cache hold behavior, only zone free pages above + * high watermark+watermark, can hold. + * 3. limit=bytes, change max pages can cache. Max can change to 500MB + * Enable and keys can both input, split by space, so can set args after enable, + * if cache not enable, can't set keys. */ static ssize_t mem_cgroup_cache_control(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { bool enable; - bool opt_enable_set = false; + bool opt_enable_set = false, opt_key_set = false; int err = 0; char *sub; struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); + char keybuf[256]; buf = strstrip(buf); if (!strlen(buf)) @@ -7300,6 +7439,14 @@ static ssize_t mem_cgroup_cache_control(struct kernfs_open_file *of, char *buf, return -EINVAL; opt_enable_set = true; break; + case OPT_CTRL_KEYS: + if (match_strlcpy(tbuf, &args[0], sizeof(tbuf)) >= + sizeof(tbuf)) + return -EINVAL; + + memcpy(keybuf, tbuf, sizeof(keybuf)); + opt_key_set = true; + break; case OPT_CTRL_ERR: default: return -EINVAL; @@ -7315,6 +7462,9 @@ static ssize_t mem_cgroup_cache_control(struct kernfs_open_file *of, char *buf, } } + if (opt_key_set) + err = __mem_cgroup_cache_control_key(keybuf, memcg); + return err ? err : nbytes; }