Received: by 2002:a05:6504:1d0:b0:1de:de76:8684 with SMTP id e16csp895855ltn; Fri, 2 Sep 2022 09:45:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR6t23yBlSO2lgAhM9ih6j4FMpCI8KIwUxukf2yYIDvuDizDv/r6IZSG221/RzKkWuYIu+SY X-Received: by 2002:a05:6402:5110:b0:440:4cb1:c137 with SMTP id m16-20020a056402511000b004404cb1c137mr34989351edd.262.1662137121039; Fri, 02 Sep 2022 09:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662137121; cv=none; d=google.com; s=arc-20160816; b=P5W3IzKjOaR8Gv+VR3SGVaVbGYzGb7dvNGtAVVbE58aGoIXB/rJ26MOTXs5QGKH0JM gflkiii2MUgB0idABiunBw3Yp0dgiFS++HJVricdXUOL8DCJ4RjVcsdwxs/6srC/t79H LkVGRgoyaKZsXZWnSZIzV/KeV2nt3kI9aJ9mqI2wNSxUZG6bemK41fd9sVbkXQnUWdTh jRYcft0OSgWFvIWNTgM8cKeRX/P0heL4FWBnHLmQHVruRd+36NCwNBH2AWpLCOok2lrR Kp9Ng7qwCSBxvZmWvwpKkJ8IlnVExNLX2EPrS8lGNAUn043EvYzrQ/LH75jiQX3Aaisx BYvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wNIc8ao3Yt5CIdYavjbANH3T4X5dkUReDekaysXGDSo=; b=ZF65TWMRdo5foZXzqFKA8McNnRLHi4QiNt+p/osQHajs0mYE0nKl+9c4VaB4nKiWnt QYjCPILX86pQlAjS8VenGUMxOpBpElYY2sSSqGa8jmAguAG362mzofy5W2UGnYUfg9Kr PyqdrEKPvPmI9LgPDu9rT/iuBF5pNMtQD1EO2ZysVcg4/x9Z+Dbbfkw9Lt4ERNLo3ftF ItH07bvwMiTQMqrcZwLMv8OiiT+Xtf69mEKpl2uccdk/qHRC164rturiwvzfxg7J2nw/ r/YAyw8v1cCGdiz93M58bRgDgYt4nGONAljzil1Jha6DkzGkZqTnSYGwKYjMI7y7tor0 ig2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QhH2Cm4l; 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 l6-20020a056402254600b0044796abf102si2441285edb.436.2022.09.02.09.44.56; Fri, 02 Sep 2022 09:45:21 -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=QhH2Cm4l; 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 S236266AbiIBQ2M (ORCPT + 99 others); Fri, 2 Sep 2022 12:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235705AbiIBQ2K (ORCPT ); Fri, 2 Sep 2022 12:28:10 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 252D2D83D7 for ; Fri, 2 Sep 2022 09:28:06 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id o4so2506844pjp.4 for ; Fri, 02 Sep 2022 09:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=wNIc8ao3Yt5CIdYavjbANH3T4X5dkUReDekaysXGDSo=; b=QhH2Cm4lO6x1voUd1Dembk6oOd9z5VY5TRrL41iWRFmmpp8cdizG8V+OUu0UJk4T41 aBRwqxgqtgljwySCPWHW60HmpaQYfdGXRRn9TMfCgOZOrcLIYDmjjtbOslwy29nx+HB6 /3W7hEuGXsIJnNCIe2Zgw7XYDjOwT1N0H1P2AY4jkvJNMPcvwyHdV8NmdAEMgkPCaxFJ 2YOewm0AxPEacPvzTN5gOid4Eqo7tbyICfOHq715O4rt8jVMgZmaCTjZxCgWwYqIXacd TqSNDW+DbtXv484tEbqq+CuR4VMQFe7e/Zcvn9YWgp63KbN3gk41EGKm2NVZOZjgLss2 Ej5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=wNIc8ao3Yt5CIdYavjbANH3T4X5dkUReDekaysXGDSo=; b=BecuGsmUVoDuiRrBAaiYMlT0vNgda4K+3Vjnv3H2dxh+3B2rBG3xNqhtc2cyt4j9/r mrBBjD5cEw/WnOCx+GQMHUyvBFxuvBIFYGnY1TUIvxkyJbdNl7pYPnmrM/UKNWXPAW5m Ur/YX/MATUbiPk3U2VXo1hKoNpJmSb4d4ahbQoIvN/Yi5yaWRAYZt7bBdcWSESW1SnUR Qd+kGpJdFZowKoxuxwh+zI5HOjGpj3gutDPq5fjqYv7+6HlvszfcuMo85UGXTVZCaqas BdR6LfCHqBtMuMr4CR5VDmH/SGc94bPh7qFX6uu1Pzuknus4lH8m5MEJmxmoI4niiV9h e1Lg== X-Gm-Message-State: ACgBeo0ALf8FQxJ4N0zJ+3RitskXM6JhdoNchulfdnd/UHpGZaeTs+Gf 1gxuaPbL49RlP/JV9/xiObFd2orrETRUmbFqEE6hfA== X-Received: by 2002:a17:902:b410:b0:172:c9d1:7501 with SMTP id x16-20020a170902b41000b00172c9d17501mr36380746plr.106.1662136085602; Fri, 02 Sep 2022 09:28:05 -0700 (PDT) MIME-Version: 1.0 References: <20220902152243.479592-1-jiebin.sun@intel.com> In-Reply-To: <20220902152243.479592-1-jiebin.sun@intel.com> From: Shakeel Butt Date: Fri, 2 Sep 2022 09:27:54 -0700 Message-ID: Subject: Re: [PATCH] ipc/msg.c: mitigate the lock contention with percpu counter To: Jiebin Sun Cc: Andrew Morton , vasily.averin@linux.dev, Dennis Zhou , Tejun Heo , Christoph Lameter , "Eric W. Biederman" , Alexey Gladkov , Manfred Spraul , alexander.mikhalitsyn@virtuozzo.com, Linux MM , LKML , "Chen, Tim C" , Feng Tang , Huang Ying , tianyou.li@intel.com, wangyang.guo@intel.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,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, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 Fri, Sep 2, 2022 at 12:04 AM Jiebin Sun wrote: > > The msg_bytes and msg_hdrs atomic counters are frequently > updated when IPC msg queue is in heavy use, causing heavy > cache bounce and overhead. Change them to percpu_counters > greatly improve the performance. Since there is one unique > ipc namespace, additional memory cost is minimal. Reading > of the count done in msgctl call, which is infrequent. So > the need to sum up the counts in each CPU is infrequent. > > Apply the patch and test the pts/stress-ng-1.4.0 > -- system v message passing (160 threads). > > Score gain: 3.38x > > CPU: ICX 8380 x 2 sockets > Core number: 40 x 2 physical cores > Benchmark: pts/stress-ng-1.4.0 > -- system v message passing (160 threads) > > Signed-off-by: Jiebin Sun [...] > > +void percpu_counter_add_local(struct percpu_counter *fbc, s64 amount) > +{ > + this_cpu_add(*fbc->counters, amount); > +} > +EXPORT_SYMBOL(percpu_counter_add_local); Why not percpu_counter_add()? This may drift the fbc->count more than batch*nr_cpus. I am assuming that is not the issue for you as you always do an expensive sum in the slow path. As Andrew asked, this should be a separate patch.