Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4881775rwl; Tue, 28 Mar 2023 12:43:37 -0700 (PDT) X-Google-Smtp-Source: AKy350burIngO0R79p9UNTFbBoSjUuPsgHP/Nh3yNrBJwVrC06w9+ljRAgfTZ8SYIZzXfRg23++8 X-Received: by 2002:a17:90a:1953:b0:240:973d:b431 with SMTP id 19-20020a17090a195300b00240973db431mr5470531pjh.42.1680032616885; Tue, 28 Mar 2023 12:43:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680032616; cv=none; d=google.com; s=arc-20160816; b=K5nImvUbv0zTIhmmWVEozN8lqjH6meUGWvbObLg0LKq7XcsbsKiHz5/GMp2Y+K8nBy xJOq3xvei5+G3EAhEGf3L3oT8ZUzMjCxGfOdXMImFd0H93MHNrw9CWAGFUzVF89HKfSO Eai7KbnxUF2FvyfesPMbY263vCm0AuzSkQjxffWZS2qwLXauebz83oQk0KoYwB/DogXL NUvbjRwuYSM99xiMrSZSisFUiRbY+cMW+FsilSEcPKfQl8gKGCgQ3KUIl18dJk6gQUng cOA5xBl6mOrre80XzWZk/7mSlzNavZyJZjgn/8Z5ESxoGUznWJ+2h68ik0mVdG3LMsC3 wAbg== 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=nqIPDr+ZqfoCi8eQc3DTNr+ThF98a/RBvzrvNFqWYDM=; b=TIhk0GJ4qgWvAozFRUagkVKxBXE63gw/OOLZnPBY3oMk4WUTXZ4IIvzl9JdpE4tKsS fhznSgCk1+AOGDs0OnbpSMQc6wLGIKMXDl+Gbm22JyA5If+HoGpAVugoT/+mZOGt6MHP PIKvcIvV3m3nUyoiQHTlQD6/OvtWlXKX4x9Xo0qsEFbSpHFnv5YhUhoDHPui4rEwPSbA FegP8S+dZhQ7nD0V9vKuWDcQcf5jj0dtx7prUW6O19Zp446ZEgVl6kj7bGQ2P/V4QCUa Jkqpj3hx02KQj4ELluQTKFxAQXYvADDCqfX+t4WxHx8oNwblUpWm22LzsHq9wAgZ/0Uo wndw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TIEXaRQD; 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 bv12-20020a17090af18c00b0023f6805f20asi13329998pjb.79.2023.03.28.12.43.19; Tue, 28 Mar 2023 12:43:36 -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=TIEXaRQD; 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 S229576AbjC1TnL (ORCPT + 99 others); Tue, 28 Mar 2023 15:43:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjC1TnK (ORCPT ); Tue, 28 Mar 2023 15:43:10 -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 19298195 for ; Tue, 28 Mar 2023 12:43:08 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id x3so54151055edb.10 for ; Tue, 28 Mar 2023 12:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680032586; 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=nqIPDr+ZqfoCi8eQc3DTNr+ThF98a/RBvzrvNFqWYDM=; b=TIEXaRQDBAZ6mBWE2R4TELhNaijNMDedZH3kg6n0ljtndAxJLXXqyFQwcErH6B46Lz U9BN+2qoq3bDs+Ypbo1k5NzI/RQIygK7ia03C7cfrRO0ByWfBXsdRCT0alHvfQTfmvRe qv9IocyC7Cjb3idOoIKKeNX5YVur0irro0khGXutbTnhV67ua5rmPZ8USHumeZuOnxd8 bw+LUtnZMfNIRTh+++D2tITNO4f5XHgKLCv401nXpXS49KzLZKP/0ycEI4wvThEYgq34 SdVY6fUmkfV2iCF/Uacl+jKfcVLSr1puNKsWanMsSlWfcXyo+ZpeNqbzs0La62nvhfVM xa2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680032586; 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=nqIPDr+ZqfoCi8eQc3DTNr+ThF98a/RBvzrvNFqWYDM=; b=oj21ziM2PRDuky44ze0xFKnmTYXSQ1pS8tLCl58Q/eorfS7esRqrsIzwikcbcY9R1r 1mjSl4mmzQRbqCddR5kMBMkIcyuvmR0a0zmr1RNFhkR4pYZorFIKpyLXgElptt0vBf98 5VLIXqn1I8qDPGbhHT98mS6loOJcsojVG+sEUQfZaJ7Knu/E4Mhx4M7bHNYFpfHCjrV5 8yHqTj+LdxlTxGJVbNX2VB9PaaglNFTEMlY1bWJpEJji2N/esUqWifuOO8uCne3HUiIR XSfB0BZsxUtcOZ9llaXtI0qXKDIU4VU+et+h96bpS1x6obN+j/PzT9GR+IdtD/pFQsFm 6Muw== X-Gm-Message-State: AAQBX9e85HctoTNp10GD4XKJeO+3E18ae5pR6VRNKdR45k5FSUzxj26G JekjYQ3rPrEAETQNR+xrsGlZwvBnQjJp2WmhIOtlxQ== X-Received: by 2002:a50:a444:0:b0:500:5463:35de with SMTP id v4-20020a50a444000000b00500546335demr8511392edb.8.1680032586465; Tue, 28 Mar 2023 12:43:06 -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:42:30 -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:34=E2=80=AFPM Yosry Ahmed wrote: > > 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 wit= h > > > > > > > > if (atomic_read(&stats_flush_ongoing) || atomic_xchg(&stats= _flush_ongoing, 1)) > > > > > > I profiled the entire series with perf and I haven't noticed a notabl= e > > > difference between before and after the patch series -- but maybe som= e > > > specific access patterns cause a regression, not sure. > > > > > > Does an atomic_cmpxchg() satisfy the same purpose? it's easier to rea= d > > > / 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. Anyway, perhaps it's better to follow what queued_spin_trylock() is doing, even if only to avoid locking the cache line unnecessarily. (Although now that I think about it, I wonder why atomic_cmpxchg doesn't do this by default, food for thought)