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 9AB50C6FA82 for ; Tue, 20 Sep 2022 02:36:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B5EC80008; Mon, 19 Sep 2022 22:36:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 165B780007; Mon, 19 Sep 2022 22:36:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 005A280008; Mon, 19 Sep 2022 22:36:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E17EB80007 for ; Mon, 19 Sep 2022 22:36:37 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AB42C1C3BC4 for ; Tue, 20 Sep 2022 02:36:37 +0000 (UTC) X-FDA: 79930900434.11.6850CF9 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf14.hostedemail.com (Postfix) with ESMTP id A2C20100014 for ; Tue, 20 Sep 2022 02:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663641396; x=1695177396; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=nk9gDyzIwubd+O3r5JYRHY7h56aCXeJ9B2IcQcqK5Pw=; b=F6UYOZq+93xyQGuwtYqOXWA8355GdbUFRLKrl+82AFMV1Y8mj5wGXx60 cUK+ERxMD1MwIUP2pOrhJMuruUu2KUBLpgsYqIl0uByT1kqiWGVHII6gc ObLxhSs0qIujEdL4AVRs16WyNhtoc+SAIC4RAViF9CcPGs6BKcVV0b4RT j/YfdsMr1fnY3jezcQVyRS6AAV3rNyN6wIW1wMo4SNgiFBIalgaxRcaw1 /dBlbO3Co13XHcqiV8h2ot2T2bjm1OeqwL1tiFkaLk/IaImD9WpEqUASu WIafr+jAto7jD8MO2Hsg+6x5SlUy0uQ4+KzmyvfSiVqxBwRCoNHSDaUbP w==; X-IronPort-AV: E=McAfee;i="6500,9779,10475"; a="385863509" X-IronPort-AV: E=Sophos;i="5.93,329,1654585200"; d="scan'208";a="385863509" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2022 19:36:33 -0700 X-IronPort-AV: E=Sophos;i="5.93,329,1654585200"; d="scan'208";a="722552579" Received: from jiebinsu-mobl.ccr.corp.intel.com (HELO [10.238.4.108]) ([10.238.4.108]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2022 19:36:29 -0700 Message-ID: <6ed22478-0c89-92ea-a346-0349be2dd99c@intel.com> Date: Tue, 20 Sep 2022 10:36:27 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH v6 2/2] ipc/msg: mitigate the lock contention with percpu counter Content-Language: en-US To: Manfred Spraul , 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 , jiebin.sun@intel.com References: <20220902152243.479592-1-jiebin.sun@intel.com> <20220913192538.3023708-1-jiebin.sun@intel.com> <20220913192538.3023708-3-jiebin.sun@intel.com> From: "Sun, Jiebin" In-Reply-To: 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=1663641397; 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=NOE1SI9TSefnYxWRjYhd7cEWPPuk/1dU7EpYk8rHg7s=; b=yIEQVwNkBQKrbKkyZ/XLRX95Sm9S5s89iyXCBdCidvk2hFX0na3J3/FGKVNC/stKQ8K6qA 20TY8LdUXURUTE8gF5u9Pf5zNbhUcmCNlgDVWL2x0xswb1KpXmPse6KpFOaigTuOcFzFZJ dEZYXw8Su2V3ivSMHClOjssCmbzIEn8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=F6UYOZq+; spf=pass (imf14.hostedemail.com: domain of jiebin.sun@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=jiebin.sun@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663641397; a=rsa-sha256; cv=none; b=JllS6Xo1qt8tkf2o0DyJAJtxYOWPeBzXrXLOEVyyN8QAfPQdBoXFcqGpTL9m8EdVVybjAh vGD3ftssEw6QlUNKK6IzlEvzyDqMY4KqoYrAOizNMQfYIuL/FYJqAAVu74DsfZy1X3H5bu 09UfNmFY1MDpkacG3iyUdSa2DHw+BCg= X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=F6UYOZq+; spf=pass (imf14.hostedemail.com: domain of jiebin.sun@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=jiebin.sun@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam04 X-Stat-Signature: utuf1t69phszkypncrf3aagjjph4p3wd X-Rspamd-Queue-Id: A2C20100014 X-HE-Tag: 1663641396-33595 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: On 9/18/2022 8:53 PM, Manfred Spraul wrote: > 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. > Hi Manfred, Thanks for your advice. But I'm not sure if we could fix the overflow issue in ipc/msg totally by clamp(val, low, INT_MAX). If the value is over s32, we might avoid the reversal sign, but still could not get the accurate value.