Received: by 2002:ac8:760c:0:b0:40f:fb00:664b with SMTP id t12csp921632qtq; Thu, 14 Sep 2023 22:30:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElHEZ/TMWWmgP4863njDU0AeRXoC6fNbrO9hswxt6PiPhnWJSq6wfBy4nC629oVDQNHdLX X-Received: by 2002:a17:90a:a602:b0:26d:689f:4253 with SMTP id c2-20020a17090aa60200b0026d689f4253mr5403091pjq.6.1694755825720; Thu, 14 Sep 2023 22:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694755825; cv=none; d=google.com; s=arc-20160816; b=KIy9k3CBe7rFDNbmTL0QyQoJSK9+qgMfiVe/OjMpSkJmC83Ih2aUR15Ol/qwWHeYTj ix+QtZp8jGcWu8ePixgfEB3pnjl3T8WgFOskN6vgL3qmcXcjIBsd3GAS5aPepto2Q3/r QtTYP8lPB2jZvjHBNxyl6jZAe5pktljQvNEgKNKDStMY3n01zubzlzYBq2lQfaocopFy WRy4IdA//BDNHzWFd7bBITwkZ3XRlM4UBJARHgS6ts1ZvbiQ1MeC4wMy2Hkfx4iFYnZz PErIXIvC1IKLCh2Yl1Ab2Cr+UIbFCNwuvMSrAUyM/N43NlbGULQ7v7vEa2uSAECkwyQr Hgpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=r7Rb24jsu1Obt5C61wSLsWivJKBy0po7p8YAHy1mWV0=; fh=xoUKUYwsHP88jVXv8iAtrUCIr9Fd+NLU74akQLg97ME=; b=j2rc4L4D2x2dmD4y0SFVCzbvm6bllOrPcT7p3/7vwmZ3UWAyGCP6gTWzoO/9tc/1RP BvUKJlJL6V62qiTJXmRi9jOQyFogmAiX7T5MGmyXYFjQNE5+qtachN4qQfAy3FAFYP8v XinjOIFOvaT7gHzCxnKswRyt8Y5n/swVST/5QOb779PJEtxkkBO+C4Dk1kqnX/WIhBeV C/msxjEBXprMGLGqdD/LN/dkO0v4mqYjWFdT6OgfaUBAs6n1k+zQe/mlV64hOOgj09of 7yOUEniOliYnIATIeuXi7z2Fr79i/D/HhpIAZllcLk4NM0HUIr79fH39EpGtOWI1Qe0s BhVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ec94cJ09; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id mu12-20020a17090b388c00b00268300061cdsi5371121pjb.168.2023.09.14.22.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 22:30:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ec94cJ09; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id CF83B81F8509; Thu, 14 Sep 2023 16:32:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230373AbjINXb6 (ORCPT + 99 others); Thu, 14 Sep 2023 19:31:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230408AbjINXbo (ORCPT ); Thu, 14 Sep 2023 19:31:44 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2E372D48 for ; Thu, 14 Sep 2023 16:31:36 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9aa0495f9cfso581285466b.1 for ; Thu, 14 Sep 2023 16:31:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694734295; x=1695339095; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=r7Rb24jsu1Obt5C61wSLsWivJKBy0po7p8YAHy1mWV0=; b=ec94cJ09zKdzjHAXxU1iRkThGliciKFPhphW1t4eNFS4oSPl3XsbT+Vug8CSQ8qmjs 0W2BS5XmVYmJobS3Mer6nPsVBXBxNIg+AQtfL2xgcSHJOw0dDMSdJuBQcl3DrcLDL1n3 VNkQOnjMJaf8laRkx+kHoJ3babjO5UqhUKysdabSfYo++J0b/1QWcA9tMlrwcYR+3w2U 48f+fQxE5HQCRtHS95YEc30BodxZevyHNYFWSZgw0jqBHjtGa7yoZnPEF9qAYyDF7xuc mPgpSbKxKfIOzf7cSDCyEtPTVviPa/u1FhFGZtI8nSLQErVztPSpn+7HlJEpdA6Zf6Ih 2GLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694734295; x=1695339095; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r7Rb24jsu1Obt5C61wSLsWivJKBy0po7p8YAHy1mWV0=; b=J56wPYnt6EM6YUAeCUxtujwU64yOHWbDeswNB/ktp3cz1OB5vKcmqTIT2kA6SYi+RD 9zG1dgLWMlS6/4jJbdxAsyfdWK01nZa0il+9eFO4aS2llDd9VmkkluecwjZCiwwlzMa/ EcY3T+5+VndkIa2KVg6u1JWA9fnL6P9eEguJ4XKtARYX6qoBBRHTIvT1DvXmMFS/U+z7 9wgFjx8DtNFotuisQUahLQwPw5YlsKwLqEOtDL1FeKXWG91+wSE7+UZBO0oSGZ8LqV8j +6Acs0s+8SJdnRXOP4Luc+m6OfF9VW0ERqbFJ83AhvQlMfC4y9vMWCaj2PecyLtjbpPj LUIA== X-Gm-Message-State: AOJu0Yx3vsa885FD7faUwTDGEH7BLAKjH4s+mfuLRHwx05boqn4x7MSu BEs+74AargRtjBu/bU2e45qrwttFtbE2Fnl98522Lg== X-Received: by 2002:a17:906:5a5f:b0:9a5:9305:83fb with SMTP id my31-20020a1709065a5f00b009a5930583fbmr100497ejc.34.1694734294841; Thu, 14 Sep 2023 16:31:34 -0700 (PDT) MIME-Version: 1.0 References: <20230913073846.1528938-1-yosryahmed@google.com> <20230913073846.1528938-4-yosryahmed@google.com> <20230914225844.woz7mke6vnmwijh7@google.com> In-Reply-To: <20230914225844.woz7mke6vnmwijh7@google.com> From: Yosry Ahmed Date: Thu, 14 Sep 2023 16:30:56 -0700 Message-ID: Subject: Re: [PATCH 3/3] mm: memcg: optimize stats flushing for latency and accuracy To: Shakeel Butt Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Ivan Babrou , Tejun Heo , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Waiman Long , kernel-team@cloudflare.com, Wei Xu , Greg Thelen , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 14 Sep 2023 16:32:02 -0700 (PDT) X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 agentk.vger.email On Thu, Sep 14, 2023 at 3:58=E2=80=AFPM Shakeel Butt = wrote: > > On Thu, Sep 14, 2023 at 10:56:52AM -0700, Yosry Ahmed wrote: > [...] > > > > > > 1. How much delayed/stale stats have you observed on real world workl= oad? > > > > I am not really sure. We don't have a wide deployment of kernels with > > rstat yet. These are problems observed in testing and/or concerns > > expressed by our userspace team. > > > > Why sleep(2) not good enough for the tests? The problem is not making the tests pass. The tests are just a signal. > > > I am trying to solve this now because any problems that result from > > this staleness will be very hard to debug and link back to stale > > stats. > > > > I think first you need to show if this (2 sec stale stats) is really a > problem. That's the thing, my main concern is that if this causes a problem, we probably won't be able to tell it was because of stale stats. It's very hard to make that connection. Pre-rstat, reading stats would always yield fresh stats (as much as possible). Now the stats can be up to 2s stale, and we don't really know how this will affect our existing workloads. > > > > > > > 2. What is acceptable staleness in the stats for your use-case? > > > > Again, unfortunately I am not sure, but right now it can be O(seconds) > > which is not acceptable as we have workloads querying the stats every > > 1s (and sometimes more frequently). > > > > It is 2 seconds in most cases and if it is higher, the system is already > in bad shape. O(seconds) seems more dramatic. So, why 2 seconds > staleness is not acceptable? Is 1 second acceptable? or 500 msec? Let's > look at the use-cases below. > > > > > > > 3. What is your use-case? > > > > A few use cases we have that may be affected by this: > > - System overhead: calculations using memory.usage and some stats from > > memory.stat. If one of them is fresh and the other one isn't we have > > an inconsistent view of the system. > > - Userspace OOM killing: We use some stats in memory.stat to gauge the > > amount of memory that will be freed by killing a task as sometimes > > memory.usage includes shared resources that wouldn't be freed anyway. > > - Proactive reclaim: we read memory.stat in a proactive reclaim > > feedback loop, stale stats may cause us to mistakenly think reclaim is > > ineffective and prematurely stop. > > > > I don't see why userspace OOM killing and proactive reclaim need > subsecond accuracy. Please explain. For proactive reclaim it is not about sub-second accuracy. It is about doing the reclaim then reading the stats immediately to see the effect. Naturally one would expect that a stat read after reclaim would show the system state after reclaim. For userspace OOM killing I am not really sure. It depends on how dynamic the workload is. If a task recently had a spike in memory usage causing a threshold to be hit, userspace can kill a different task if the stats are stale. I think the whole point is *not* about the amount of staleness. It is more about that you expect a stats read after an event to reflect the system state after the event. Whether this event is proactive reclaim or a spike in memory usage or something else. As Tejun mentioned previously [1]: "The only guarantee you need is that there has been at least one flush since the read attempt started". [1]https://lore.kernel.org/lkml/ZP92xP5rdKdeps7Z@mtj.duckdns.org/ > Same for system overhead but I can > see the complication of two different sources for stats. Can you provide > the formula of system overhead? I am wondering why do you need to read > stats from memory.stat files. Why not the memory.current of top level > cgroups and /proc/meminfo be enough. Something like: > > Overhead =3D MemTotal - MemFree - SumOfTopCgroups(memory.current) We use the amount of compressed memory in zswap from memory.stat, which is not accounted as memory usage in cgroup v1. > > > > > > > I know I am going back on some of the previous agreements but this > > > whole locking back and forth has made in question the original > > > motivation. > > > > That's okay. Taking a step back, having flushing being indeterministic > > I would say atmost 2 second stale instead of indeterministic. Ack. > > > in this way is a time bomb in my opinion. Note that this also affects > > in-kernel flushers like reclaim or dirty isolation > > Fix the in-kernel flushers separately. The in-kernel flushers are basically facing the same problem. For instance, reclaim would expect a stats read after a reclaim iteration to reflect the system state after the reclaim iteration. > Also the problem Cloudflare is facing does not need to be tied with this. When we try to wait for flushing to complete we run into the same latency problem of the root flush.