From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD7D5C54EE9 for ; Sun, 18 Sep 2022 12:53:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9C4A940008; Sun, 18 Sep 2022 08:53:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2496940007; Sun, 18 Sep 2022 08:53:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C639940008; Sun, 18 Sep 2022 08:53:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 79553940007 for ; Sun, 18 Sep 2022 08:53:52 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4B005C03A4 for ; Sun, 18 Sep 2022 12:53:52 +0000 (UTC) X-FDA: 79925198304.07.3DE0591 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by imf08.hostedemail.com (Postfix) with ESMTP id EC734160008 for ; Sun, 18 Sep 2022 12:53:51 +0000 (UTC) Received: by mail-ej1-f46.google.com with SMTP id u9so58874195ejy.5 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=A2ci7O45jAx5rGvNFoQPReIOArRF9cUo9ehMgJm2/Y1w75UOO8KzQKj8qr3Q5xpy3P +efHkeVwnfR3x9dXZQyzaR25CIc9wQwB8bwvkIupw6gNvVffblRJHUdW+r2M9cw6VbYw SJVtk03ruHD3H/0HwopxS3rBLM2O7AMLqsUny/XNrl8WTZ2d4Dwub5oty9sq0vJ5WUY1 INkKcXoKnkvj7deaFy26OZnPKeeIuOa+WcWfNgA+VnENy9R5u5ZlvsKg2x7xXo3SEvhf Lhi9BhRrF0yne5K6LoVB1Qmz2XPfNBiAf5yZjeg4Lqo7YsnmGScBZGm866a3iPTf6OVR eRHg== X-Gm-Message-State: ACrzQf07x64TaU8Vp3BYGG47rL1Q1bNReL53nK2YRJj6icXLeAxFFkVA gqeZCCZetNLac9P7MeUnEHKv7A== X-Google-Smtp-Source: AMsMyM5p9fT6KbixCtDQelPo6TexlnkeLzgg0KUT3L5ZYXpyMzuHG4brcM9ThyTJoBHM8JmB+XDFHQ== 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663505632; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SKbV4mKu73VuNVhI6M2LnjoCEeDVwapxGXXk0hJK72A=; b=h2nY6UA12DIAIU5/XqTpTVC++D4TExB+yIcsojTTDtv5imw4301TIXoI6Hax5+GF5ySJdL gIX15D6uXhhbyrvxDJ8Ppbjcwjgwv/qG2footrRhQJqXb64rZD+Bf4nZF5FbVrMo0nlxwl NE1fvb2DxeznwtgYef8oY/qlVA6svyk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=colorfullife-com.20210112.gappssmtp.com header.s=20210112 header.b=hV99jqFA; spf=pass (imf08.hostedemail.com: domain of manfred@colorfullife.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=manfred@colorfullife.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663505632; a=rsa-sha256; cv=none; b=EjaboBNK3ipxEXGAHRfEP/6rTDdMdxYeUtvefZ0omzmuyEw83otMcOd9HpHa86AwrwIPnC j6WKGLKsj3iGxsGnUyXJRSagjdAv9Fbm3yb4dhHLqu+Y8a2iWD8gth69lB+Q3Dp6tGYrCJ ETKp0nz5HPyt6t5Cwup2T43VsDEJcKs= X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: EC734160008 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=colorfullife-com.20210112.gappssmtp.com header.s=20210112 header.b=hV99jqFA; spf=pass (imf08.hostedemail.com: domain of manfred@colorfullife.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=manfred@colorfullife.com; dmarc=none X-Stat-Signature: ymf79u559wsg5rbda78mzm373ohxzx8t X-Rspam-User: X-HE-Tag: 1663505631-702955 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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