Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1401857rwb; Sun, 18 Sep 2022 06:43:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6zC0gqkiK5BSMqDANZLWC6w69NsKiMi21CdRpo5w9IQvaj/EVyxvtpigFk8OfLll6scKFJ X-Received: by 2002:a63:5fd6:0:b0:434:96fe:f508 with SMTP id t205-20020a635fd6000000b0043496fef508mr11971594pgb.306.1663508610870; Sun, 18 Sep 2022 06:43:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663508610; cv=none; d=google.com; s=arc-20160816; b=Pv1Nr/bY/LpdM0w7PY51MfNV1XXlYUyif6L2M6WYLmwHJ4KBNDNtQTMKGkzAucxe+2 UgMgb07AkenqXnGBHFNgvpXD7rABGHsfwHf0hRvz/RZI8H3N/dA/UJrw9EQ0JTmXUANe gYqtbyNKAP/NEiZ8hRBCJBzUf/hk1jhF5XT1TioHxtZnx3WyJ8AlwZN9TN/sINuvKSG3 kekWxQn8CzIlEsL3ZCddpQdUZX0H2PbvTG/CCL1bf4yS7m8bie1n/mu2XP07dq+F9Pqz I3d/6mnyp8tgjd1fovVWMdKnXjPkooDu85nk1hnat0O5WHgD4wD9oiLtah3uxui7kZBi DXpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=SKbV4mKu73VuNVhI6M2LnjoCEeDVwapxGXXk0hJK72A=; b=pEZ/XhJizc4rx5aJYGdPK8BcqpKvKshrUjEKV5f61H2WYAi1AOPpVR+KwMwc5OUroG drrMKVSVZiOEUPkQwX7oJE0TYh3BaoYDbbQ8oanE+A2smqOiLFL81XuLf/0B1lCF/EtQ lwk9USTfv//MhPvkN+9j+xY9xL7vb7kU9JnzH+DhsBElgGXep4VhYF0PjLl3qWAYiFpX /ZBQyiBMF4uVnhnAoodrAN2TYqrBxwEA+ICgmCW8eS+0aL+VnE9paEnckIHUsBvnEXIX Ez7tb0qjIXRN1WkYCJtsrkIabKmTmOUZ+bGBy+2LrvgZBoq/+w9ns8keH+RhQkKuJHbl SwJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@colorfullife-com.20210112.gappssmtp.com header.s=20210112 header.b=hV99jqFA; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a62e911000000b0052c78eecaffsi26047121pfh.174.2022.09.18.06.43.17; Sun, 18 Sep 2022 06:43:30 -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=@colorfullife-com.20210112.gappssmtp.com header.s=20210112 header.b=hV99jqFA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229577AbiIRMx4 (ORCPT + 99 others); Sun, 18 Sep 2022 08:53:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbiIRMxx (ORCPT ); Sun, 18 Sep 2022 08:53:53 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDE4424975 for ; Sun, 18 Sep 2022 05:53:51 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id l14so58806265eja.7 for ; Sun, 18 Sep 2022 05:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colorfullife-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=SKbV4mKu73VuNVhI6M2LnjoCEeDVwapxGXXk0hJK72A=; b=hV99jqFA22d1stSPIYXXgvzHWcel2GEqsbeq4BhConbSE5mTOzF+3xlTYLreDCdzxG XSm4GFjqsgiBt6MdTtu/2bi9mmZSxpz6ZYe2bzc0Fyc+CBwhh+j+1zwgyjr9esh1nDMi eyBf0iOkyGw8ysWe104/TMzgGsfkiv5hpGr3ZSFMranOWu4amLO5dwAfXvUDJ3l8qNsL uTTmn5Kq8x43B6/46Vja1NRQefsKldJF3h5TMxjriKkaAZh0ialpdk3KpLnhZlcMYzAr pyGLA3eksF+plpo6ZBQhneTWU5q/Tgo/195LpX8LIN5dH2XhJZtrtAe8WPV1XiGMVfzK ooVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=SKbV4mKu73VuNVhI6M2LnjoCEeDVwapxGXXk0hJK72A=; b=5IJBIg4siMb+4NToKWR7pdxO3bgdNbj1qTcPoiHdeCQSDod5qVa/j9ZYyTsv2MjU+1 OH5s4QSSkKkwo8xNEQLDwifGaclS+zNemWqTC9k+Zau+SeFnOHGFtUoYCRJRgC0W+wG6 d7TSkqtI0K9GU4ydYlGBRCTrK0BASmuk2PSIRA/oXpBcokAZbLengT6kEfsNhnPMXY0V DSoSl1pc953ZtO/D/vRSa96awq2r4LuKjAEkfq8HTS225RkJ0l7WFfLgmKpZQ1Pb/yhm 7h5WPwir6BFrq0a4gNdsjV4JbxI4Pi9zLNCVQBSIzqGx3Y+vlkUqEMUZJMUjcZInMXLV xLNQ== X-Gm-Message-State: ACrzQf0/jDEMrt/IIAtrd5sDBFeGhcHbmgD/kmbXSaWW27QUwmSuZVhI h5p9q4pEBcIzFgXlphVJzIivLw== X-Received: by 2002:a17:907:7e94:b0:77a:c48b:c80 with SMTP id qb20-20020a1709077e9400b0077ac48b0c80mr9096922ejc.690.1663505630489; Sun, 18 Sep 2022 05:53:50 -0700 (PDT) Received: from ?IPV6:2003:d9:9726:8300:b088:c09:537d:ce99? (p200300d997268300b0880c09537dce99.dip0.t-ipconnect.de. [2003:d9:9726:8300:b088:c09:537d:ce99]) by smtp.googlemail.com with ESMTPSA id 2-20020a170906210200b00715a02874acsm13955267ejt.35.2022.09.18.05.53.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Sep 2022 05:53:49 -0700 (PDT) Message-ID: Date: Sun, 18 Sep 2022 14:53:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH v6 2/2] ipc/msg: mitigate the lock contention with percpu counter Content-Language: en-US To: Jiebin Sun , akpm@linux-foundation.org, vasily.averin@linux.dev, shakeelb@google.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, ebiederm@xmission.com, legion@kernel.org, alexander.mikhalitsyn@virtuozzo.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: tim.c.chen@intel.com, feng.tang@intel.com, ying.huang@intel.com, tianyou.li@intel.com, wangyang.guo@intel.com, Tim Chen References: <20220902152243.479592-1-jiebin.sun@intel.com> <20220913192538.3023708-1-jiebin.sun@intel.com> <20220913192538.3023708-3-jiebin.sun@intel.com> From: Manfred Spraul In-Reply-To: <20220913192538.3023708-3-jiebin.sun@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Hi Jiebin, On 9/13/22 21:25, 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_counter > greatly improve the performance. Since there is one percpu > struct per 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.99x > > 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 > Reviewed-by: Tim Chen Reviewed-by: Manfred Spraul > @@ -495,17 +496,18 @@ static int msgctl_info(struct ipc_namespace *ns, int msqid, > msginfo->msgssz = MSGSSZ; > msginfo->msgseg = MSGSEG; > down_read(&msg_ids(ns).rwsem); > - if (cmd == MSG_INFO) { > + if (cmd == MSG_INFO) > msginfo->msgpool = msg_ids(ns).in_use; > - msginfo->msgmap = atomic_read(&ns->msg_hdrs); > - msginfo->msgtql = atomic_read(&ns->msg_bytes); > + max_idx = ipc_get_maxidx(&msg_ids(ns)); > + up_read(&msg_ids(ns).rwsem); > + if (cmd == MSG_INFO) { > + msginfo->msgmap = percpu_counter_sum(&ns->percpu_msg_hdrs); > + msginfo->msgtql = percpu_counter_sum(&ns->percpu_msg_bytes); Not caused by your change, it just now becomes obvious: msginfo->msgmap and ->msgtql are type int, i.e. signed 32-bit, and the actual counters are 64-bit. This can overflow - and I think the code should handle this. Just clamp the values to INT_MAX. --     Manfred