Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7806567rwl; Thu, 23 Mar 2023 08:54:48 -0700 (PDT) X-Google-Smtp-Source: AK7set9ZgzREpvbxlr45j4zTJj/5fRTcCgpJIJ0P+KlmGPGpx6hVgqyR5JUDvefCK0Ur5K3l2uVr X-Received: by 2002:a17:906:a20f:b0:930:1178:2220 with SMTP id r15-20020a170906a20f00b0093011782220mr10331895ejy.40.1679586888716; Thu, 23 Mar 2023 08:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679586888; cv=none; d=google.com; s=arc-20160816; b=1AX12x9kqSeNa55OJGkT1sb/XU7ayZJVO+eiWpld9Y8DrQQ56svwbsu0/UU6gcIpw4 rvmQZt7ergF7drR1/f8CXwdBDI0Ys4U6p28tdjB11hnLNpkkJ4hFUQ2NFdMdXrQnGFfs jZ4qDdSx3QNlyAhnBcpgr7tEDLRlM3PKovLuEHiQeP7bVL0SrTgNDi+a7ludksX9bSUh KEOcId79RZhEs8G94iWPBEKJQuaxypRj6L5aDiy3jdAdThtV2nT3pRW4eroBXf1rmwAv URgH9mE7O0xl+gSEtk76bgos88y7ltlpItOKh/A3B2CyjFsQxvprffONYPbFY6glQozJ 1IiQ== 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=TIHMsdmfle7NugjLuFYQiNRPSMKIKN1rr5aYwFC8Kug=; b=FHR89s7NarkMkxEVtwosRC2M5tzvL1Sg0/b4ZLZvDM4ntWjca4/Vilpv+Qo8qCop3M hR/Vb6AZW5NdulOmCKHLTtG1d/Ty833SGtoYuCKn7DUb5XlYEGXN57lVaXRBXEZGobXH p5DD6FRalGhI69qc44xBaTUFY/s7exQrfd+clN0ClTT+J6pR5sZ+Iky07087XDtXNeyZ XzWIEQwQZLiVTCISVbnNx4hJy+9RDInKOVvaPt35qOJhwPo4N3rKQB/TQA3X+YkJ3Jt7 XfuYiyp93TpXKtPa3oVOzs0FiKJXrzSq7HLjFeZF156uf4sKVWicAv44fhvCNwKGt4/+ 9Wmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NnpqzKnh; 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 z18-20020a17090655d200b0093ae5807239si5210896ejp.71.2023.03.23.08.54.24; Thu, 23 Mar 2023 08:54:48 -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=NnpqzKnh; 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 S231488AbjCWPqk (ORCPT + 99 others); Thu, 23 Mar 2023 11:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231439AbjCWPqi (ORCPT ); Thu, 23 Mar 2023 11:46:38 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C8621BAF1 for ; Thu, 23 Mar 2023 08:46:36 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id eh3so88572621edb.11 for ; Thu, 23 Mar 2023 08:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679586395; 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=TIHMsdmfle7NugjLuFYQiNRPSMKIKN1rr5aYwFC8Kug=; b=NnpqzKnhqFnJAt8X+CKmsaMihz2+x72k0iSwes0Z93hrQCCmnIjykaTSGPeNQ5pFhH Ihrt+7xKrvcJ83OWSpM9YB5TzbUiwKAKedqLBMpOYu7VudORQSNlTrZ/sZVIouVytrmh 8mRFg85soOgbowRyhrnI2fxNMftE7L06F70jdiEbEkgPyZZb1Gx9QEk58YI9QSl27zs1 8nh6biODhrdfptWo85kOkztlCfF4i/Ih+hkxxrH/M9QQ9WDY2JEdbRrI10oZ7tKOl1RJ gthE+6pN8lZAyXxGbsbBwRN8FPh2O5R7OTCAdHVZyHYMghuAo6HWsZtEhTNsg344Cx3N ML3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679586395; 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=TIHMsdmfle7NugjLuFYQiNRPSMKIKN1rr5aYwFC8Kug=; b=E8IJnyV+CKcrTSdS/RM/ESXXAwN6wmYcwO8pISL6ZO249akT8tncFMpbIvht8kuAj0 8pQqiXd/jdV3xgzPpAvPSBaWYdjO69rmq1q/G2ks3bXypGpsnyMMt8iS6WxS2Gxq6y4s U8Yp1IdDvwxPX7qS/GXFedd9/JlNATD3ebg16tqxE+3MLwN6S6089+HdPSpq95Y05J+y JjmxNMBbtn7XFDJ8alarTauJDhIXFYB03/xn8089AvAaA4WXDg8bjgZXp7yJWqpkpoiw I+V+pnW8WCnXkk1v4WA5Ey/+vnmCEgv+iqQQQLJOHWA2EH7BPsbtwXPQAEKALvbltjbk eXVg== X-Gm-Message-State: AO0yUKW1P0w+8G+xmfOrk4wf+D5oWSBWHLszGcQg7Jslo+WYwnuDPT6F DeHpnmv1JYnCzz0pcK+O2x7u3xL3qlntIrd+5aTIxA== X-Received: by 2002:a17:906:34cd:b0:8e5:411d:4d09 with SMTP id h13-20020a17090634cd00b008e5411d4d09mr5178971ejb.15.1679586394636; Thu, 23 Mar 2023 08:46:34 -0700 (PDT) MIME-Version: 1.0 References: <20230323040037.2389095-1-yosryahmed@google.com> <20230323040037.2389095-4-yosryahmed@google.com> <20230323154304.GA739026@cmpxchg.org> In-Reply-To: <20230323154304.GA739026@cmpxchg.org> From: Yosry Ahmed Date: Thu, 23 Mar 2023 08:45:58 -0700 Message-ID: Subject: Re: [RFC PATCH 3/7] cgroup: rstat: remove cgroup_rstat_flush_irqsafe() To: Johannes Weiner Cc: Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Vasily Averin , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.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 Thu, Mar 23, 2023 at 8:43=E2=80=AFAM Johannes Weiner wrote: > > On Thu, Mar 23, 2023 at 04:00:33AM +0000, Yosry Ahmed wrote: > > The naming of cgroup_rstat_flush_irqsafe() can be confusing. > > It can read like "irqsave", which means that it disables > > interrupts throughout, but it actually doesn't. It is just "safe" to > > call from contexts with interrupts disabled. > > > > Furthermore, this is only used today by mem_cgroup_flush_stats(), which > > will be changed by a later patch to optionally allow sleeping. Simplify > > the code and make it easier to reason about by instead passing in an > > explicit @may_sleep argument to cgroup_rstat_flush(), which gets passed > > directly to cgroup_rstat_flush_locked(). > > > > Signed-off-by: Yosry Ahmed > > --- > > block/blk-cgroup.c | 2 +- > > include/linux/cgroup.h | 3 +-- > > kernel/cgroup/cgroup.c | 4 ++-- > > kernel/cgroup/rstat.c | 24 +++++------------------- > > mm/memcontrol.c | 6 +++--- > > 5 files changed, 12 insertions(+), 27 deletions(-) > > > > diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c > > index bd50b55bdb61..3fe313ce5e6b 100644 > > --- a/block/blk-cgroup.c > > +++ b/block/blk-cgroup.c > > @@ -1043,7 +1043,7 @@ static int blkcg_print_stat(struct seq_file *sf, = void *v) > > if (!seq_css(sf)->parent) > > blkcg_fill_root_iostats(); > > else > > - cgroup_rstat_flush(blkcg->css.cgroup); > > + cgroup_rstat_flush(blkcg->css.cgroup, true); > > > > rcu_read_lock(); > > hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) { > > diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h > > index 3410aecffdb4..743c345b6a3f 100644 > > --- a/include/linux/cgroup.h > > +++ b/include/linux/cgroup.h > > @@ -691,8 +691,7 @@ static inline void cgroup_path_from_kernfs_id(u64 i= d, char *buf, size_t buflen) > > * cgroup scalable recursive statistics. > > */ > > void cgroup_rstat_updated(struct cgroup *cgrp, int cpu); > > -void cgroup_rstat_flush(struct cgroup *cgrp); > > -void cgroup_rstat_flush_irqsafe(struct cgroup *cgrp); > > +void cgroup_rstat_flush(struct cgroup *cgrp, bool may_sleep); > > void cgroup_rstat_flush_hold(struct cgroup *cgrp); > > void cgroup_rstat_flush_release(void); > > > > diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c > > index 935e8121b21e..58df0fc379f6 100644 > > --- a/kernel/cgroup/cgroup.c > > +++ b/kernel/cgroup/cgroup.c > > @@ -5393,7 +5393,7 @@ static void css_release_work_fn(struct work_struc= t *work) > > if (ss) { > > /* css release path */ > > if (!list_empty(&css->rstat_css_node)) { > > - cgroup_rstat_flush(cgrp); > > + cgroup_rstat_flush(cgrp, true); > > list_del_rcu(&css->rstat_css_node); > > } > > > > @@ -5406,7 +5406,7 @@ static void css_release_work_fn(struct work_struc= t *work) > > /* cgroup release path */ > > TRACE_CGROUP_PATH(release, cgrp); > > > > - cgroup_rstat_flush(cgrp); > > + cgroup_rstat_flush(cgrp, true); > > This is an anti-pattern, please don't do this. Naked bool arguments > are a pain to comprehend at the callsite and an easy vector for bugs. > > cgroup_rstat_flush_atomic() would be a better name for, well, atomic > callsites. Thanks for pointing this out. I will rename it to cgroup_rstat_flush_atomic() in upcoming versions instead. I will also do the same for mem_cgroup_flush_stats() as I introduce a similar boolean argument for it in the following patch. > > > diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c > > index af11e28bd055..fe8690bb1e1c 100644 > > --- a/kernel/cgroup/rstat.c > > +++ b/kernel/cgroup/rstat.c > > @@ -243,30 +243,16 @@ static bool should_skip_flush(void) > > * This function is safe to call from contexts that disable interrupts= , but > > * @may_sleep must be set to false, otherwise the function may block. > > */ > > -__bpf_kfunc void cgroup_rstat_flush(struct cgroup *cgrp) > > +__bpf_kfunc void cgroup_rstat_flush(struct cgroup *cgrp, bool may_slee= p) > > { > > if (should_skip_flush()) > > return; > > > > - might_sleep(); > > - spin_lock(&cgroup_rstat_lock); > > - cgroup_rstat_flush_locked(cgrp, true); > > - spin_unlock(&cgroup_rstat_lock); > > -} > > - > > -/** > > - * cgroup_rstat_flush_irqsafe - irqsafe version of cgroup_rstat_flush(= ) > > - * @cgrp: target cgroup > > - * > > - * This function can be called from any context. > > - */ > > -void cgroup_rstat_flush_irqsafe(struct cgroup *cgrp) > > -{ > > - if (should_skip_flush()) > > - return; > > + if (may_sleep) > > + might_sleep(); > > might_sleep_if() Thanks for pointing this out. I don't think it will be needed if we keep cgroup_rstat_flush_irqsafe() and only rename it to cgroup_rstat_flush_atomic(), but it is useful to know that it exists for future reference.