Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2347881ioo; Mon, 23 May 2022 16:43:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzDCUNJXTpPjH7/PHNJMKgSSbMTDejjASCE0XFc9MOaC8txt15FOJzrC1WEPkdg3eZpkYi X-Received: by 2002:a17:907:7283:b0:6f4:ff4f:1b6e with SMTP id dt3-20020a170907728300b006f4ff4f1b6emr21572571ejc.344.1653349409611; Mon, 23 May 2022 16:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653349409; cv=none; d=google.com; s=arc-20160816; b=QG1GlrFKU5M8cU/2hr2cMNDWvo8k7oKBlDaW01oUqBLlTo6zZ9M20Io7py3daqgiuJ Bhk3AwAJH7IsS0/43XukbWH6qi7EMORmhof7gKYSOqLpVyD479xuDXMBEfxFJrJmBgon WdfIK50ZIuPP7MlcB9lscd/LmRWsz2XH5HJwxIhQmgWBNX/7yU1oajAuJtCYiIdLCBzH MtmHgcRuJAhgQdq0VFwX7Vhc9UxwrP7gdJ6eTJotI/z/4IyPgimkVa/HCU+UaEZ/KoJm Fc5yccBxWxk0IaXo8kniV+OFm2gcRIolvrxZxV5lVhPS08SzydMfjlF1RnzP0GeJ0yOr SNGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tNZwUkKZtlmZ14jNWylohEgLi2zUCj6Z0VWU+7uDZNM=; b=eojVj3Zb2cugZ3H1ECGwVf9iLBuICUDhrRl+outM14QC3a7SQ2VUQKFhl+R7HE9Ne9 UCvOSs749RrHf6DikGVF7kJTmEBCZsPaiN4Oy248ohwxK4ypkX3h2DACvbpNpwwihlD9 qLPclnCXbLg/AB+s8dDSL6ypVshLCaM67lg220X/ebiBcysKWF8apxZ2oJ1hJM1B7it9 a12Gt5uHr43K6NVDceydPCqqulHTtQXWLbEpuBu/AG+yPGoCom9HfS/yOlidOV04epdg p/oLdg/6VMrYI6Qc2xNeaG59/mqjaKBoU+YYru1gIlA4ezTvzCIw4vII5iDKUx9x1Uyf K+Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=r+jnJOIB; 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 sb39-20020a1709076da700b006feb8253446si10071846ejc.749.2022.05.23.16.43.00; Mon, 23 May 2022 16:43:29 -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=r+jnJOIB; 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 S231693AbiEWWvQ (ORCPT + 99 others); Mon, 23 May 2022 18:51:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbiEWWvO (ORCPT ); Mon, 23 May 2022 18:51:14 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 433361003 for ; Mon, 23 May 2022 15:51:12 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id h5so22165352wrb.11 for ; Mon, 23 May 2022 15:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tNZwUkKZtlmZ14jNWylohEgLi2zUCj6Z0VWU+7uDZNM=; b=r+jnJOIBusH635WqI8fbwufkzACI9oCjiSIfKUDvHLseBJPHh9vUSZlWtwSH8Sydl+ p0/3xnIcp17otnrYR/qZYEtr6fCmmo/gji7kOUYPP6UyvM1lhwAZhAh+PfEezkRw1I+b 0l+aqABzU+E1xxYyggSXp2yt3nt7hQt8aIVYsfT0XMAZIcoUsbXMGNq3dYHqcSyQidme Y+uNXLp/WE5SR/6z9aJrefZIBRRQrknYRS8H+rvGVbIqlCI6X3PKndf5zmU9QieV6U0v r4hmfFl33JKtb0OxMQi2LHy5P1cGQYOlOTDCinO58dnFAPIIEWMTyKmgebufRzp65StN 2U6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tNZwUkKZtlmZ14jNWylohEgLi2zUCj6Z0VWU+7uDZNM=; b=t+KxhMivCuNwipQpKUkPYqiHibmM6yc39lidK1ljPAlSSnqnWE/rhhW1gwWjC16zB3 DBFQfdWpWNgwvLGrx2tX3ZyV4O0v1Jnbm1PKMH7rLtztlQNetuzkXtbIly19vLCK5hMN LPot1Pyo0tma6FnMJgPbDl+liYi7xwU2tTM8egbVky1Nuvk940tzzVXmGNYlTkvuhzAA HWWxZCVLTfIs7g1/4+jjAVDBSGIdKx7RmEYvSHif/xjGxUI1zBHrHZYV+brnlg1Ws8Js WE18kdSpBpcNMFdwnG1flWLQnxY+7TU85dfxJ3CrdHggsv9faSivzvlwV196D67L0Cg2 b72w== X-Gm-Message-State: AOAM530oXB6ihaT8bAXh+v5wvVdHsoOEojCzPW9Ve4lFuy4uFZdZt+wt PN/Vs7GkWxnK4jfQFdrsebnsZ4N6MDJuW3+lp9KNzQ== X-Received: by 2002:a05:6000:1548:b0:20f:c4bb:defd with SMTP id 8-20020a056000154800b0020fc4bbdefdmr11656246wry.210.1653346270703; Mon, 23 May 2022 15:51:10 -0700 (PDT) MIME-Version: 1.0 References: <20220518223815.809858-1-vaibhav@linux.ibm.com> <87zgjcg4xs.fsf@vajain21.in.ibm.com> In-Reply-To: From: Yosry Ahmed Date: Mon, 23 May 2022 15:50:34 -0700 Message-ID: Subject: Re: [PATCH] memcg: provide reclaim stats via 'memory.reclaim' To: Michal Hocko Cc: Vaibhav Jain , Cgroups , linux-doc@vger.kernel.org, Linux Kernel Mailing List , Linux-MM , Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Vladimir Davydov , Andrew Morton , "Aneesh Kumar K . V" , Shakeel Butt Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 On Fri, May 20, 2022 at 12:29 AM Michal Hocko wrote: > > On Fri 20-05-22 10:45:43, Vaibhav Jain wrote: > > > > Thanks for looking into this patch Michal, > > > > Michal Hocko writes: > > > > > On Thu 19-05-22 04:08:15, 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 > > > > > > Why cannot you use memory.stat? Sure it would require to iterate over > > > the reclaimed hierarchy but the information about scanned and reclaimed > > > pages as well as other potentially useful stats is there. > > > > Agree that "memory.stat" is more suitable for scanned/reclaimed stats as > > it already is exposing bunch of other stats. > > > > The discussion on this patch however seems to have split into two parts: > > > > 1. Is it a good idea to expose nr_scanned/nr_reclaimed to users-space > > and if yes how ? > > > > IMHO, I think it will be better to expose this info via 'memory.stat' as it > > can be useful insight into the reclaim efficiency and vmpressure. > > We already do that with some more metrics > pgrefill 9801926 > pgscan 27329762 > pgsteal 22715987 > pgactivate 250691267 > pgdeactivate 9521843 > pglazyfree 0 > pglazyfreed 0 > > > 2. Will it be useful to provide feedback to userspace when it writes to > > 'memory.reclaim' on how much memory has been reclaimed ? > > > > IMHO, this will be a useful feeback to userspace to better adjust future > > proactive reclaim requests via 'memory.reclaim' > > How precise this information should be? A very simplistic approach would > be > cp memory.stat stats.before > echo $WHATEVER > memory.reclaim > cp memory.stat stats.after > > This will obviously contain also activity outside of the explicitly > triggered reclaim (racing background/direct reclaim) but isn't that what > actually matters? Are there any cases where the only metric you care > about is the triggered reclaim in isolation? I think it might be useful to have a dedicated entry in memory.stat for proactively reclaimed memory. A case where this would be useful is tuning and evaluating userspace proactive reclaimers. For instance, if a userspace agent is asking the kernel to reclaim 100M, but it could only reclaim 10M, then most probably the proactive reclaimer is not using a good methodology to figure out how much memory do we need to reclaim. IMO this is more useful, and a superset of just reading the last reclaim request status through memory.reclaim (read stat before and after). Additionally, things get complicated if the userspace agent is multi-threaded. For a cumulative entry in memory.stat, it shouldn't matter by a lot as we are looking at the total for all threads cumulatively anyway. If we are only reading the memory reclaimed in the last request (through memory.reclaim), then we can easily get the results of a request that happened on a different thread. > > -- > Michal Hocko > SUSE Labs