Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp448699rwo; Fri, 21 Jul 2023 14:48:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlGOjYZXwVt4rkZrsQHVUM5ULzIE1F9jVtkRI/OG8HSZcvkHznPEflk8WvWRgeVqXwLCq/ou X-Received: by 2002:a17:903:1c7:b0:1bb:14e7:4fdc with SMTP id e7-20020a17090301c700b001bb14e74fdcmr3709158plh.61.1689976091238; Fri, 21 Jul 2023 14:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689976091; cv=none; d=google.com; s=arc-20160816; b=kxtR1Uv/WDYZhDKW2WPngPz0SLuolTuWqqoraTxSybBzm+PdCpu1NAEAU7s7kpqNr6 Z/pcVi2NqZ6AcopIJLa9NvwIu+wn7BG8phPdkpHgfdelZ0g/3NJsZCS9so6EoJaE90fU Fmwvf8ZAV7xwNwKAbfPE1gpXb2yH5ySFfqygh1mwYugtUh11pqtON4Fwkh6Ghsc3JMI0 G2NNNwrZ1QVQWWRE8899XA0B8r4j/eA/BD0YdV70dh+ROV9l9SlNEXTk363iQ686mHXi LT+b3VzyX1em66oEHUh53IvsEMDKinyfXIJ1zx+crob+teg/GNcHpVnAd8Y+mbP+NIZt SZfg== 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=JOgbHJec+Tti6Wru7OdTqH4+oMnk38DLOG9c4qJJzP8=; fh=c1UwdoVUBWpDs9BsiNGqncHEg1NGWxVsao3/QkzTiuQ=; b=n5X/sPJ5gG5BIEez711ldngeCSMKGcOewvF/sb2LGdGrwmXFiR89WKV4HVecJ4w/1w dpykCvGOX3N0hbDKBXBFGYDGhbblX6XIrvDjOWdGUr+mZwM7lpqKmShyiC9kADpeXztY kXTyfVNPq4dUj0JEuPptix9SthZf5FsqpkSVWtC5m09jExPHIQPwhYEDk23mnKHTStnk ezBvfNjJUVuNJDmhFwt8r7/002Er0cnQsKvEJPD4EodfwJ3NwAccfzALeNzaVcXUsxYI 6ZrMbZjQPKssEy15d8dFkZTVg1V2pvZ+c18c6RSgprPvhqnRu6IQstmTWoKerG152nHK iHVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hkZ+D5g5; 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 o5-20020a170902d4c500b001b6788a5528si4105946plg.622.2023.07.21.14.47.58; Fri, 21 Jul 2023 14:48:11 -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=20221208 header.b=hkZ+D5g5; 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 S230460AbjGUVAg (ORCPT + 99 others); Fri, 21 Jul 2023 17:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjGUVAe (ORCPT ); Fri, 21 Jul 2023 17:00:34 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 650FE2D46 for ; Fri, 21 Jul 2023 14:00:33 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-51e29ede885so3073819a12.3 for ; Fri, 21 Jul 2023 14:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689973232; x=1690578032; 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=JOgbHJec+Tti6Wru7OdTqH4+oMnk38DLOG9c4qJJzP8=; b=hkZ+D5g5lDrDl4A690EnFIQrEBWzd57RPaM7SaKw8Y1xk7u1cAMRN4ld2mJkGcGqTY /owNQyHKnflgKZIMZHrBc4AfSR3tYOaMOz+dYxvCdQz1ey2+U9QmjTviN0Qum0KxXOdw 8SFQWbBe/mtcxHqLJFyQClCzU3YhFgrJb03GP0qsdY0KqtaR9x7Hx4Kq9tfA6JVlHuMC ypntCYhcJXE3lxIkq+N9LeOkrGyUDm31Kih652QMPZI12bzYmDTEAxVdi1OIoHwEX4uX mQtgA1yxQCz6Ur0+IYN0S57Jk3wDnFBAsv0rrUdhewR+YipnqPXBqEiLqMAQS7fN91mG kzeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689973232; x=1690578032; 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=JOgbHJec+Tti6Wru7OdTqH4+oMnk38DLOG9c4qJJzP8=; b=DwMI6dacj2EfS1iG4yXtMBudmtvWa2SgteLBgZyMKOH/pi6Wx7iNS48bHVRfCWM/vA fP7CMlWWkA1aAAZ7dTQ2HDyfDjJUJeHkoF1cRiHUAblbjrSLvglzhDBshI7L+/V3QQXY kYJJwFbCmAQ8ekpnGY4CQjrIHtVJeT58yQl6/wHkcGv1rPHtkVaw6GUzj7ynLVmffHbT 0x7VspEjpvQYU8l/aJvdbLLzmG0XM6R+3nCftnbbumTIoZhE7oMv9gRgPR82UDfSub0Q mtBauf/HAhyJj4b69nynmrHAIOaZfGn3RBD1xKS+AW3nEmjcXYNEqgw7MFVYAaJls8Qb 5Dxw== X-Gm-Message-State: ABy/qLZr4OpxPXHEkDKY6pE6RV07/6ZE2Vq+aYFMW0cHNqwkxzX8Ho2t 4tT+W6SeIgMfS332jmNSf4kWmKSFbKP+65MtlfrJIw== X-Received: by 2002:a17:906:101a:b0:98d:cd3e:c193 with SMTP id 26-20020a170906101a00b0098dcd3ec193mr2203336ejm.46.1689973231695; Fri, 21 Jul 2023 14:00:31 -0700 (PDT) MIME-Version: 1.0 References: <20230720070825.992023-1-yosryahmed@google.com> <20230720153515.GA1003248@cmpxchg.org> <20230721204408.GA1033322@cmpxchg.org> In-Reply-To: <20230721204408.GA1033322@cmpxchg.org> From: Yosry Ahmed Date: Fri, 21 Jul 2023 13:59:55 -0700 Message-ID: Subject: Re: [RFC PATCH 0/8] memory recharging for offline memcgs To: Johannes Weiner Cc: Tejun Heo , Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , "Matthew Wilcox (Oracle)" , Zefan Li , Yu Zhao , Luis Chamberlain , Kees Cook , Iurii Zaikin , "T.J. Mercier" , Greg Thelen , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_BLOCKED,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, Jul 21, 2023 at 1:44=E2=80=AFPM Johannes Weiner wrote: > > On Fri, Jul 21, 2023 at 11:47:49AM -0700, Yosry Ahmed wrote: > > On Fri, Jul 21, 2023 at 11:26=E2=80=AFAM Tejun Heo wrot= e: > > > > > > Hello, > > > > > > On Fri, Jul 21, 2023 at 11:15:21AM -0700, Yosry Ahmed wrote: > > > > On Thu, Jul 20, 2023 at 3:31=E2=80=AFPM Tejun Heo w= rote: > > > > > memory at least in our case. The sharing across them comes down t= o things > > > > > like some common library pages which don't really account for muc= h these > > > > > days. > > > > > > > > Keep in mind that even a single page charged to a memcg and used by > > > > another memcg is sufficient to result in a zombie memcg. > > > > > > I mean, yeah, that's a separate issue or rather a subset which isn't = all > > > that controversial. That can be deterministically solved by reparenti= ng to > > > the parent like how slab is handled. I think the "deterministic" part= is > > > important here. As you said, even a single page can pin a dying cgrou= p. > > > > There are serious flaws with reparenting that I mentioned above. We do > > it for kernel memory, but that's because we really have no other > > choice. Oftentimes the memory is not reclaimable and we cannot find an > > owner for it. This doesn't mean it's the right answer for user memory. > > > > The semantics are new compared to normal charging (as opposed to > > recharging, as I explain below). There is an extra layer of > > indirection that we did not (as far as I know) measure the impact of. > > Parents end up with pages that they never used and we have no > > observability into where it came from. Most importantly, over time > > user memory will keep accumulating at the root, reducing the accuracy > > and usefulness of accounting, effectively an accounting leak and > > reduction of capacity. Memory that is not attributed to any user, aka > > system overhead. > > Reparenting has been the behavior since the first iteration of cgroups > in the kernel. The initial implementation would loop over the LRUs and > reparent pages synchronously during rmdir. This had some locking > issues, so we switched to the current implementation of just leaving > the zombie memcg behind but neutralizing its controls. Thanks for the context. > > Thanks to Roman's objcg abstraction, we can now go back to the old > implementation of directly moving pages up to avoid the zombies. > > However, these were pure implementation changes. The user-visible > semantics never varied: when you delete a cgroup, any leftover > resources are subject to control by the remaining parent cgroups. > Don't remove control domains if you still need to control resources. > But none of this is new or would change in any way! The problem is that you cannot fully monitor or control all the resources charged to a control domain. The example of common shared libraries stands, the pages are charged on first touch basis. You can't easily control it or monitor who is charged for what exactly. Even if you can find out, is the answer to leave the cgroup alive forever because it is charged for a shared resource? > Neutralizing > controls of a zombie cgroup results in the same behavior and > accounting as linking the pages to the parent cgroup's LRU! > > The only thing that's new is the zombie cgroups. We can fix that by > effectively going back to the earlier implementation, but thanks to > objcg without the locking problems. > > I just wanted to address this, because your description/framing of > reparenting strikes me as quite wrong. Thanks for the context, and sorry if my framing was inaccurate. I was more focused on the in-kernel semantics rather than user-visible semantics. Nonetheless, with today's status or with reparenting, once the memory is at the root level (whether reparented to the root level, or in a zombie memcg whose parent is root), the memory has effectively escaped accounting. This is not a new problem that reparenting would introduce, but it's a problem that recharging is trying to fix that reparenting won't. As I outlined above, the semantics of recharging are not new, they are equivalent to reclaiming and refaulting the memory in a more accelerated/efficient manner. The indeterminism in recharging is very similar to reclaiming and refaulting. What do you think?