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 C5CEBECAAD5 for ; Mon, 5 Sep 2022 12:12:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CA628D0066; Mon, 5 Sep 2022 08:12:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47A2C8D0050; Mon, 5 Sep 2022 08:12:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 341958D0066; Mon, 5 Sep 2022 08:12:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 22A828D0050 for ; Mon, 5 Sep 2022 08:12:13 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E3CD3160551 for ; Mon, 5 Sep 2022 12:12:12 +0000 (UTC) X-FDA: 79877918904.06.3DF7103 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf14.hostedemail.com (Postfix) with ESMTP id A3BD8100059 for ; Mon, 5 Sep 2022 12:12:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662379931; x=1693915931; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=cESe8vq/hRJPKQcNPWYwY2QfT3DdGtul83c8mx+Y1T4=; b=WdqZjj8Pk6K4bT3AeeWyV/RsHL6m5APii8E5BvxBxGFFHOWDpDoEoDZA VqzCGLm8DaxyLsHpWy07+GtUd80QkQdwuuvCgvbn2aYimBMPDYOdpVXB0 K15ii2Zxkzo1f8SA7YBe2FA3JAc2sLljjLUsMfgbxLQYKC26i3m+6LI4g DFVuktXw6hgpOXiRIat4m0IKyXb0PIWa1Mmvwn+aO6n18aGHCOk4jTQAJ nqIL5Ye6ZZ/uBdjKvZEW96t3hSV4zGHDYMxpkTg7sE782xoeUYouMQG8/ 9VCJcLcN+a55RTobkA9nTtNRA5bWSAOC/lkS58esN6hss4N65sxAhr5lO g==; X-IronPort-AV: E=McAfee;i="6500,9779,10460"; a="276118444" X-IronPort-AV: E=Sophos;i="5.93,291,1654585200"; d="scan'208";a="276118444" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 05:12:10 -0700 X-IronPort-AV: E=Sophos;i="5.93,291,1654585200"; d="scan'208";a="643788389" Received: from jiebinsu-mobl.ccr.corp.intel.com (HELO [10.238.0.228]) ([10.238.0.228]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 05:12:06 -0700 Message-ID: Date: Mon, 5 Sep 2022 20:12:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.1 Subject: Re: [PATCH] ipc/msg.c: 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, jiebin.sun@intel.com References: <20220902152243.479592-1-jiebin.sun@intel.com> From: "Sun, Jiebin" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=WdqZjj8P; spf=softfail (imf14.hostedemail.com: 192.55.52.136 is neither permitted nor denied by domain of jiebin.sun@intel.com) smtp.mailfrom=jiebin.sun@intel.com; dmarc=fail reason="No valid SPF" header.from=intel.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662379932; a=rsa-sha256; cv=none; b=fuzE9XcuyweUPQTzFM/KSSsCF4ALr9fEmB01Sak9tQLpySJVPYlmgIy3TdtVzxTclc9bbo Y6gv8SfOKePL2x6AunQRGkF/Xhcur66pYNGZgaZgWIzvWeJIfM/aH2N4Ae1ptXQfljK7RU DiBLn8aaQngsKiYh72BK/RPvai93sww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662379932; 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=rD9l7Cx5Ss6HtMT0xgq5ITs+pG0307rduB/aC1XGFW4=; b=x9dJB6FddjkHImqEax+eTNRu1kw34VZK+v9nphLBHOTEwLwND9aVrXbHc+0W2iGYBxUoGG TzX5tv8mOZINRQ8N7V6ZTBUURjoHauLX+TIHwT9cA4ZigVIOuykFjF/eZoYJuBpmt5X5Vu asVVixElGbAOu4CMPluWzTehn8WmawE= Authentication-Results: imf14.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=WdqZjj8P; spf=softfail (imf14.hostedemail.com: 192.55.52.136 is neither permitted nor denied by domain of jiebin.sun@intel.com) smtp.mailfrom=jiebin.sun@intel.com; dmarc=fail reason="No valid SPF" header.from=intel.com (policy=none) X-Rspamd-Server: rspam06 X-Stat-Signature: 85tgoqqwwwa598xg9qrghdcotkftx4cc X-Rspam-User: X-Rspamd-Queue-Id: A3BD8100059 X-HE-Tag: 1662379931-28714 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/4/2022 3:35 AM, Manfred Spraul wrote: > Hi Jiebin, > > On 9/2/22 17:22, 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. > > With ipc namespaces, there is one struct per namespace, correct? > > The cost is probably still ok, but the change log should be correct. > Yes, that's what I want to summarize. The IPC msg namespace is unique and there is only one percpu counter in IPC msg namespace. Thanks. > >> @@ -1303,14 +1305,16 @@ void msg_init_ns(struct ipc_namespace *ns) >>       ns->msg_ctlmnb = MSGMNB; >>       ns->msg_ctlmni = MSGMNI; >>   -    atomic_set(&ns->msg_bytes, 0); >> -    atomic_set(&ns->msg_hdrs, 0); >> +    percpu_counter_init(&ns->percpu_msg_bytes, 0, GFP_KERNEL); >> +    percpu_counter_init(&ns->percpu_msg_hdrs, 0, GFP_KERNEL); >>       ipc_init_ids(&ns->ids[IPC_MSG_IDS]); > > These calls can fail. You must add error handling. I have add error handling for percpu_counter_init. Thanks. > > -- > >     Manfred > >