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 0BB9DECAAA1 for ; Fri, 9 Sep 2022 12:17:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 770FB8D0003; Fri, 9 Sep 2022 08:17:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F8958D0002; Fri, 9 Sep 2022 08:17:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 599C88D0003; Fri, 9 Sep 2022 08:17:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 477FE8D0002 for ; Fri, 9 Sep 2022 08:17:35 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 21F2B1C5D3D for ; Fri, 9 Sep 2022 12:17:35 +0000 (UTC) X-FDA: 79892447670.11.0044AEE Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf03.hostedemail.com (Postfix) with ESMTP id 62B2120077 for ; Fri, 9 Sep 2022 12:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662725853; x=1694261853; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UAAQ+YLzvmmUI6dBHAsDTOGyqlQLeOvNNzTP+cKD4uk=; b=leIu2aVB4HF1Oqg0LEAvY3E4Zm20pcfFMwzq4xzOrJPYZYPm+hBj+rI8 M/mQImINWdgNWlHXYL9z+8NPllHROc6FbuHr8ZXwn4cNpTKOK8mwxttf1 9fcNVuL3vAWtW3DILIiC4T0CTZIJGOrJpOXCgK5sdQ4tKq5vneB+1WEyc rcfCx6/pNDpXFCXMgtueBW+D3SrdxymIod4fvxkF+OdoyGbf5nKlF64dC kFjIP/Q+GgOW29Ulu/jisVOfib9zPO+CXE/t/tvTBNC0wenXlbExYpzPF xdhFde2kk8OyvzMo7xHNjXwIFTOXJSXbX/7vyDwY7WrSkuedVolFC64v9 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10464"; a="277194656" X-IronPort-AV: E=Sophos;i="5.93,303,1654585200"; d="scan'208";a="277194656" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2022 05:17:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,303,1654585200"; d="scan'208";a="645516055" Received: from linux-pnp-server-13.sh.intel.com ([10.239.176.176]) by orsmga008.jf.intel.com with ESMTP; 09 Sep 2022 05:17:28 -0700 From: Jiebin Sun To: 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, manfred@colorfullife.com, 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 Subject: [PATCH v5 0/2] ipc/msg: mitigate the lock contention in ipc/msg Date: Sat, 10 Sep 2022 04:36:34 +0800 Message-Id: <20220909203636.2652466-1-jiebin.sun@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220902152243.479592-1-jiebin.sun@intel.com> References: <20220902152243.479592-1-jiebin.sun@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662725854; a=rsa-sha256; cv=none; b=r+lDEU/fQ/MFv3ZmSawCU2q7dDCimkPL3snKiFSk7gMLmAwRyWSZ4PmNvkJe9MCEn8rb7A 7HV6/SPxMRx8Pu/zDrPplsERDVpGsomFDHjtT23v7OGrGABoo6Bv0oMGapsdoGW+y1bDMQ Bv/ZBFGtIFBmCBhh6eq3kicPfGPuBPY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=leIu2aVB; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf03.hostedemail.com: domain of jiebin.sun@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=jiebin.sun@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662725854; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UAAQ+YLzvmmUI6dBHAsDTOGyqlQLeOvNNzTP+cKD4uk=; b=rzshnP+xqVb9gFHsa8A+OGEYWxRHmxT7He5CYV1mz6Q0z+gP/54EJhSCdwwuuODz9NJ8Y3 XCg7dqEjjMnedYYamLJLY0ikni+2max0L8roAhEQa48DV5OskNB+5j9h77HFIO/6zaxkJK O0lRlgXA4CoQhtdIp4ZMCUzqWQmB0LI= X-Stat-Signature: i4o9ytpim1hikj53pdpqdattxzzusaj4 X-Rspamd-Queue-Id: 62B2120077 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=leIu2aVB; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf03.hostedemail.com: domain of jiebin.sun@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=jiebin.sun@intel.com X-Rspamd-Server: rspam02 X-HE-Tag: 1662725853-243124 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, Here are two patches to mitigate the lock contention in ipc/msg. The 1st patch is to add the new interface percpu_counter_add_local and percpu_counter_sub_local. The batch size in percpu_counter_add_batch should be very large in heavy writing and rare reading case. Add the "_local" version, and mostly it will do local adding, reduce the global updating and mitigate lock contention in writing. The 2nd patch is to use percpu_counter instead of atomic update in ipc/msg. 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. Changes in v5: 1. Use INT_MAX as the large batch size in percpu_counter_local_add and percpu_counter_sub_local. 2. Use the latest kernel 6.0-rc4 as the baseline for performance test. 3. Move the percpu_counter_local_add and percpu_counter_sub_local from percpu_counter.c to percpu_counter.h. Changes in v3: 1. Add comment and change log for the new function percpu_counter_add_local. Who should use it and who shouldn't. Changes in v2: 1. Separate the original patch into two patches. 2. Add error handling for percpu_counter_init. The performance gain increases as the threads of workload become larger. Performance 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) Regards Jiebin