Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6297806rwl; Tue, 4 Apr 2023 10:22:51 -0700 (PDT) X-Google-Smtp-Source: AKy350ZikG31FhQMduuzhDrUJu9hpLK5SrRwez06OXiH/23iewNotWqFZuv7yZMN3ZL73hpQu5Aa X-Received: by 2002:a17:907:80a:b0:937:4001:6eda with SMTP id wv10-20020a170907080a00b0093740016edamr342019ejb.38.1680628970724; Tue, 04 Apr 2023 10:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680628970; cv=none; d=google.com; s=arc-20160816; b=qXxxdC3RzwPlWHgWApS/XkuBOI5Otvn0RBCHUVsnc3tHJ1/ccxGaLApdKF8P8l1KLI rOi7bIShCL/a17xNJTXJoL4L7zfYHtgK/lW+EjAzbuO/Aq7kg2uPKgzRgLN2Xq/B/bHi q8N65036qLaue1hpogNlNOdIMm8GzMkfzNoK2AEmHcgOF2OjdX71EkDUCnf+TlR0gzMz 6VeC5iuwyFSwMOpzRXFUSKnhbObIeLILNRrzlBGRIRGkvoofBg+PjLjpLUdrhg4aE5Ia R8VcUprxJKvPWEW2MOo8Te1SmLEDiD48UzE2Sg8GXmUfsYFDTiSFOkNBz0zOo1XYMuOq UJwg== 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=H/6nWpG035DFCd1KL6TSDLFyH9kaDtT1tj9RQy6j89U=; b=jvwjTRZMdtlnQjQV4Zs5//dTdtryhsGtR4kOCm95/A85dkJ802E5ctbeLze6ZtRYgR XKTMCEz+cixktKjeZLaeeCQU9lYmxN11s45ZlkFG2yt5rkambTtOGrly33Bv5AE33KJp o0laMqXaGir73AybKONka0Rrnn0Pj4AMCperQnJpeCyUwl1zyd4hDuSuF9EU4aokSUgn DH/g+fHBM6xjeQCRsL/UJB6ijfsnoD+dEx9uuBMqqe3X86lf6F47FiiU4nDfMIsIFQt7 cUlQbALDQCogvsNciBdjavkxgbPSmIvylf4Pg1BoIoawJmHt3e0g2LJSiMFFJ7Rsdptq lhEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PKraOirR; 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 ak14-20020a170906888e00b009477d131256si974111ejc.566.2023.04.04.10.22.26; Tue, 04 Apr 2023 10:22:50 -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=PKraOirR; 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 S235831AbjDDRV6 (ORCPT + 99 others); Tue, 4 Apr 2023 13:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235885AbjDDRVv (ORCPT ); Tue, 4 Apr 2023 13:21:51 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 698161717 for ; Tue, 4 Apr 2023 10:21:45 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id d3so11697473ybu.1 for ; Tue, 04 Apr 2023 10:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680628904; 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=H/6nWpG035DFCd1KL6TSDLFyH9kaDtT1tj9RQy6j89U=; b=PKraOirR2pRBA2DBW/b33pTm+8HXjKvpeNeRzehm9FD9V7XXtodyrrySXy1qTEBZQr KFtO6wcuZl5I0TAgoLpYtumb2AXH1YDSl7tNZVF0teic9sNmnZ5Au1/xUa9gyEVdQLdV AY7qyFZ1dPyPFa1UUhVHvv8/mO0zS1TBX7chxj/oUPivbEu361UcjMNugE1rCkF2gF0Q 67lgHtBl39eyST0OLIFXiGODcqI2+588kxayaRE7NbbqOro+EqNNKkmqAeeBCCR7SquS F31eMziiL3Tu2fHhzHuplp2dE7AYSjVVNkuvNqRVoXYN2Tei1Q9gxYr8f2pGG+ajomnQ hbug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680628904; 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=H/6nWpG035DFCd1KL6TSDLFyH9kaDtT1tj9RQy6j89U=; b=lr4XmPaBnHwclVfM7tyMoEjHGrzKEy0yOdZCJq2ScDC8qAyWXhkT6xR3v5QWLEXcXe Ygj7vPAA89HdVyDQ78Tz7NDhXXBK9XJ2G3spMPJYiOlP4L6s+0CIrVEn1jCW1tbliqS8 IN99r0lsL+diiw2e7KgpVMO17yvf0Kx5z1mz4hSzLJ8ITQGctL7I1zqSv+BLdi/gatOc 93RKOrZ0ce43SAsDhvsFRTbVnGkkWaDXQsfmkgEOFCPv2XylgKnAh8bSwR4Rgh1B90zR lgCO/ynJQgzlGfvA0rLDZwHWAJC2XQtMyMHZbtDfPWZQO0JQYdJXJ1ohBhPZxSM9di8l acnA== X-Gm-Message-State: AAQBX9fwt/lMHPguMbrk1BlVKhRULC/BnbvyxPvT7IhQNPK30Mv8bf7U PjbSd/tROYvuvtnXF39IZe94ezQBGuMKou3Qc1OTXw== X-Received: by 2002:a25:ca4b:0:b0:b77:d2db:5f8f with SMTP id a72-20020a25ca4b000000b00b77d2db5f8fmr2305401ybg.12.1680628904510; Tue, 04 Apr 2023 10:21:44 -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: From: Shakeel Butt Date: Tue, 4 Apr 2023 10:21:33 -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 10:13=E2=80=AFAM Shakeel Butt = wrote: > > 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 = just > > > + * skip. This avoids a thundering herd problem on the rstat glo= bal 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. Oh also take a look at https://lore.kernel.org/all/20230404052228.15788-1-feng.tang@intel.com/