Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4285898rdb; Thu, 14 Sep 2023 18:57:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwfvStR2x5K3Vii7bkXpbXrsNSRK7+uJv0xkdw6J0jLeZD1bNwDOkvJhipRIDVZc2Z4IQj X-Received: by 2002:a17:903:4285:b0:1c3:4565:225 with SMTP id ju5-20020a170903428500b001c345650225mr318186plb.10.1694743073665; Thu, 14 Sep 2023 18:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694743073; cv=none; d=google.com; s=arc-20160816; b=d7/pXhj7DIDnX77FDRlQDDnUYJEWgOzP77Q6leJcuhcSRbxbUjjBA8rE5ZG9zn/Rfg 3zhqA3IOGNMbJYo+jxIllWCjVgeXPiRCFh1yayUeuR3kUwm2k1SFEJsrODSWBR1EYoCj lOjwGnqaW50QtnvThWWuRW0rtS3D/sV1id0EWC+VHCZMLT6gPvSOm+MKKNl6fOK9/TTe f41HCKs8rt7CWFEIA2r3WWcdhzuQ33YFpemNBpL3HMYldf2//UhZ5if5qZSp4YDfjZPO zlc1ojpphvCalD8u9JbzOR+0blhq3c/MHOyNmBOnqTecvQnnbjF+pe9/pUG5aEE21Lot 8AWQ== 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=ljbrHfpo2IKe26opU5ehmoNQnl15X51TY3BJK0gEGYU=; fh=FliBBm5o+YgmQVfOIrBzy/uWPpKZJLxbs5bNc203T7I=; b=dBzwa3t79La5U/cVHNE/99g2RJ7SKm62JZmBr1HiV0Ye2v0nAjA0IR6E0jWf7fX/qr bnqLD+XCPfaOoZrXFUf9vPYALooAhSGt/MlpWbmm8HLZDm5tviXsLdCaDhtXDmlz5hap f//9yZUiPSqXT9XdRLf6e2ShHNd7+kmPhafZkfvdeRb2NNHjT9qnFyJziST84ztkFtV1 P+JAfqbASqeh7DRZR4+d1iN6uVQ9X1MjkrdJ7fi9E0i2ymtrxX8zVmPU0B6Qjk/96ODv i7eNhBeEBGm4tGw0DGAHqxKAPjnWalc84CUO41It/g2x7rkXFT/27Ywak5HWt0R5LGht mM0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qmReZO2B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id b5-20020a170902650500b001b9e383bb34si2486393plk.120.2023.09.14.18.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 18:57:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qmReZO2B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 6657080BA7CF; Thu, 14 Sep 2023 10:36:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232399AbjINRgq (ORCPT + 99 others); Thu, 14 Sep 2023 13:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbjINRgp (ORCPT ); Thu, 14 Sep 2023 13:36:45 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F295B1BFE for ; Thu, 14 Sep 2023 10:36:40 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c382f23189so13235ad.0 for ; Thu, 14 Sep 2023 10:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694713000; x=1695317800; 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=ljbrHfpo2IKe26opU5ehmoNQnl15X51TY3BJK0gEGYU=; b=qmReZO2Bb4EeDD8PD3bNjkvqwYj4p9DvDkLEd0v88Rlhw60VWyPmfHMZe2xl7GnwVv zTLHAnXZit7yew1KB+QXuasZRjmbdfZB8MJwBG/dt6+VJydPqJ90RlMULPiU23He9Wvk 0xWofpItOubu4YAq15TgH3CxGohX16qekNcKm2wz8KFfXdA2vv5zg2dXsgiaPINlsoxC PyJQmeLDu50whdZZM4U/9KZKq1x9gfXXoFgkMImQ1BcWbshnWMvffbE7Zdi6rNgJY01g d8QtehQ3t8KbqlT9II//3izlGw88QwDw4eg2lSWugnxCeSoaThv1QDsqpsuRo2zjZjP5 eE2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694713000; x=1695317800; 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=ljbrHfpo2IKe26opU5ehmoNQnl15X51TY3BJK0gEGYU=; b=YcX2jsnuail5BByrCXloCvq/27wiGnzMarPMjuSHFYT2R8ijHjydOSQDHHhWZM1O0i j84npTfuda7elCvM+hWPF+xZlIqZdmNzlI6ko51tWY2cMgRZHGJjfEQilRXlZ0QNCCU0 wghxcXefTBVgO72EMcrk1cFcc/oHu2vUhpCpo8xvR33GTFd4CVriWFAry8FC3tcNJg/+ k6X660Lw4m88quDRf3aYXOZ3d9H+Rij1RQGYH+VW6umzskNcnZNRIJqie+uAZ+GFbH9a moqckelUujcXGOxIczV/e/Gn/p7ER7XbEcNtBzz0PSsOnCoHmQho6E+/+2MOgLEq7cFI YjSA== X-Gm-Message-State: AOJu0YwBUUBfS6Rft/dxDWgdSmyq/amuLd313eChRoo7pRwlMfNkHN83 mTTl9eUEus33oG8CpLRoR+Q9qiph1WeFSo9M/UZxFilfTyQ1leO8SHs= X-Received: by 2002:a17:902:a3c8:b0:1c1:efe5:ccf8 with SMTP id q8-20020a170902a3c800b001c1efe5ccf8mr9658plb.17.1694713000337; Thu, 14 Sep 2023 10:36:40 -0700 (PDT) MIME-Version: 1.0 References: <20230913073846.1528938-1-yosryahmed@google.com> <20230913073846.1528938-4-yosryahmed@google.com> In-Reply-To: <20230913073846.1528938-4-yosryahmed@google.com> From: Shakeel Butt Date: Thu, 14 Sep 2023 10:36:28 -0700 Message-ID: Subject: Re: [PATCH 3/3] mm: memcg: optimize stats flushing for latency and accuracy To: Yosry Ahmed 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 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 10:36:47 -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 groat.vger.email On Wed, Sep 13, 2023 at 12:38=E2=80=AFAM Yosry Ahmed wrote: > > Stats flushing for memcg currently follows the following rules: > - Always flush the entire memcg hierarchy (i.e. flush the root). > - Only one flusher is allowed at a time. If someone else tries to flush > concurrently, they skip and return immediately. > - A periodic flusher flushes all the stats every 2 seconds. > > The reason this approach is followed is because all flushes are > serialized by a global rstat spinlock. On the memcg side, flushing is > invoked from userspace reads as well as in-kernel flushers (e.g. > reclaim, refault, etc). This approach aims to avoid serializing all > flushers on the global lock, which can cause a significant performance > hit under high concurrency. > > This approach has the following problems: > - Occasionally a userspace read of the stats of a non-root cgroup will > be too expensive as it has to flush the entire hierarchy [1]. This is a real world workload exhibiting the issue which is good. > - Sometimes the stats accuracy are compromised if there is an ongoing > flush, and we skip and return before the subtree of interest is > actually flushed. This is more visible when reading stats from > userspace, but can also affect in-kernel flushers. Please provide similar data/justification for the above. In addition: 1. How much delayed/stale stats have you observed on real world workload? 2. What is acceptable staleness in the stats for your use-case? 3. What is your use-case? 4. Does your use-case care about staleness of all the stats in memory.stat or some specific stats? 5. If some specific stats in memory.stat, does it make sense to decouple them from rstat and just pay the price up front to maintain them accurately? Most importantly please please please be concise in your responses. 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. thanks, Shakeel