Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3882385rwe; Mon, 17 Apr 2023 05:08:07 -0700 (PDT) X-Google-Smtp-Source: AKy350b2zWyQyvB0aYDnSeDO++AlAaXiEKLhjdC6cm0JnsDrv/m3bczqw7IzzjwS6AFTfWvp1MGj X-Received: by 2002:a05:6870:610f:b0:184:4669:6bd2 with SMTP id s15-20020a056870610f00b0018446696bd2mr8791959oae.43.1681733287663; Mon, 17 Apr 2023 05:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681733287; cv=none; d=google.com; s=arc-20160816; b=VCSpekd6RwI1sw6s8r2SfOxEMMvUC9RaWwWNyNsMVDqN8Qm+XWHhj8TeI3QOfNMmKG tgqWym3TVQWdAKjxddVQP3q0gtxTqKHK+JTOI/0f0oht6WJosvXrC3hT4veiP3VjMAuM KsXGE91xWRnpebNlhaEb5/NGVek3THBGBPn6ANSgJu4KMvgwzDMAPHLtOyimCnObyk7f VnB8gewKRsA7e32y/zdWXKbl0gYTP6kCCXy1XzipsnAhpDN+2IG9XLNqzqrGCxexHZDb jnKW/uEaqXw7JFfDL8CXl/mtISNZGTeYT084YPiKPXwTaJtnM4XWkbaX6d7nGXOn2r29 PtlQ== 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=hAfhUM23NLqVvA/6Hxfd6Xgc8oePCVqguK6TK2m4xx0=; b=Uwhsaw3yfOxK9RM7dule65a4i6MM+0z1OIDJ0g0EjKXqSF4eb0Rv7bM1F3UA12CdHC sf/HpO5lZdPRrFcHME19NFrZnn956pa8Z7J+qr1rrEt8czDQHdb6pLG1KdGX4kAcAIY8 zFTcIYtqTrHCVPwVC9/pM5yswD6c9wwlSYlpLzb4iGyojTMCfhMWt7tZl5UYymVGHtUL s76BA/PAq28LdjE+WgT2UbIxD69BFL3ekKfayvZTKlmy/sSRP+wEkGXvqUYMs3+DQ0DA yAosyun7tWNZeyXazeGhnbqnL5uYfuDlqU4pwzVOn3NPslTRunG1DdvPf/oo5B4t0erT QcvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=YOBGao3G; 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 s33-20020a056870eaa100b00180570000c2si9415797oap.72.2023.04.17.05.07.54; Mon, 17 Apr 2023 05:08:07 -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=YOBGao3G; 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 S229562AbjDQL4v (ORCPT + 99 others); Mon, 17 Apr 2023 07:56:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230322AbjDQL4r (ORCPT ); Mon, 17 Apr 2023 07:56:47 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10F1F98 for ; Mon, 17 Apr 2023 04:55:46 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id kt6so25219005ejb.0 for ; Mon, 17 Apr 2023 04:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681732535; x=1684324535; 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=hAfhUM23NLqVvA/6Hxfd6Xgc8oePCVqguK6TK2m4xx0=; b=YOBGao3Gh4rsypVOuHoE1ytvu3v+zzuIisiDjA+pAPLUyn2lc4W2y580wM0QGqDuBK t2E4fbgVIhzJkdNrXON9Fk4ppV/G0uJJY87Mggs8FmMDwvTtrBjmQayh9K/oWmrRXfDT w3OPKIPguHHmcs76WPPVys//oHx3UrhionPHUQHviOENI+JaZF1M/wpgoGXe0OqwfSVJ amMjGmlYHvk2HrrkdEj7F2j2V2hoSumB9UuA9pw4ITvpp7IPm19MV3XM8v0gk3ZoHHlA 4y71YZlBrpzkXhBU69R8xFtV1gn1I/z2Ufb4CZ7Dh1rW6T7kjFc6InE6Cpgq/99EkcVp jAwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681732535; x=1684324535; 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=hAfhUM23NLqVvA/6Hxfd6Xgc8oePCVqguK6TK2m4xx0=; b=Lv6a0uUuj/ilooMcn/rcu53JbMtW/nObGu/+wIu8z5cnJn9h2q7ruD/uSNuhcNszyT rd5ENc4Bx4V3iag/WffRp4fjfm+C9EoO9GjI1DUjgxPx6pLCDuxv58AGieA5LxIvS0D6 SSs8Fw7TMsebQZneCbNyB4q4+hcbA36RDEB14pEjeWvMpR04AspZ96znG3xabgPxhuy3 XMCq90gp5JQTeCCVSYmbp+PhiarV6oEuX5T5R+4KGvNsJWWR/haIjMhjlYCEAlCBWNt2 QMHnArv4DTExOLQQ/ALf+4nTQqDW9lcFFK4T2TAX5rRpCaZB43Ct7xe2Xt4pKA+OEYX5 bhkA== X-Gm-Message-State: AAQBX9fjby74UIIzC15frwIbGdpY+9sOvJ0uxa9iatAbt0M3cfWbPLhH VxIjjsM4wqswMYa4zbmy26/OrHWG+YVRBZbVR6La9g== X-Received: by 2002:a17:906:2656:b0:94e:5f2a:23fe with SMTP id i22-20020a170906265600b0094e5f2a23femr3568963ejc.5.1681732534659; Mon, 17 Apr 2023 04:55:34 -0700 (PDT) MIME-Version: 1.0 References: <20230403220337.443510-1-yosryahmed@google.com> In-Reply-To: <20230403220337.443510-1-yosryahmed@google.com> From: Yosry Ahmed Date: Mon, 17 Apr 2023 04:54:52 -0700 Message-ID: Subject: Re: [PATCH mm-unstable RFC 0/5] cgroup: eliminate atomic rstat To: Alexander Viro , Christian Brauner , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.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_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 Mon, Apr 3, 2023 at 3:03=E2=80=AFPM Yosry Ahmed = wrote: > > A previous patch series ([1] currently in mm-unstable) changed most > atomic rstat flushing contexts to become non-atomic. This was done to > avoid an expensive operation that scales with # cgroups and # cpus to > happen with irqs disabled and scheduling not permitted. There were two > remaining atomic flushing contexts after that series. This series tries > to eliminate them as well, eliminating atomic rstat flushing completely. > > The two remaining atomic flushing contexts are: > (a) wb_over_bg_thresh()->mem_cgroup_wb_stats() > (b) mem_cgroup_threshold()->mem_cgroup_usage() > > For (a), flushing needs to be atomic as wb_writeback() calls > wb_over_bg_thresh() with a spinlock held. However, it seems like the > call to wb_over_bg_thresh() doesn't need to be protected by that > spinlock, so this series proposes a refactoring that moves the call > outside the lock criticial section and makes the stats flushing > in mem_cgroup_wb_stats() non-atomic. > > For (b), flushing needs to be atomic as mem_cgroup_threshold() is called > with irqs disabled. We only flush the stats when calculating the root > usage, as it is approximated as the sum of some memcg stats (file, anon, > and optionally swap) instead of the conventional page counter. This > series proposes changing this calculation to use the global stats > instead, eliminating the need for a memcg stat flush. > > After these 2 contexts are eliminated, we no longer need > mem_cgroup_flush_stats_atomic() or cgroup_rstat_flush_atomic(). We can > remove them and simplify the code. > > Yosry Ahmed (5): > writeback: move wb_over_bg_thresh() call outside lock section > memcg: flush stats non-atomically in mem_cgroup_wb_stats() > memcg: calculate root usage from global state > memcg: remove mem_cgroup_flush_stats_atomic() > cgroup: remove cgroup_rstat_flush_atomic() > > fs/fs-writeback.c | 16 +++++++---- > include/linux/cgroup.h | 1 - > include/linux/memcontrol.h | 5 ---- > kernel/cgroup/rstat.c | 26 ++++-------------- > mm/memcontrol.c | 54 ++++++++------------------------------ > 5 files changed, 27 insertions(+), 75 deletions(-) > > -- > 2.40.0.348.gf938b09366-goog > Any thoughts on this series, anyone? :)