Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4876930rwl; Tue, 28 Mar 2023 12:38:35 -0700 (PDT) X-Google-Smtp-Source: AK7set+VkPY+Dd2sqVTBrbb1RhtTtHgm8nQb6rsdnjoJ0REwjAMYn96kTNe7IjTk1gxEQYuTWDM/ X-Received: by 2002:a05:6402:17da:b0:4fc:97d9:18ec with SMTP id s26-20020a05640217da00b004fc97d918ecmr21115157edy.21.1680032315174; Tue, 28 Mar 2023 12:38:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680032315; cv=none; d=google.com; s=arc-20160816; b=F/kf61Tw3lYx95SjrbtxvZRhiugKr0ggqScog9fWXo0XZABIHE2jFpdSEj6uR9+oPE PdNEtvNNeEf9QWx7KixLW2T0f2zhu3VdmWlkSnr7QtNkVUdDBnJ/kAm1thCFgMk86aFR 2F3jixbpLIFecT7+k07mpz877xkxL+CadmIMQqQweN/Y5gvTFCO/BzwCw1Nbq6Ql2mwv FkKoEkb3q9BuNBLm3I7eSKfYy/3N3u9oLk4OVHyLqLiw8ndpKZN09PCG0xla/GxBBdKT jgy4Wb7y6xKtxuQH5ZlE421Bcf0B9gGyrMRWmahXVOF7MUHSu9Qp2wAAUTGpFJrgc9+w ZtSA== 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=PCcvIywQQCX7FP21Q6hk+wcOp0VhtxDKF+8JhJGEAfQ=; b=aynf2cqc4FpgrxM3oB9TrY8bap2S5Mi+9Ve3VUGQMyKw9BZNEnDpBSt//WccVsUAth yEtbg18AYaPCOGzHcXHl8jfopujFNksmAnoW9XXzCar3U/bjm6NTFxTrFoB4AUx02UAM UZkAtEbzwT1iTLiPA0J6dk3hKoR07AjG0Xc+9MQBPldq1jL30JsZuDDyoJ1T8Z5imM4I j4MElqMZb9aNVs161WgpW2FFmoOrIgDR46cLE1TtBYXtkr9NMY3ahR2XfF3M/u++uxTN 8yuWC/51gvoh5vYZv2WRPSBn38L2OUe2PGa2m1rPQKW/3wu9sb1EAIvuDTfqF70MDJ9t me3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dHoOF8rN; 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 bc17-20020a056402205100b0050223f6f6c3si10672504edb.108.2023.03.28.12.37.03; Tue, 28 Mar 2023 12:38:35 -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=dHoOF8rN; 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 S229637AbjC1Te7 (ORCPT + 99 others); Tue, 28 Mar 2023 15:34:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjC1Tez (ORCPT ); Tue, 28 Mar 2023 15:34:55 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59AB7F7 for ; Tue, 28 Mar 2023 12:34:53 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id w9so54214399edc.3 for ; Tue, 28 Mar 2023 12:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680032092; 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=PCcvIywQQCX7FP21Q6hk+wcOp0VhtxDKF+8JhJGEAfQ=; b=dHoOF8rNOSkdjd1rnnf8XC6IGb6FKwmM7Ivdvjk2GQi/EbVyThzjBYyHQXopuJULIg 3p1bzuC4gKKNl6Fqhda2du3Rr+s6FdBcg4aXKrD1ycu2zktIM3FTOAoGmv4pZHnjujsT rvqc9SbA4NjhcACriIJnLeYfMpWyuhW0j5mUqMiEJuGYX3I6Vm1bge9vyTRqSfTQ+kFD hcNKe+61X/fdB+69ZT/PWtpn27JcWOnhGjSUdRlOVudULYhr4IE9KPo4WrZdFpVOufcb x3G5vlvhcJZuXWJ1jNnDtE5NmkzFKju+dq8flQe22Sd56znLfGyB2CeL5tXa6i93FNYi J7Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680032092; 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=PCcvIywQQCX7FP21Q6hk+wcOp0VhtxDKF+8JhJGEAfQ=; b=ckTM9Jx/tu40wHec5XCvcX67PAyWBlyLICa1KWwiHPbWHCiqH5UCraZC/C4PErzJKd gOWdXuX2+0rNx1S8FWqy+901Ptqe+BZqGdXZ9zdzbGUIRQ4Fwti5RhUa8iJIo6GQ3MQl 2CmXZ4n8VVANhStvnGd2i6fX06tx45366xaNGzjzsViiZSTa+QIp+Q9Lmeywox9iMn3p VI0ur8Q3V11Y7XlfG1N/TEC9BqTOD7WTwE7X1G6eSIffn+/1RqjfVo8CORGmktu9ikgZ +0sZrXr95r8XqGKrMbQz9Tv/2R1YDiHOlgyS2ln0wnghG0TuXMqTfzZ+iqbLKNZ6KjAq m6Zg== X-Gm-Message-State: AAQBX9dWN2EyBf3T69uB0eLarqjEJA+vUSFNQ0lE4FAF0tSKhfQ0pvB8 E74NZsGnHLIFxW22NPvKRks5TPToKmADuS5YWFUbXQ== X-Received: by 2002:a50:d581:0:b0:502:1d1c:7d37 with SMTP id v1-20020a50d581000000b005021d1c7d37mr8497378edi.8.1680032091630; Tue, 28 Mar 2023 12:34:51 -0700 (PDT) MIME-Version: 1.0 References: <20230328061638.203420-1-yosryahmed@google.com> <20230328061638.203420-6-yosryahmed@google.com> <20230328141523.txyhl7wt7wtvssea@google.com> In-Reply-To: From: Yosry Ahmed Date: Tue, 28 Mar 2023 12:34:15 -0700 Message-ID: Subject: Re: [PATCH v1 5/9] memcg: replace stats_flush_lock with an atomic To: Shakeel Butt Cc: Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Johannes Weiner , Michal Hocko , Roman Gushchin , 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 Tue, Mar 28, 2023 at 12:28=E2=80=AFPM Shakeel Butt = wrote: > > On Tue, Mar 28, 2023 at 11:53=E2=80=AFAM Yosry Ahmed wrote: > > > [...] > > > > + if (atomic_xchg(&stats_flush_ongoing, 1)) > > > > > > Have you profiled this? I wonder if we should replace the above with > > > > > > if (atomic_read(&stats_flush_ongoing) || atomic_xchg(&stats_f= lush_ongoing, 1)) > > > > I profiled the entire series with perf and I haven't noticed a notable > > difference between before and after the patch series -- but maybe some > > specific access patterns cause a regression, not sure. > > > > Does an atomic_cmpxchg() satisfy the same purpose? it's easier to read > > / more concise I guess. > > > > Something like > > > > if (atomic_cmpxchg(&stats_flush_ongoing, 0, 1)) > > > > WDYT? > > > > No, I don't think cmpxchg will be any different from xchg(). On x86, > the cmpxchg will always write to stats_flush_ongoing and depending on > the comparison result, it will either be 0 or 1 here. > > If you see the implementation of queued_spin_trylock(), it does the > same as well. Interesting. I thought cmpxchg by definition will compare first and only do the write if stats_flush_ongoing =3D=3D 0 in this case. I thought queued_spin_trylock() was doing an atomic_read() first to avoid the LOCK instruction unnecessarily the lock is held by someone else.