Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5134988rwl; Mon, 3 Apr 2023 15:06:34 -0700 (PDT) X-Google-Smtp-Source: AKy350YKx+tHWle5ZRESMPLOGxiXD4TAH0mFLof0j+Q1ZyI+fUkIpWLfx56NDIb3kpmrkMhXGTXL X-Received: by 2002:a17:90b:3ec3:b0:234:106a:34ab with SMTP id rm3-20020a17090b3ec300b00234106a34abmr511038pjb.6.1680559594231; Mon, 03 Apr 2023 15:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680559594; cv=none; d=google.com; s=arc-20160816; b=uDjFAYq8iCdOCraEKkFBKJEHINZx0AlRY27s28WYMp4YltRwhI+LG517ECirO3xCXm La0TWQ5Dv3Fz/zTtpAAb7L19WB4g9JOrIXHD31HiwtBESA0LR9sXyUy4pyCxSJAhaUex Xo4ND+WyNbhBvUnKpdMoyDgdhZgV9fx0VF08f2uU+s+17dfGq1nLu6MbwwBgu9n03rFv PZZsxd6urlixhju8MobWhYukdK2gwy1cnwMacPV1EYVz2+cOQi0sEJjZIvvYbCQ5u5nu FuMgE2A0B+mA778TalTDjj+q84gKwcx7eyqrwMMZbDoHvmJx9TobEpYGcRfjdxdp/yYH sw+g== 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=S+Pu9YVys7d4kSNF1Q1j+VStoW6Udcnhp1204T10rf0=; b=maXwjH4FigQc6arOjYG9hXwTkD1YQQJmuKWkvaJmijk4GM1IpqYR7yUBPCj/1IKsh0 zhgTwZJVA9tnhLaM6lwzXLk+F9GQ6VRk7Zzlh9poDdgVhhQEd/IdOPetIgC5w9Byg1VZ wnLDooKIU47MyM4kBRGAkmBvooJL6Deul98oSARw03d4iA2Kw+/gDMoub8sVkuVmuFPy +BmQ759WVzgqtweNjlm9zqNCfeoEZfZ8KbiRuwrHhIcLi0GvX0JmBBYv9jJbpQI3YCug eZ2hVp34SbZD09s7PjuduxmqGibPOf5+k2kyi8tjMZj+zUM40aXvoj+FtsvRFgaXBWE/ hzrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MQc0fA7+; 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 i9-20020a170902eb4900b001a1c54c1a64si8749237pli.250.2023.04.03.15.06.22; Mon, 03 Apr 2023 15:06:34 -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=MQc0fA7+; 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 S229861AbjDCWFm (ORCPT + 99 others); Mon, 3 Apr 2023 18:05:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbjDCWFg (ORCPT ); Mon, 3 Apr 2023 18:05:36 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C4746AB for ; Mon, 3 Apr 2023 15:05:33 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id w9so123089048edc.3 for ; Mon, 03 Apr 2023 15:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680559532; 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=S+Pu9YVys7d4kSNF1Q1j+VStoW6Udcnhp1204T10rf0=; b=MQc0fA7+oJ5pXhxxZImDXr5z6gNisXy6E+KS8J35TPw72G5kFBVbjh7kwQJ1pYpeKX ALIeHYtsuFVit4ojWHQg4PjXvHbvMvILW8/w0oxNN8pueWh6LStay5FVuUqUuGorC5Z6 RS8g+Zsr99eX3NBfJHoshcrdMnlMJYyd2SsO+3bQTJdgfu4m5arn5ecYYnb97xK+LXBC ZBJkG0iOD7lxiLAB3PLydCsDk4EOZuHuZMpkwrwcF37r2t4CxP/ou8MAuJaMyMotyi7g GsK+x/49ejSIp1u7NJ8dsNOj8sud5LRpXF2CDd8KqUSH5kNjZsROpa5HzOhGwnXl/bTF B/Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680559532; 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=S+Pu9YVys7d4kSNF1Q1j+VStoW6Udcnhp1204T10rf0=; b=6DFdgBe7Co0WNHw9tBiaAyCVpjWp0GSE0zuQYXMhMv/YpZXXyx9VFmQgt6vyUZXtyW 7PqJefFYzygdxGgpb7OQdmbQOgNRsx3uLavdE07DF3qbVwUSRxsn5FUWZyispGfWeqeO ehI9JVOoo6mKczyieb41lVw1QBe+4vKztIk4v20QYzxh72HcadogukCSlwJxESJ86dGX WvjIdyhxjU3eWzh0epe08LVIooEGrOvlfnGxHbbjknynUEdTcnRv31dIMECuUFiLc4uq F7rVhWCv9C+bQLpWtzh2H3240xSg1dRnZNP5bKr2GAdx+nw+MXN9fPwPFPRuNVFDoq+r 5lWw== X-Gm-Message-State: AAQBX9c7GmJOLVhhCUC4Mcn6xkZJYZdpNbGiDAPJQoSTL1NQhyJkQ/Zc htKrFLRJDYexwWfvz/0NV8SXSuqWPH0d5/Tj5CVogg== X-Received: by 2002:a17:907:7894:b0:8e5:411d:4d09 with SMTP id ku20-20020a170907789400b008e5411d4d09mr85418ejc.15.1680559531710; Mon, 03 Apr 2023 15:05:31 -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, 3 Apr 2023 15:04:55 -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=-15.7 required=5.0 tests=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,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 Mon, Apr 3, 2023 at 3:03=E2=80=AFPM Yosry Ahmed = wrote: > > A previous patch series ([1] currently in mm-unstable) changed most .. and I naturally forgot to link this: [1] https://lore.kernel.org/linux-mm/20230330191801.1967435-1-yosryahmed@go= ogle.com/ > 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 >