Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2247689iob; Fri, 20 May 2022 05:29:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy85oCQhJywpwLm+Kt3xc1nazA5FabV+DISN8klr8RhmZAliDGLd05RQKzD21Xf2IKEHz+/ X-Received: by 2002:a65:554a:0:b0:3f6:885:b291 with SMTP id t10-20020a65554a000000b003f60885b291mr8179881pgr.608.1653049762927; Fri, 20 May 2022 05:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653049762; cv=none; d=google.com; s=arc-20160816; b=FU8QpX3FFmCknprDff3Gfsj8sd4C5VDWfKwgyMKdBRA4prY3SRtzpSA2DamdSzWiHd DV4sfBRcar1Q1LA9nCIW2YFZkcn2qUP+dl/WbZ5mzaqI1Nt3lpdkXUuRKJ25hd8QgRyx JSodotBl0pMsWPzWRlEaMD/p/PKVr7Dj/iAIOooSqwIq/zcP0MVmQfnnB3RcAeA6IODM /HyMLbEvAiCDPnrbt13vl6JOOQooKC6v6gBeKtFy8TL6VWd/F+WpzHRaozbWnt2pTYS6 bjaWdv+8aMw/bO+az026oF2aM54cD8uPMzijBZCbHe7IRSRaMIfNzBYujAIJ09QQrKCL lLwA== 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=69aaD4QPBI9GdAKDBus5t7k/zTxSvsdipve2TR2Ob64=; b=ln7hZXGHan0wy13UWIfK50mr4E4EZz5CORcxSpHA1sy7sDLAE66uJmfa81xRJXND4W 90K7xbIC3a4nx376yhKx3EaIAyoFaNmrmC2jCyhzwJ2crM7vZC2Q/dLXCRmLwRtNqvBe Vy02sCip6xWDR/q3lG4+Z60TbYx5BAMJcIoqZclB/UtQKdHCPaSVKGuVUvG0DRa6trRf PCIrMrtrYHri5EE/aKj0jonoBFDXxOsoV2FovjkW8tV/qAIXAP3HRRauD9dMcdcd1yC0 0gY8MCE+p2wy614SDi+CLGXZ0VAo8YsViJeYHyFppNB37jrzhVdXCyFVmKW6zjiuuAWf j97A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GkrWqpjb; 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 n7-20020a170903110700b00153b2d164afsi11383570plh.183.2022.05.20.05.29.06; Fri, 20 May 2022 05:29:22 -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=GkrWqpjb; 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 S243812AbiESSXd (ORCPT + 99 others); Thu, 19 May 2022 14:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243064AbiESSX3 (ORCPT ); Thu, 19 May 2022 14:23:29 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E00250E0E for ; Thu, 19 May 2022 11:23:27 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id f2so8384887wrc.0 for ; Thu, 19 May 2022 11:23:27 -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=69aaD4QPBI9GdAKDBus5t7k/zTxSvsdipve2TR2Ob64=; b=GkrWqpjb2yzPqkTVz9B3AF1h6LM7P8OXxi4jhC4daSBHKirsPkAj/SnhCBRObr6hEA WiRe4Wva0Ozk3jVncq2kBHskGsms1JYwqHmXoWzPjEPybLXpd46qdKbASSPGfdxi63vy LJQH7E7ZG4EQo1NMjCDQ0C21BbsohR5OpwSvd5tXaRitjNYoejlK5W2ozBG9NWI+9HsO 5EE6MfloqEZZ2bWuw2IDjRbqk6NiHnUWnmQgkFaiD6UyO98KHexuzXwqXY6gYRjB37Lv EhtgEtqHenGlbGslS2t3DXNV3YJTqWgMMvu0VwKxEOxEdNtIkE+6JtzxqyJGaKb+J7tA hXMA== 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=69aaD4QPBI9GdAKDBus5t7k/zTxSvsdipve2TR2Ob64=; b=iyEiQcTGfttaDog5Fh8zTICxvOiLGRjz1gTs/V4gKNnbtdYUmFLBRVj9TWgPfmG1RY d8HZjXBrMBeSVBA3QY/nhXCdR/dtUWEswEKeUyypWE1ri91tId+VWrbgHHIzCvfOKNsa Wurx94A5ZXgXuM3/PkCWgfYPqE+UJQeG7ULUoKFDFnohi1ZK/wEl34PDglUsAA9cYibZ r5dHfK4HNZdrPIIfRmK5Zowv1SJckKdgUihwR4qITjOIYTzxFi2aylL8dQQ7AUqyYI99 J35Wf+HnejZwNmQjdpjGzbkiI0VaQyi7WiEGUjAzJd8R0RVJPOfgafk+0AJOuf44xaiy TnPg== X-Gm-Message-State: AOAM5323VmFNW505rRoDIMRHn5/cnL0H+V6kil0BcI2EhiYh61Qtg55V HSIGkEkmg+vbYtMp5NS1adbcJnDm81v5pqPCJW+MVw== X-Received: by 2002:adf:fb05:0:b0:20a:e113:8f3f with SMTP id c5-20020adffb05000000b0020ae1138f3fmr5325035wrr.534.1652984605773; Thu, 19 May 2022 11:23:25 -0700 (PDT) MIME-Version: 1.0 References: <20220518223815.809858-1-vaibhav@linux.ibm.com> <878rqxhpn1.fsf@vajain21.in.ibm.com> In-Reply-To: <878rqxhpn1.fsf@vajain21.in.ibm.com> From: Yosry Ahmed Date: Thu, 19 May 2022 11:22:49 -0700 Message-ID: Subject: Re: [PATCH] memcg: provide reclaim stats via 'memory.reclaim' To: Vaibhav Jain Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, Linux Kernel Mailing List , Linux-MM , Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Michal Hocko , 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=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 On Thu, May 19, 2022 at 1:51 AM Vaibhav Jain wrote: > > Hi, > > Thanks for looking into this patch, > > Yosry Ahmed writes: > > > On Wed, May 18, 2022 at 3:38 PM 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 ? > > > > Isn't this a racy read? struct vmpressure can be changed between the > > write and read by other reclaim operations, right? > Read/write of vmpr stats is always done in context of vmpr->sr_lock > which is also the case for this patch. So not sure how the read is racy > ?. I didn't mean that you can read the value while it is being changed. I meant that between writing to memory.reclaim and reading from it, another reclaim operation could modify memcg vmpressure. A sequence like this: 1) Write to memory.reclaim 2) Kernel coincidentally runs reclaim on that memcg 3) Read from memory.reclaim The result would be that you are reading the stats of another reclaim operation, not the one invoked by writing to memory.reclaim. > > > > > I was actually planning to send a patch that does not updated > > vmpressure for user-controller reclaim, similar to how PSI is handled. > > > Ok, not sure if I am inferring correctly as to how how that would be > useful. Can you please provide some more context. IIUC vmpressure is used as an indicator for memory pressure. In my opinion it makes sense if vmpressure is not changed on reclaim operations directly invoked by the user, as they are not directly related to whether the system is under memory pressure or not. PSI is handled in a similar way. See e22c6ed90aa9 ("mm: memcontrol: don't count limit-setting reclaim as memory pressure"). > > The primary motivation for this patch was to expose the vmpressure stats > to user space that are available with cgroup-v1 but not with cgroup-v2 > AFAIK If the main goal is exposing vmpressure, regardless of proactive reclaim, this is something else. AFAIK vmpressure is not popular anymore and PSI is the more recent/better indicator. > > > The interface currently returns -EBUSY if the entire amount was not > > reclaimed, so isn't this enough to figure out if it was successful or > > not? > Userspace may very well want to know the amount of memory that was > partially reclaimed even though write to "memory.reclaim" returned > '-EBUSY'. This feedback can be useful info for implementing a retry > loop. > > > If not, we can store the scanned / reclaim counts of the last > > memory.reclaim invocation for the sole purpose of memory.reclaim > > reads. > Sure sounds reasonable to me. > > > Maybe it is actually more intuitive to users to just read the > > amount of memory read? In a format that is similar to the one written? > > > > i.e > > echo "10M" > memory.reclaim > > cat memory.reclaim > > 9M > > > Agree, I will address that in v2. > > > > -- > Cheers > ~ Vaibhav