Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1398792iob; Thu, 19 May 2022 05:59:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZCXsXvjHrXM9B1DKts+y60CqZSXIRSND38XIrwD8Uel1peEgCe7nHANPU4Zd5qJP3VNOb X-Received: by 2002:a65:6e0b:0:b0:3aa:6146:15a8 with SMTP id bd11-20020a656e0b000000b003aa614615a8mr3817483pgb.181.1652965187370; Thu, 19 May 2022 05:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652965187; cv=none; d=google.com; s=arc-20160816; b=uIs78MeCtk/ZP+SM+YV5wJLHOUnAAu2CvfikCOo/4YEFVL0txfVK8k1Cf2f5OvwcRY kEp3CSoeZZEAk0ovxZT1qqR0jyF9GXULxfTQD1/c0e16IrBqnvpdmXwEYDWVUGPN3An1 uqDDCO1MXk8gxUJQEJmNrSiukd2okmZGvGjIfY1Ko0ABAsaXakNIE3vsAetVWaUjCQgL MUW45VauBIgVXuYfC/ps0w+XVqEzTu+HxBSrcbgkZDuMyfA29vMthrvbfZSFt+Ky3WAd PXegFvKfZMJkHZpd0UuVLmnN7E+bX0se/QJcnxBvylfQYQxIHwCVTTzORcBLJ1FuWJPj spcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=5ASte9vGYV8NmyufWXTtDt+wnTToG5G7bVCsDgy4Kpg=; b=o0elyfFXBYHwjrelDxobjL+GiSrZT3zsXpHDbfJJapbD4NPyNfT+QNePaKEEaEu4V9 7CkHEBNdQvkwePevEdtAJDyb94o/zslCMOWRxmBDl0UWGy9/CWyZ5AeUnmzJ/JmNVn4J NhlSyTcuYXviqBpxZqm1TqJQngjNyoOHCWNtzuty1zxeBiLEwglpklbTVpT6WHHqy68U H+OF7ft7nUIQx5BCG4WC9d9ikrmdzbJ6rl/kWXusfFpB3kRPUqMWztUdAtf5AQaOa5dU y3kjrq8pUmJoAkZysQrhL9EH99Qw0HmD2koGAYVNvtk2BCrKLky7W4HMioaSpJ1kPuDL /Xxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gwTVGnSB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c7-20020a637247000000b003c60870c831si6424119pgn.394.2022.05.19.05.59.35; Thu, 19 May 2022 05:59:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gwTVGnSB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234869AbiESH7x (ORCPT + 99 others); Thu, 19 May 2022 03:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbiESH7w (ORCPT ); Thu, 19 May 2022 03:59:52 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3642393ED for ; Thu, 19 May 2022 00:59:50 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2fecfc7a95aso39421417b3.22 for ; Thu, 19 May 2022 00:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=5ASte9vGYV8NmyufWXTtDt+wnTToG5G7bVCsDgy4Kpg=; b=gwTVGnSBCH1OItkK8408hxAE3H+3MOivih34m7SBHEGT0+6hAZOMLNPptS8SIvLmuk dn2y46gEkcFMT6rDddZ+v7a37E4u+yB8m9HWh7XNQNIo8o+qpgOH/q9QPz/KwdaFOIVV Nq6tzQ02jiflJjryDeixn4W/tNmMMnumKiTZ36ZxRroI3RPCmJHaY4M7pNq/lV3jccpO rZPjU/9DuAsZ2bqhz0zyrw8D0P4kaiQK7kHNRTbeHzkIcduFAaVBVEqNoXOd8BJqnfd4 NYrOoQgzKjbdFMCsMqLS1DyP1f9llOtIzlwbiTSrOq7EO3K9qk7QpbKFIsyOkuDu1TuB Mt5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=5ASte9vGYV8NmyufWXTtDt+wnTToG5G7bVCsDgy4Kpg=; b=AC5rh/Cawa7D+pesZBfSX1a1uni+QWwB1PneCcYa88s0YS3tZ4BJhDzzxQ9RtD94Tr rxf//R6tZTctvwx8VEfYsCuF8atla9JOvEjwMFxlVJZ2tQSGhNRuBx3C9ni5y4cIXmuh iJsdpLLBrir3U7l8psnH2xnh65xu8FRMC5Kt9flHpyZyzxUeB5/ORmRoAl+YNLMlphBe HemeD3UymmdBrqfto+tEdbZ4w+ta878oE9flqNkrLuXLS97vCd1ACw8svsr+UNr3gv/O nSlwlY/wWC6xDS8RM+8DOIu5CLX0SaLKvUtp625mdbRe4zkEzmsNHRukvtPx5vF0JRjs 3SJA== X-Gm-Message-State: AOAM530J/8ASWbdzVOS5BZyxwooQuNRxdkqeHj0PYo3An1MoWbj967W0 CIAAK8hhUNfPtvVc+BlbujCyvPZSrEMA X-Received: from gthelen2.svl.corp.google.com ([2620:15c:2cd:202:d3bc:20ba:fd8e:8208]) (user=gthelen job=sendgmr) by 2002:a25:4bc6:0:b0:64d:efe1:a7d1 with SMTP id y189-20020a254bc6000000b0064defe1a7d1mr3156185yba.70.1652947189788; Thu, 19 May 2022 00:59:49 -0700 (PDT) Date: Thu, 19 May 2022 00:59:47 -0700 In-Reply-To: <20220518223815.809858-1-vaibhav@linux.ibm.com> Message-Id: Mime-Version: 1.0 References: <20220518223815.809858-1-vaibhav@linux.ibm.com> Subject: Re: [PATCH] memcg: provide reclaim stats via 'memory.reclaim' From: Greg Thelen To: Vaibhav Jain , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Vaibhav Jain wrote: > [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 I certainly appreciate the ability for shell scripts to demonstrate cgroup operations with textual interfaces, but such interface seem like they are optimized for ease of use by developers. I wonder if for runtime production use an ioctl or netlink interface has been considered for cgroup? I don't think there are any yet, but such approaches seem like a more straightforward ways to get nontrivial input/outputs from a single call (e.g. like this proposal). And they have the benefit of not requiring ascii serialization/parsing overhead. > [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 */ > };