Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5890550rwb; Wed, 7 Sep 2022 09:22:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR7s+cYoUg755DvSqQkxeU697ClBvV1dBTy8yp+4wbK9VlPbiiNXmehn8q2L9yAK+ipPO3+O X-Received: by 2002:a17:906:cc13:b0:73d:d22d:63cd with SMTP id ml19-20020a170906cc1300b0073dd22d63cdmr2894950ejb.741.1662567755318; Wed, 07 Sep 2022 09:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662567755; cv=none; d=google.com; s=arc-20160816; b=RkxsW9LCODnWWeYZTQcOhUWZOpa+yoBXjdXxAbdETk1I+zeIfhDJmKCNY5SnECl7ne 1S4tWlsayxAbyWPeJ7wK/o8/AaCTMHnoIUNb7AbO17a3St587tHwhYng4s8wx9hFYuSQ XA4tRkaMAtZL0Q5iDUBGmKIgC5n7RAQkg1AYExzIUehWaRgGKZ3iDVbe/Wee4k3zujti d8F+uYLXD1m908/DnTjhATpxS0MfRSsL1URi/Z1oYnDSsHdnzubanAYd8x663eDR+rid YNpVfTFTr2YVnFSHkBtR4LehOJx/el6A7YbJ5K0D9S3vf73gpNZyu0FlX5KZUWX2BsWy 92Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=35GR41yR8jWXOhFEzIXlyIjwMF0V+CGKRaL/y+v6PxY=; b=E53zdcWNmceIOdfjRV/pmju2NYsq/xvytcHu/TfXAj3i5p3en5i/hz0YmdFiwMoaLS i3520GtedSOt6tcF3qv+Vlmh7eqkJ9HfPOa8K4RY0GsHOx+m7KVjbTXwbRVmynD+cTNS iBlcTkEH1G+M47JmrxtRvMyejtoONaZv1byafw6hZvosTVvGcIkQjg8NwISlsfE+d6qJ uK56dGKhgQ6dVHh6TfCL0WJNZ4pTv9rVJcw7aQRe3N8/UIY4kvQ/mWlSZUdrlRgA6CJP +Kumfx+EL5e26kavOPqbtH0BV1S2ukXBMWEqMhbBJ7m4uTz9i5h9hPHpmpDsn39gVSb9 gnUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HKSvGvG1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a170906118400b0073d4da4039asi11550152eja.468.2022.09.07.09.22.10; Wed, 07 Sep 2022 09:22:35 -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=@intel.com header.s=Intel header.b=HKSvGvG1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230366AbiIGQFs (ORCPT + 99 others); Wed, 7 Sep 2022 12:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230345AbiIGQFN (ORCPT ); Wed, 7 Sep 2022 12:05:13 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AAFB9F8E1 for ; Wed, 7 Sep 2022 09:03:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662566636; x=1694102636; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=8qmgsTp0R++7umL+kTPdAI4AENu4bF7ohljPEUK86+0=; b=HKSvGvG1OJu++CvzXa4nDRLqv6ShHqUeZiqTjNJCnYfGFTfgHunbTRoZ Avz8CQ5QU6YViwjOvSJ+1NnQ6pxx8UZeLmr+/L30jFUOaxcM6QYmATeay X27qdgakosp78XYbqHzubH83i7L0N+5xOIOZXpOgNOFjgPpbeJSkht8nM rdpQGmUwNXfpt7SSUWSY371E7HZJiaV6082vitslsO6+6/YsigPw5JBNK W1SaKX8rS+Hgt2qwk/WLzbuavW/gO2hlzFi6dD/E8Mm1X6cptdSj3mv3B BSRfur2Yg/a54s+PqgRN0MqKzAXRarHidoPaQ7o0LDpBRlJq8OiOT/Fzi Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10463"; a="283917477" X-IronPort-AV: E=Sophos;i="5.93,297,1654585200"; d="scan'208";a="283917477" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2022 09:01:54 -0700 X-IronPort-AV: E=Sophos;i="5.93,297,1654585200"; d="scan'208";a="565570756" Received: from schen9-mobl.amr.corp.intel.com ([10.209.53.232]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2022 09:01:53 -0700 Message-ID: Subject: Re: [PATCH v4] ipc/msg: mitigate the lock contention with percpu counter From: Tim Chen 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, 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 Date: Wed, 07 Sep 2022 09:01:53 -0700 In-Reply-To: <20220907172516.1210842-1-jiebin.sun@intel.com> References: <20220907172516.1210842-1-jiebin.sun@intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 (3.34.4-1.fc31) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 On Thu, 2022-09-08 at 01:25 +0800, 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.17x > > ... > > +/* large batch size could reduce the times to sum up percpu counter */ > +#define MSG_PERCPU_COUNTER_BATCH 1024 > + Jiebin, 1024 is a small size (1/4 page). The local per cpu counter could overflow to the gloabal count quickly if it is limited to this size, since our count tracks msg size. I'll suggest something larger, say 8*1024*1024, about 8MB to accommodate about 2 large page worth of data. Maybe that will further improve throughput on stress-ng by reducing contention on adding to the global count. Tim