Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1050487rwl; Wed, 29 Mar 2023 11:55:02 -0700 (PDT) X-Google-Smtp-Source: AKy350aHXMyB/THgJaLmC9NUoM83BYBqLdfcNaKlHM5WzbY8sYlQvNQLUNcosaqt7XyZdcUT8caI X-Received: by 2002:a17:906:ca0c:b0:930:1914:88fe with SMTP id jt12-20020a170906ca0c00b00930191488femr20760565ejb.68.1680116102467; Wed, 29 Mar 2023 11:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680116102; cv=none; d=google.com; s=arc-20160816; b=yFdXaatOSh5yTAq2tEihskVN801kPyV6eMdl8rDVplpd6svRbrfRTapqjxpU1URB83 oMjvkmg7651jnz+KSVKgsRiINeXYUX8VX1dXg55tBFRi4g+bKE34JpiBh4fHmR0NUvNz eOdReQBipI3SuzmqmdZPuYLdfZmuBpF68K+mnzZh827L8e7Cm3AAIrCFF3NfUdx2k53F m+dQibWK2LQdFJl5EvW17qwkQiNY09YfNs1Z4gC6D5bnIeapM48MjgwcF8kjaCFmou/j qPmqphleLc66p0k8t614zlfkYgFWH4cmYEJ8nvxamHffpEYqH5+f/6cMH+gnXH/fzjka B15Q== 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=eIBZAFv2wQMorQ5lc8tGcKMX+DgU71oiqiwG/4lRhic=; b=kHo7N+p3gm1UKtdhTnSbQ8EzgvrsDXABa8vBitq3H9dGs2tJDknWTPhgnvLBNjPCpL /b1z9zbmeKlhOUz5wT3SGl9beItMoYOrmviOsS16krz9BS+taG5foW2EfBQHz4ri8zF7 dKg9p7SPHaW+4R4P69WrX7NttUpYcS2RMI/EW/4fhCN9cd6OlZIvQL2TUOvvo5JBpCVi zy0JA6XHe2O9CHZgG6TiQ4OQ0m8J56tTc68tH/qKmwzB+ysFJTqhPVN0Knxm9fdEAXAU OZ9wAgEEPuwJ4u/GL7JG59lqfyB916/qRSnl3o1FU/dLkHxaX1l8dkJuAzTlVNtr/i3c ak9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=aPynEkp0; 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 tx9-20020a1709078e8900b009334769e7ebsi27995890ejc.790.2023.03.29.11.54.37; Wed, 29 Mar 2023 11:55:02 -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=aPynEkp0; 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 S229806AbjC2SmV (ORCPT + 99 others); Wed, 29 Mar 2023 14:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbjC2SmU (ORCPT ); Wed, 29 Mar 2023 14:42:20 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 541355251 for ; Wed, 29 Mar 2023 11:42:17 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id ek18so67165332edb.6 for ; Wed, 29 Mar 2023 11:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680115336; 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=eIBZAFv2wQMorQ5lc8tGcKMX+DgU71oiqiwG/4lRhic=; b=aPynEkp0gt2yrrh6KFRsPFu4+QI+22LUjC71jLtYRdPz3tvtiYrWpQlMXP+93X3yGB FiYhI/lB1nm7o983gXqChQwZJgo7TUHZHozyA54eTsiL7qEpKTDtVNZjtT5OnUGO3FcT /Ghx5u5imvI3Gsd9iJAQJreaU9lhZCpMwvKLL4xwq3MEiupMjCgS2J6LanHI7FZzdNHE DD5BkwhMH87ZYXPw7tl2iLTM3LS+8SO6AidoBxBPFw0iS+D9jzkDX1w9ejhJCbS882ck 3Y9hQaaQPnDbj315Xgi6CAnGj+I61uN4wFCd/FWxc6pmq9vBaD7hAvSlXrhKcXQw6j9r 0zJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680115336; 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=eIBZAFv2wQMorQ5lc8tGcKMX+DgU71oiqiwG/4lRhic=; b=va8GXI7MQzwtnyHv0fXwnRh1zWIEwyXL318V4YIZa9OQx3skZ4ISPhQLNMKtJXGUAE F/yTTmoIpSW7r9uI+ak6Txo8cF61clb+A0QKx3PAce1usMd8YQ//bi329mQdkJjS2qWl hS4SOcJE41R33wyAw7PDQe5FQK45WWSVWIxWMCqQVtcn48KufBIS4++9T5PKZ7cKiYVP V3yDOH5GXR2YZbXKiIzeuHt40q6AAc15CYM3koil3Qug0ZcOV3iTPSOHk5SEfLR8WPQT oAR4jFhjMfQpwKWHmdX9jlIfiQ+GEOpQevbgSE87wVoGVVVMdr4VYb7SaZ4h+88awuVe aonA== X-Gm-Message-State: AAQBX9cBJ/fxL/bXzmAtMijzlDCxVbjkYg8xVg6ubSfirkUqv/dwuObM GsvSFO3uxC+YlZBSHz+roGnD/wQfbKrwbvbYhYQ8Sg== X-Received: by 2002:a17:906:81da:b0:92f:b329:cb75 with SMTP id e26-20020a17090681da00b0092fb329cb75mr2122145ejx.5.1680115335713; Wed, 29 Mar 2023 11:42:15 -0700 (PDT) MIME-Version: 1.0 References: <20230328221644.803272-1-yosryahmed@google.com> <20230328221644.803272-5-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Wed, 29 Mar 2023 11:41:39 -0700 Message-ID: Subject: Re: [PATCH v2 4/9] cgroup: rstat: add WARN_ON_ONCE() if flushing outside task context To: Michal Hocko Cc: Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , =?UTF-8?Q?Michal_Koutn=C3=BD?= , 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 Wed, Mar 29, 2023 at 4:22=E2=80=AFAM Michal Hocko wrot= e: > > On Tue 28-03-23 22:16:39, Yosry Ahmed wrote: > > rstat flushing is too expensive to perform in irq context. > > The previous patch removed the only context that may invoke an rstat > > flush from irq context, add a WARN_ON_ONCE() to detect future > > violations, or those that we are not aware of. > > > > Ideally, we wouldn't flush with irqs disabled either, but we have one > > context today that does so in mem_cgroup_usage(). Forbid callers from > > irq context for now, and hopefully we can also forbid callers with irqs > > disabled in the future when we can get rid of this callsite. > > I am sorry to be late to the discussion. I wanted to follow up on > Johannes reply in the previous version but you are too fast ;) > > I do agree that this looks rather arbitrary. You do not explain how the > warning actually helps. Is the intention to be really verbose to the > kernel log when somebody uses this interface from the IRQ context and > get bug reports? What about configurations with panic on warn? Do we > really want to crash their systems for something like that? Thanks for taking a look, Michal! The ultimate goal is not to flush in irq context or with irqs disabled, as in some cases it causes irqs to be disabled for a long time, as flushing is an expensive operation. The previous patch in the series should have removed the only context that flushes in irq context, and the purpose of the WARN_ON_ONCE() is to catch future uses or uses that we might have missed. There is still one code path that flushes with irqs disabled (also mem_cgroup_usage()), and we cannot remove this just yet; we need to deprecate usage threshold events for root to do that. So we cannot enforce not flushing with irqs disabled yet. So basically the patch is trying to enforce what we have now, not flushing in irq context, and hopefully at some point we will also be able to enforce not flushing with irqs disabled. If WARN_ON_ONCE() is the wrong tool for this, please let me know. > > > Signed-off-by: Yosry Ahmed > > Reviewed-by: Shakeel Butt > > --- > > kernel/cgroup/rstat.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c > > index d3252b0416b6..c2571939139f 100644 > > --- a/kernel/cgroup/rstat.c > > +++ b/kernel/cgroup/rstat.c > > @@ -176,6 +176,8 @@ static void cgroup_rstat_flush_locked(struct cgroup= *cgrp, bool may_sleep) > > { > > int cpu; > > > > + /* rstat flushing is too expensive for irq context */ > > + WARN_ON_ONCE(!in_task()); > > lockdep_assert_held(&cgroup_rstat_lock); > > > > for_each_possible_cpu(cpu) { > > -- > > 2.40.0.348.gf938b09366-goog > > -- > Michal Hocko > SUSE Labs