From patchwork Wed May 18 22:38:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 12854202 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 EFDE7C433F5 for ; Wed, 18 May 2022 22:38:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E18F8D0002; Wed, 18 May 2022 18:38:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7922B8D0001; Wed, 18 May 2022 18:38:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60A838D0002; Wed, 18 May 2022 18:38:43 -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 4ACDF8D0001 for ; Wed, 18 May 2022 18:38:43 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 207D6120850 for ; Wed, 18 May 2022 22:38:43 +0000 (UTC) X-FDA: 79480329726.01.688B2E7 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf20.hostedemail.com (Postfix) with ESMTP id 1E9241C00E3 for ; Wed, 18 May 2022 22:38:29 +0000 (UTC) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24ILmTaJ022038; Wed, 18 May 2022 22:38:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=cWTccgEFni0SxdgeQnDGBy9L1Zho1qh6R/OThU17sl8=; b=ZOZcebrJGbgwHxCcYecMtKnjvK4wLXM9H04DjFyVCjX3ux0bJgJlOKB7ZnmbAu2cnL0b pHTobF0gikeR9oo+GUGFJh7ytrxzP8nKyyd2VO1bdD5bi/ggvsiEZkqBjrr8+3oAyswW g6nooA2efPDT45R51URRzKY7JaU944KOYKDjpKIYifat4B6N7zdDCUrtS/gopBvGtt+A rae5DRO4L7qh/wSJf0DzfJwHYuEQSL8HhK0MiGIYWszZHXi4fwaCovtM8xBlu7nxICTV L9U7BDa+reXdgayM4Kjf/qgkmEDXemte+07rre1yQ4UIfTRmOK9/2lghvaYbyUHR3Kzj sw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g591s0ykk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 May 2022 22:38:36 +0000 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24IMMZVP002682; Wed, 18 May 2022 22:38:36 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g591s0yjf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 May 2022 22:38:36 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24IMcIbm028428; Wed, 18 May 2022 22:38:33 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03ams.nl.ibm.com with ESMTP id 3g2429e9my-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 May 2022 22:38:33 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24IMcU6f22020420 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 May 2022 22:38:30 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 755844C050; Wed, 18 May 2022 22:38:30 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2AB64C044; Wed, 18 May 2022 22:38:25 +0000 (GMT) Received: from vajain21.in.ibm.com (unknown [9.43.77.53]) by d06av22.portsmouth.uk.ibm.com (Postfix) with SMTP; Wed, 18 May 2022 22:38:25 +0000 (GMT) Received: by vajain21.in.ibm.com (sSMTP sendmail emulation); Thu, 19 May 2022 04:08:24 +0530 From: Vaibhav Jain To: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Vaibhav Jain , Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Michal Hocko , Vladimir Davydov , Andrew Morton , "Aneesh Kumar K . V" , Shakeel Butt , Yosry Ahmed Subject: [PATCH] memcg: provide reclaim stats via 'memory.reclaim' Date: Thu, 19 May 2022 04:08:15 +0530 Message-Id: <20220518223815.809858-1-vaibhav@linux.ibm.com> X-Mailer: git-send-email 2.35.1 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: WW_Zj-4Qv0pvqo8tFz9-I-3xNtkXyPAI X-Proofpoint-ORIG-GUID: dBh774JKVVFITszzeWAwa8USh6ZJW1U6 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-18_06,2022-05-17_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 clxscore=1011 mlxlogscore=999 bulkscore=0 priorityscore=1501 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205180125 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=ZOZcebrJ; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf20.hostedemail.com: domain of vaibhav@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=vaibhav@linux.ibm.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1E9241C00E3 X-Rspam-User: X-Stat-Signature: owjynt6r5h5y1uii4oxtt9frgs5dsyo9 X-HE-Tag: 1652913509-91408 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: [1] Provides a way for user-space to trigger proactive reclaim by introducing a write-only memcg file 'memory.reclaim'. However reclaim stats like number of pages scanned and reclaimed is still not directly available to the user-space. This patch proposes to extend [1] to make the memcg file 'memory.reclaim' readable which returns the number of pages scanned / reclaimed during the reclaim process from 'struct vmpressure' associated with each memcg. This should let user-space asses how successful proactive reclaim triggered from memcg 'memory.reclaim' was ? With the patch following command flow is expected: # echo "1M" > memory.reclaim # cat memory.reclaim scanned 76 reclaimed 32 [1]: https://lore.kernel.org/r/20220425190040.2475377-1-yosryahmed@google.com Cc: Shakeel Butt Cc: Yosry Ahmed Signed-off-by: Vaibhav Jain --- Documentation/admin-guide/cgroup-v2.rst | 15 ++++++++++++--- mm/memcontrol.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 27ebef2485a3..44610165261d 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1209,18 +1209,27 @@ PAGE_SIZE multiple when read back. utility is limited to providing the final safety net. memory.reclaim - A write-only nested-keyed file which exists for all cgroups. + A nested-keyed file which exists for all cgroups. - This is a simple interface to trigger memory reclaim in the - target cgroup. + This is a simple interface to trigger memory reclaim and retrieve + reclaim stats in the target cgroup. This file accepts a single key, the number of bytes to reclaim. No nested keys are currently supported. + Reading the file returns number of pages scanned and number of + pages reclaimed from the memcg. This information fetched from + vmpressure info associated with each cgroup. + Example:: echo "1G" > memory.reclaim + cat memory.reclaim + + scanned 78 + reclaimed 30 + The interface can be later extended with nested keys to configure the reclaim behavior. For example, specify the type of memory to reclaim from (anon, file, ..). diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2e2bfbed4717..9e43580a8726 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6423,6 +6423,19 @@ static ssize_t memory_oom_group_write(struct kernfs_open_file *of, return nbytes; } +static int memory_reclaim_show(struct seq_file *m, void *v) +{ + struct mem_cgroup *memcg = mem_cgroup_from_seq(m); + struct vmpressure *vmpr = memcg_to_vmpressure(memcg); + + spin_lock(&vmpr->sr_lock); + seq_printf(m, "scanned %lu\nreclaimed %lu\n", + vmpr->scanned, vmpr->reclaimed); + spin_unlock(&vmpr->sr_lock); + + return 0; +} + static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { @@ -6525,6 +6538,7 @@ static struct cftype memory_files[] = { .name = "reclaim", .flags = CFTYPE_NS_DELEGATABLE, .write = memory_reclaim, + .seq_show = memory_reclaim_show, }, { } /* terminate */ };