Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6288404rwl; Tue, 4 Apr 2023 10:15:09 -0700 (PDT) X-Google-Smtp-Source: AKy350a4OCo6PkyyAb3RE4f59ynisBcGvYB7B3IWcGeVr6b63/SfFPso3Vy7s+k154B6OO8v8u2q X-Received: by 2002:a17:906:d04d:b0:93f:fbe:c388 with SMTP id bo13-20020a170906d04d00b0093f0fbec388mr364260ejb.27.1680628508955; Tue, 04 Apr 2023 10:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680628508; cv=none; d=google.com; s=arc-20160816; b=I+loqGGSu6QpVrKhJf7P1WOpNwrlFVfLycs8G+PkCDj/YOMgCs995fI1Zpq2MZwYWU lChUVG89M1BjlJfVrN55aTKrIxNmbDxN4fmF2UwzfJl7eX3BMmMByIWj6QjIn+aY4hQu jUThkF0mO05NWO0/8Io8MxA8OFLGfiXPa36e7MSy4uPnlWwB/ryDm++R+dPrCOPJFTGB Ir5yvQ3TLbosqMR7sknkl7ngRzQW5Fm6SQc2QtOw6pYzlE1a1Nu/s3K/xBu8vzQYQEXL fbeJipj0hnv7G0uhPAUrIsMb7OTp2UZTonbrFUv1y9B7v40XnFKkQNh2YZAp6FNJs6Nf yLfA== 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=jB81HM7QxwklDvE39D9zGEd7EL3RK9tGsVExEctIF9g=; b=zSFl1u9+DfN2DdiuhU6B5okhbQUdbELCwtJKs5BEhhEwoyNPZxYPy6cW55VRjEH/9x KFah3heJtRFEIcvfy+rzkuIF/yg7l6w6PlBA2GiKGRj1LCXxYhOvyQ0NV8YzSDzrujU3 g3H12Keuh4iRMw0n91X2GhrKyoDo0FIr/ZT+M7djsZFyC0UyRefUMGS8MSi2ITcEdrbX 9Qag0XOWd3jtMmnwQmSmg/VKhBlhDaU2nJqQ9VLa2YixVJCRDJeViHCJwKMYcoa22k1L 1h/NPqAwf3+7gd7HzuZnkK8WV16MP/nVL+T40MAQsVPkkfWAnx/mn83fkvXC6Qauhn3r mNQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RTE9uUoI; 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 gt23-20020a170906f21700b009476a8cb01esi7704568ejb.654.2023.04.04.10.14.43; Tue, 04 Apr 2023 10:15:08 -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=RTE9uUoI; 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 S231181AbjDDROH (ORCPT + 99 others); Tue, 4 Apr 2023 13:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235056AbjDDROA (ORCPT ); Tue, 4 Apr 2023 13:14:00 -0400 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49E4710C1 for ; Tue, 4 Apr 2023 10:13:59 -0700 (PDT) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-54601d90118so471608597b3.12 for ; Tue, 04 Apr 2023 10:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680628438; 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=jB81HM7QxwklDvE39D9zGEd7EL3RK9tGsVExEctIF9g=; b=RTE9uUoI7XQ8R2+nrWW7Yx58+ErEPGeeDfqbJ/xGvvaIQ77F/wmkQ1JiRiLzfMk3ds aGgu1IiS++nn+phVSuzWXmhmnnCR/c6rjOJll7kCeyjgPiFt1rAHATUDSo6RV05Qzvc2 xUkU5W+YitmDn4UuYTkJUwt6iLG7fqJ2JdKIaUoaN4I5bJucmRLBWHWQyYSLVRgj5Kb9 YYRNr9aHII9yl6U38B61zDPm53mjPR6kWofIAAjQ+MEUUeIyy/AFwTH+9VuLtJzwYqJj tf1x0gtzBFYsSXZzhLN/ugTsZ4z2Nt+9QfJqs8jO0/JRmH/lPnHVRTX2DCl54PANUWGW Ny3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680628438; 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=jB81HM7QxwklDvE39D9zGEd7EL3RK9tGsVExEctIF9g=; b=HWIWF8Cipg1RRlwUzOQUrxXe4+15T8b8Xi6fOzzxLfsaj1tpisvtyHK7X7NRoW8EJx dxO4xS6abkiqntNXrL7u89sszxxJ+EUNzf9mzWncntwVW1tLT8fz0ntjZsSa0vONRi/2 OQ0FHKJLf8xU82Td4+n5r3UEk1/Jp2hROEqprm8NwZBJIn7eTmuiG719leUj3jZ6k3mJ 5NEjnFLvNsqwFEAwSykdVUEQgRvTUjI58mFZ02x8sWEDAayqpnW+h4YrAyPmaplx5syG FbWRvUEO4kSncqNMQzLXR+7CT+6HZvVzmyqZ8lF3yplF3N6XyzRu0pIEVEI7fMEMlnXP K9yg== X-Gm-Message-State: AAQBX9f0Z3rv+MssIoqBSNZaGyPtH4XBOTeTr1HOu+i20uvNuVPOP2Lf XVApEmknKrUq+NdBkwztrkYIyteJDBNYB1H3UCedVw== X-Received: by 2002:a81:ac0d:0:b0:52b:fd10:4809 with SMTP id k13-20020a81ac0d000000b0052bfd104809mr1973994ywh.0.1680628438438; Tue, 04 Apr 2023 10:13:58 -0700 (PDT) MIME-Version: 1.0 References: <20230330191801.1967435-1-yosryahmed@google.com> <20230330191801.1967435-5-yosryahmed@google.com> <20230404165258.ie6ttxobbmgn62hs@blackpad> In-Reply-To: <20230404165258.ie6ttxobbmgn62hs@blackpad> From: Shakeel Butt Date: Tue, 4 Apr 2023 10:13:47 -0700 Message-ID: Subject: Re: [PATCH v3 4/8] memcg: replace stats_flush_lock with an atomic To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: Yosry Ahmed , Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Johannes Weiner , Michal Hocko , Roman Gushchin , 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, Michal Hocko 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 Tue, Apr 4, 2023 at 9:53=E2=80=AFAM Michal Koutn=C3=BD wrote: > > Hello. > > On Thu, Mar 30, 2023 at 07:17:57PM +0000, Yosry Ahmed wrote: > > static void __mem_cgroup_flush_stats(void) > > { > > - unsigned long flag; > > - > > - if (!spin_trylock_irqsave(&stats_flush_lock, flag)) > > + /* > > + * We always flush the entire tree, so concurrent flushers can ju= st > > + * skip. This avoids a thundering herd problem on the rstat globa= l lock > > + * from memcg flushers (e.g. reclaim, refault, etc). > > + */ > > + if (atomic_read(&stats_flush_ongoing) || > > + atomic_xchg(&stats_flush_ongoing, 1)) > > return; > > I'm curious about why this instead of > > if (atomic_xchg(&stats_flush_ongoing, 1)) > return; > > Is that some microarchitectural cleverness? > Yes indeed it is. Basically we want to avoid unconditional cache dirtying. This pattern is also used at other places in the kernel like qspinlock.